This repository has been archived by the owner on Mar 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace auto-generated ID with a given name #21
The user has to specify a name per state machine. This simplifies the code.
- Loading branch information
Showing
13 changed files
with
43 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/scala/de/retest/guistatemachine/api/ActionTransitions.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
18 changes: 12 additions & 6 deletions
18
src/main/scala/de/retest/guistatemachine/api/impl/GuiStateMachineApiImpl.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,24 @@ | ||
package de.retest.guistatemachine.api.impl | ||
|
||
import de.retest.guistatemachine.api.{GuiStateMachine, GuiStateMachineApi, Id} | ||
import de.retest.guistatemachine.api.{GuiStateMachine, GuiStateMachineApi} | ||
|
||
import scala.collection.concurrent.TrieMap | ||
|
||
/** | ||
* Thread-safe implementation of the API. It is thread-safe because it uses `IdMap`. | ||
* Thread-safe implementation of the API. | ||
*/ | ||
class GuiStateMachineApiImpl extends GuiStateMachineApi { | ||
private val stateMachines = IdMap[GuiStateMachine]() | ||
private val stateMachines = TrieMap[String, GuiStateMachine]() | ||
|
||
override def createStateMachine(): Id = stateMachines.addNewElement(new GuiStateMachineImpl) | ||
override def createStateMachine(name: String): GuiStateMachine = { | ||
val guiStateMachine = new GuiStateMachineImpl | ||
stateMachines += (name -> guiStateMachine) | ||
guiStateMachine | ||
} | ||
|
||
override def removeStateMachine(id: Id): Boolean = stateMachines.removeElement(id) | ||
override def removeStateMachine(name: String): Boolean = stateMachines.remove(name).isDefined | ||
|
||
override def getStateMachine(id: Id): Option[GuiStateMachine] = stateMachines.getElement(id) | ||
override def getStateMachine(name: String): Option[GuiStateMachine] = stateMachines.get(name) | ||
|
||
override def clear(): Unit = stateMachines.clear() | ||
} |
63 changes: 0 additions & 63 deletions
63
src/main/scala/de/retest/guistatemachine/api/impl/IdMap.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
21 changes: 11 additions & 10 deletions
21
src/test/scala/de/retest/guistatemachine/api/impl/GuiStateMachineApiImplSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,29 @@ | ||
package de.retest.guistatemachine.api.impl | ||
|
||
import de.retest.guistatemachine.api.{AbstractApiSpec, GuiStateMachineApi, Id} | ||
import de.retest.guistatemachine.api.{AbstractApiSpec, GuiStateMachineApi} | ||
|
||
class GuiStateMachineApiImplSpec extends AbstractApiSpec { | ||
"GuiStateMachineApi" should { | ||
"create, get and remove a new state machine" in { | ||
val stateMachineId = GuiStateMachineApi().createStateMachine() | ||
stateMachineId shouldEqual Id(0) | ||
|
||
val stateMachine = GuiStateMachineApi().getStateMachine(stateMachineId) | ||
GuiStateMachineApi().createStateMachine("tmp") | ||
val stateMachine = GuiStateMachineApi().getStateMachine("tmp") | ||
stateMachine.isDefined shouldBe true | ||
val fsm = stateMachine.get | ||
fsm.getActionExecutionTimes.size shouldEqual 0 | ||
fsm.getAllExploredActions.size shouldEqual 0 | ||
|
||
GuiStateMachineApi().removeStateMachine(stateMachineId) shouldBe true | ||
GuiStateMachineApi().removeStateMachine("tmp") shouldBe true | ||
GuiStateMachineApi().getStateMachine("tmp").isDefined shouldBe false | ||
} | ||
|
||
"clear all state machines" in { | ||
GuiStateMachineApi().createStateMachine shouldEqual Id(0) | ||
GuiStateMachineApi().createStateMachine shouldEqual Id(1) | ||
GuiStateMachineApi().createStateMachine shouldEqual Id(2) | ||
GuiStateMachineApi().createStateMachine("tmp0") | ||
GuiStateMachineApi().createStateMachine("tmp1") | ||
GuiStateMachineApi().createStateMachine("tmp2") | ||
GuiStateMachineApi().clear() | ||
GuiStateMachineApi().getStateMachine(Id(2)).isEmpty shouldEqual true | ||
GuiStateMachineApi().getStateMachine("tmp0").isEmpty shouldEqual true | ||
GuiStateMachineApi().getStateMachine("tmp1").isEmpty shouldEqual true | ||
GuiStateMachineApi().getStateMachine("tmp2").isEmpty shouldEqual true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 0 additions & 24 deletions
24
src/test/scala/de/retest/guistatemachine/api/impl/IdMapSpec.scala
This file was deleted.
Oops, something went wrong.
7 changes: 2 additions & 5 deletions
7
src/test/scala/de/retest/guistatemachine/api/impl/StateImplSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters