Skip to content

Commit

Permalink
style(analysis, domain, parser, api, state): improve consistency in n…
Browse files Browse the repository at this point in the history
…aming conventions for test descriptions and messages
  • Loading branch information
Ro0t-set committed Feb 3, 2025
1 parent 9b12730 commit 44dcdcf
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 40 deletions.
8 changes: 4 additions & 4 deletions analysis/src/test/scala/analysis/DependencySpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ class DependencySpec extends FunSuite:

noDependTest(
testName =
"Domain package should only depend on itself and standard libraries",
"domain package should only depend on itself and standard libraries",
importRoot = "domain..",
packageToCheck = "..domain..",
forbiddenPackages = Seq("..laminar..", "..state..", "..js.."),
becauseMsg =
"Domain layer should be isolated from infrastructure and application layers"
"domain layer should be isolated from infrastructure and application layers"
)

noDependTest(
testName = "State package should only depend on itself and Laminar",
testName = "state package should only depend on itself and Laminar",
importRoot = "state..",
packageToCheck = "..state..",
forbiddenPackages = Seq("..view..", "..API.."),
becauseMsg =
"State layer should be isolated from infrastructure and application layers"
"state layer should be isolated from infrastructure and application layers"
)
4 changes: 2 additions & 2 deletions analysis/src/test/scala/domain/DomainSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import munit.ScalaCheckSuite
import org.scalacheck.Prop.forAll

class DomainSpec extends FunSuite with ScalaCheckSuite:
test("Edge from x to y is the same of y to x") {
test("edge from x to y is the same of y to x") {
forAll {
(
id1: Int,
Expand All @@ -32,7 +32,7 @@ class DomainSpec extends FunSuite with ScalaCheckSuite:
}
}

test("Edges with different nodes is not equal") {
test("edges with different nodes is not equal") {
forAll {
(
id1: Int,
Expand Down
4 changes: 2 additions & 2 deletions analysis/src/test/scala/parser/EdgeParserSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ class EdgeParserSpec extends FunSuite with ScalaCheckSuite:
"target": $target
}]"""

test("EdgeParser parses valid single edge JSON") {
test("parses valid single edge JSON") {
forAll(validEdgeJsonGen) { jsonString =>
EdgeParser.parse(jsonString).fold(false) { edges =>
edges.size == 1
}
}
}

test("EdgeParser handles invalid JSON") {
test("if JSON is invalid, no edges are parsed without exceptions") {
forAll(Gen.numStr) { invalidJson =>
EdgeParser.parse(invalidJson).isEmpty
}
Expand Down
4 changes: 2 additions & 2 deletions analysis/src/test/scala/parser/NodeParserSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class NodeParserSpec extends FunSuite with ScalaCheckSuite:
GraphNode(id, Position(x, y, z), label, color)
)

test("NodeParser parses valid single node JSON") {
test("parses valid single node JSON") {
forAll(validNodeJsonGen) {
case (jsonString, validJsonNodeFromParams) =>
NodeParser.parse(jsonString).fold(false) { nodes =>
Expand All @@ -42,7 +42,7 @@ class NodeParserSpec extends FunSuite with ScalaCheckSuite:
}
}

test("NodeParser handles invalid JSON") {
test("if JSON is invalid, no nodes are parsed without exceptions") {
forAll(Gen.numStr) { invalidJson =>
NodeParser.parse(invalidJson).isEmpty
}
Expand Down
4 changes: 2 additions & 2 deletions js/src/test/scala/api/ApiSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ApiSpec extends FunSuite with ScalaCheckSuite:
"target": $target
}]"""

test("Add nodes from JSON") {
test("add nodes from JSON") {
forAll(validNodeJsonGen) {
case (jsonString, validJsonNodeFromParams) =>
GraphAPI.addNodesFromJson(
Expand All @@ -51,7 +51,7 @@ class ApiSpec extends FunSuite with ScalaCheckSuite:
}
}

test("Add edges from JSON") {
test("add edges from JSON") {
forAll(validEdgeJsonGen) { jsonString =>
GraphAPI.addEdgesFromJson(
jsonString
Expand Down
50 changes: 25 additions & 25 deletions js/src/test/scala/state/AnimationStateSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,73 +25,73 @@ class AnimationStateSpec extends FunSuite with ScalaCheckSuite:

test("initial state validates default values") {
Prop.all(
Prop(AnimationState.batch.now() == 1),
Prop(AnimationState.currentTick.now() == 0),
Prop(AnimationState.engine.now().isEmpty),
Prop(AnimationState.mode.now() == ViewMode.Mode3D)
AnimationState.batch.now() == 1,
AnimationState.currentTick.now() == 0,
AnimationState.engine.now().isEmpty,
AnimationState.mode.now() == ViewMode.Mode3D
)
}

test("SetEngine updates engine and resets state") {
test("updates engine and resets state") {
forAll(Gen.const(js.Dynamic.literal())) { mockEngine =>
AnimationState.animationObserver.onNext(SetEngine(mockEngine))
Prop.all(
Prop(AnimationState.engine.now().contains(mockEngine)),
Prop(!AnimationState.running.now()),
Prop(AnimationState.currentTick.now() == 0)
AnimationState.engine.now().contains(mockEngine),
!AnimationState.running.now(),
AnimationState.currentTick.now() == 0
)
}
}

test("StartAnimation manages running state") {
test("start animation") {

AnimationState.animationObserver.onNext(StartAnimation())
Prop(AnimationState.running.now())
AnimationState.running.now()

}

test("PauseAnimation stops animation") {
test("stops animation") {

AnimationState.animationObserver.onNext(StartAnimation())
AnimationState.animationObserver.onNext(PauseAnimation())
Prop(!AnimationState.running.now())
!AnimationState.running.now()

}

test("NextTick increments current tick") {
test("increments current tick") {

val initialTick = AnimationState.currentTick.now()
AnimationState.animationObserver.onNext(NextTick())
Prop(AnimationState.currentTick.now() == initialTick + 1)
AnimationState.currentTick.now() == initialTick + 1

}

test("AnimationBatch updates batch value") {
test("updates batch value") {
forAll(Gen.choose(1, 10)) { batchValue =>
AnimationState.animationObserver.onNext(AnimationBatch(batchValue))
Prop(AnimationState.batch.now() == batchValue)
AnimationState.batch.now() == batchValue
}
}

test("Reset restores initial state") {
test("restores initial state") {

AnimationState.animationObserver.onNext(StartAnimation())
AnimationState.animationObserver.onNext(NextTick())
AnimationState.animationObserver.onNext(Reset())
Prop.all(
Prop(!AnimationState.running.now()),
Prop(AnimationState.currentTick.now() == 0)
!AnimationState.running.now(),
AnimationState.currentTick.now() == 0
)

}

test("SwitchMode toggles between view modes") {
test("Switch mode between view modes") {

val initialMode = AnimationState.mode.now()
AnimationState.animationObserver.onNext(SwitchMode())
Prop(
AnimationState.mode.now() ==
(if initialMode == ViewMode.Mode3D then ViewMode.Mode2D
else ViewMode.Mode3D)
)

AnimationState.mode.now() ==
(if initialMode == ViewMode.Mode3D then ViewMode.Mode2D
else ViewMode.Mode3D)

}
6 changes: 3 additions & 3 deletions js/src/test/scala/state/GraphStateSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class GraphStateSpec extends FunSuite with ScalaCheckSuite:
GraphState.commandObserver.onNext(SetNodes(Set.empty))
GraphState.commandObserver.onNext(SetEdges(Set.empty))

test("addNode should add a node to the state") {
test("add a node to the state") {
forAll {
(id: Int, label: String, color: Int, x: Double, y: Double, z: Double) =>
val node: Set[GraphNode] =
Expand All @@ -27,7 +27,7 @@ class GraphStateSpec extends FunSuite with ScalaCheckSuite:
}
}

test("addEdge should add an edge to the state") {
test("add an edge to the state") {
forAll {
(
id1: Int,
Expand Down Expand Up @@ -56,7 +56,7 @@ class GraphStateSpec extends FunSuite with ScalaCheckSuite:
}
}

test("addEdgeById should add an edge to the state") {
test("add an edge to the state by nodes' ids") {
forAll {
(
id1: Int,
Expand Down

0 comments on commit 44dcdcf

Please sign in to comment.