From 830fd07f51366c2469457b542bc5a795834aa444 Mon Sep 17 00:00:00 2001 From: Isuru Rajapakse Date: Sun, 15 Aug 2021 11:24:46 +1000 Subject: [PATCH] Remove guava dependencies as gabe already has a lower version of it --- build.gradle.kts | 5 +- buildSrc/src/main/kotlin/Dependencies.kt | 1 - .../com/xfastgames/witness/items/data/Node.kt | 58 ---------------- .../items/renderer/PuzzlePanelRenderer.kt | 6 +- .../screens/composer/PuzzleComposerScreen.kt | 3 +- .../screens/solver/PuzzleSolverScreen.kt | 11 +-- .../witness/screens/widgets/WPuzzleEditor.kt | 3 +- .../xfastgames/witness/utils/guava/Graph.kt | 5 +- .../witness/utils/guava/MutableValueGraph.kt | 8 +++ .../witness/utils/guava/Traverser.kt | 19 +++++ .../witness/utils/guava/ValueGraph.kt | 23 +++++-- src/main/resources/fabric.mod.json | 1 - .../witness/items/data/GraphTests.kt | 5 +- .../xfastgames/witness/utils/GuavaTests.kt | 69 +++++++++++++++++++ .../witness/utils/ValueGraphTests.kt | 56 --------------- 15 files changed, 134 insertions(+), 139 deletions(-) create mode 100644 src/main/kotlin/com/xfastgames/witness/utils/guava/MutableValueGraph.kt create mode 100644 src/main/kotlin/com/xfastgames/witness/utils/guava/Traverser.kt create mode 100644 src/test/kotlin/com/xfastgames/witness/utils/GuavaTests.kt delete mode 100644 src/test/kotlin/com/xfastgames/witness/utils/ValueGraphTests.kt diff --git a/build.gradle.kts b/build.gradle.kts index 57ca800..97d3164 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -27,14 +27,11 @@ dependencies { modImplementation("net.fabricmc", "fabric-language-kotlin", Fabric.Kotlin.version) modImplementation("net.fabricmc.fabric-api", "fabric-api", Fabric.API.version) - modImplementation(Mods.libgui) + modImplementation(include(Mods.libgui)!!) modImplementation(Mods.modmenu) modImplementation(Mods.nbtcrafting) - implementation(Google.guava) - testRuntimeOnly(JUnit.jupiter_engine) - testImplementation(JUnit.jupiter) testImplementation(Google.truth) } diff --git a/buildSrc/src/main/kotlin/Dependencies.kt b/buildSrc/src/main/kotlin/Dependencies.kt index 6c19604..e3194c9 100644 --- a/buildSrc/src/main/kotlin/Dependencies.kt +++ b/buildSrc/src/main/kotlin/Dependencies.kt @@ -11,7 +11,6 @@ object Mods { } object Google { - const val guava = "com.google.guava:guava:30.0-jre" const val truth = "com.google.truth:truth:1.0.1" } diff --git a/src/main/kotlin/com/xfastgames/witness/items/data/Node.kt b/src/main/kotlin/com/xfastgames/witness/items/data/Node.kt index ac09bde..b8de1c0 100644 --- a/src/main/kotlin/com/xfastgames/witness/items/data/Node.kt +++ b/src/main/kotlin/com/xfastgames/witness/items/data/Node.kt @@ -1,9 +1,6 @@ package com.xfastgames.witness.items.data import com.google.common.graph.EndpointPair -import com.google.common.graph.MutableGraph -import com.google.common.graph.Traverser -import com.xfastgames.witness.utils.guava.clear import net.minecraft.nbt.NbtCompound import kotlin.math.hypot import kotlin.math.pow @@ -34,25 +31,6 @@ fun distance(u: Node, v: Node): Float = @Suppress("UnstableApiUsage") operator fun EndpointPair.contains(node: Node) = this.nodeU() == node || this.nodeV() == node -/** - * Optimize a node graph with [Ramer–Douglas–Peucker algorithm](https://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm) - */ -@Suppress("UnstableApiUsage") -fun MutableGraph.optimize(starting: Node): MutableGraph { - val line: List = Traverser.forGraph(this).breadthFirst(starting).toList() - if (line.size < 2) return this - - this.clear() - - val mutableList: MutableList = line.toMutableList() - RamerDouglasPeucker(mutableList, 1.0, mutableList) - - mutableList.chunked(2).forEach { (prevNode, nexNode) -> - putEdge(prevNode, nexNode) - } - return this -} - /** Copy pasta of https://www.rosettacode.org/wiki/Ramer-Douglas-Peucker_line_simplification#Kotlin **/ private fun perpendicularDistance(pt: Node, lineStart: Node, lineEnd: Node): Float { var dx: Float = lineEnd.x - lineStart.x @@ -74,40 +52,4 @@ private fun perpendicularDistance(pt: Node, lineStart: Node, lineEnd: Node): Flo val ay: Float = pvy - pvdot * dy return hypot(ax, ay) -} - -fun RamerDouglasPeucker(pointList: List, epsilon: Double, out: MutableList) { - if (pointList.isEmpty()) return - if (pointList.size < 2) throw IllegalArgumentException("Not enough points to simplify") - - // Find the point with the maximum distance from line between start and end - var dmax = 0.0f - var index = 0 - val end = pointList.size - 1 - for (i in 1 until end) { - val d = perpendicularDistance(pointList[i], pointList[0], pointList[end]) - if (d > dmax) { - index = i; dmax = d - } - } - - // If max distance is greater than epsilon, recursively simplify - if (dmax > epsilon) { - val recResults1 = mutableListOf() - val recResults2 = mutableListOf() - val firstLine = pointList.take(index + 1) - val lastLine = pointList.drop(index) - RamerDouglasPeucker(firstLine, epsilon, recResults1) - RamerDouglasPeucker(lastLine, epsilon, recResults2) - - // build the result list - out.addAll(recResults1.take(recResults1.size - 1)) - out.addAll(recResults2) - if (out.size < 2) throw RuntimeException("Problem assembling output") - } else { - // Just return start and end points - out.clear() - pointList.firstOrNull()?.let { out.add(it) } - pointList.lastOrNull()?.let { out.add(it) } - } } \ No newline at end of file diff --git a/src/main/kotlin/com/xfastgames/witness/items/renderer/PuzzlePanelRenderer.kt b/src/main/kotlin/com/xfastgames/witness/items/renderer/PuzzlePanelRenderer.kt index 3b6bc4b..cb848f5 100644 --- a/src/main/kotlin/com/xfastgames/witness/items/renderer/PuzzlePanelRenderer.kt +++ b/src/main/kotlin/com/xfastgames/witness/items/renderer/PuzzlePanelRenderer.kt @@ -7,6 +7,8 @@ import com.xfastgames.witness.Witness import com.xfastgames.witness.items.KEY_PANEL import com.xfastgames.witness.items.data.* import com.xfastgames.witness.utils.* +import com.xfastgames.witness.utils.guava.edgeValueOf +import com.xfastgames.witness.utils.guava.incidentEdges import net.fabricmc.fabric.api.client.rendering.v1.BuiltinItemRendererRegistry import net.minecraft.client.MinecraftClient import net.minecraft.client.render.RenderLayer @@ -124,7 +126,7 @@ object PuzzlePanelRenderer : BuiltinItemRendererRegistry.DynamicItemRenderer { private fun numberOfEdgesVisible(graph: ValueGraph, node: Node): Int = graph.incidentEdges(node).count { endpointPair -> - graph.edgeValue(endpointPair).value !in listOf(Edge.NONE, Edge.HIDDEN) + graph.edgeValueOf(endpointPair) !in listOf(Edge.NONE, Edge.HIDDEN) } private fun RenderContext.renderNode(graph: ValueGraph, node: Node): Unit = when { @@ -135,7 +137,7 @@ object PuzzlePanelRenderer : BuiltinItemRendererRegistry.DynamicItemRenderer { } private fun RenderContext.renderEdge(graph: ValueGraph, side: EndpointPair) { - val edge: Edge = graph.edgeValue(side).value ?: return + val edge: Edge = graph.edgeValueOf(side) ?: return val startNode: Node = side.nodeU() val endNode: Node = side.nodeV() val start = Vec3f(startNode.x, startNode.y, 0f) diff --git a/src/main/kotlin/com/xfastgames/witness/screens/composer/PuzzleComposerScreen.kt b/src/main/kotlin/com/xfastgames/witness/screens/composer/PuzzleComposerScreen.kt index eb6f99b..9a2ce00 100644 --- a/src/main/kotlin/com/xfastgames/witness/screens/composer/PuzzleComposerScreen.kt +++ b/src/main/kotlin/com/xfastgames/witness/screens/composer/PuzzleComposerScreen.kt @@ -19,6 +19,7 @@ import com.xfastgames.witness.screens.widgets.icons.BreakIcon import com.xfastgames.witness.screens.widgets.icons.EndIcon import com.xfastgames.witness.screens.widgets.icons.StartIcon import com.xfastgames.witness.utils.* +import com.xfastgames.witness.utils.guava.putEdgeValue import io.github.cottonmc.cotton.gui.SyncedGuiDescription import io.github.cottonmc.cotton.gui.client.BackgroundPainter import io.github.cottonmc.cotton.gui.client.CottonInventoryScreen @@ -211,7 +212,7 @@ class PuzzleComposerScreenDescription( val neighbours: List = outputPuzzle.graph.adjacentNodes(node).toList() val neighbourhood: MutableMap = mutableMapOf() neighbours.forEach { neighbour -> - neighbourhood[neighbour] = outputPuzzle.graph.edgeValue(neighbour, node).get() + neighbourhood[neighbour] = outputPuzzle.graph.edgeValue(neighbour, node) } updatedGraph.removeNode(node) updatedGraph.addNode(updatedNode) diff --git a/src/main/kotlin/com/xfastgames/witness/screens/solver/PuzzleSolverScreen.kt b/src/main/kotlin/com/xfastgames/witness/screens/solver/PuzzleSolverScreen.kt index 593dd97..96b6924 100644 --- a/src/main/kotlin/com/xfastgames/witness/screens/solver/PuzzleSolverScreen.kt +++ b/src/main/kotlin/com/xfastgames/witness/screens/solver/PuzzleSolverScreen.kt @@ -3,7 +3,6 @@ package com.xfastgames.witness.screens.solver import com.google.common.graph.EndpointPair import com.google.common.graph.Graph import com.google.common.graph.MutableGraph -import com.google.common.graph.Traverser import com.xfastgames.witness.Witness import com.xfastgames.witness.blocks.redstone.IronPuzzleFrameBlock import com.xfastgames.witness.entities.PuzzleFrameBlockEntity @@ -14,6 +13,8 @@ import com.xfastgames.witness.items.data.* import com.xfastgames.witness.screens.solver.PuzzleSolverScreen.Sounds.Instances.FOCUS_MODE_DOING_INSTANCE import com.xfastgames.witness.sounds.LoopingSoundInstance import com.xfastgames.witness.utils.* +import com.xfastgames.witness.utils.guava.Traverser +import com.xfastgames.witness.utils.guava.hasEdgeConnecting import com.xfastgames.witness.utils.guava.mutableGraph import kotlinx.coroutines.FlowPreview import net.fabricmc.api.EnvType @@ -137,7 +138,7 @@ class PuzzleSolverScreen : Screen(NarratorManager.EMPTY) { val (clampedClickX, clampedClickY) = panelHitResult.position - val line: List = Traverser.forGraph(previousLine).breadthFirst(start).toList() + val line: List = Traverser.forGraph(previousLine).depthFirst(start).toList() val lastNode: Node = line.last { it.modifier != Modifier.END } val nodeBeforeLastNode: Node? = lastNode.let { line.getOrNull(line.indexOf(lastNode) - 1) } @@ -156,9 +157,11 @@ class PuzzleSolverScreen : Screen(NarratorManager.EMPTY) { updatedLine.putEdge(newEnd, lastNode) } - val updatedSolution: List = Traverser.forGraph(updatedLine).breadthFirst(start).toList() + val updatedSolution: List = Traverser.forGraph(updatedLine).depthFirst(start) val updatedEnd: Node? = updatedSolution.firstOrNull { it.modifier == Modifier.END } + // TODO: Looks like this maybe broken after removing guava traverser, + // but seems to work on standalone builds weirdly enough when { // If over an node, and the node is not already part of solution overNode != null && @@ -182,7 +185,7 @@ class PuzzleSolverScreen : Screen(NarratorManager.EMPTY) { val solution: List = if (updatedLine.nodes().contains(start)) - Traverser.forGraph(updatedLine).breadthFirst(start).toList() + Traverser.forGraph(updatedLine).depthFirst(start).toList() else emptyList() // Remove nodes that are not a part of the main line diff --git a/src/main/kotlin/com/xfastgames/witness/screens/widgets/WPuzzleEditor.kt b/src/main/kotlin/com/xfastgames/witness/screens/widgets/WPuzzleEditor.kt index ea33c05..398cc3a 100644 --- a/src/main/kotlin/com/xfastgames/witness/screens/widgets/WPuzzleEditor.kt +++ b/src/main/kotlin/com/xfastgames/witness/screens/widgets/WPuzzleEditor.kt @@ -7,6 +7,7 @@ import com.xfastgames.witness.items.data.Node import com.xfastgames.witness.items.data.Panel import com.xfastgames.witness.items.data.getPanel import com.xfastgames.witness.items.renderer.PuzzlePanelRenderer +import com.xfastgames.witness.utils.guava.edgeValueOf import com.xfastgames.witness.utils.intersects import com.xfastgames.witness.utils.rotate import io.github.cottonmc.cotton.gui.client.BackgroundPainter @@ -136,7 +137,7 @@ class WPuzzleEditor( result } - val edge: Edge? = edgeNodePair?.let { inputPuzzle.graph.edgeValue(it).orElse(null) } + val edge: Edge? = edgeNodePair?.let { inputPuzzle.graph.edgeValueOf(it) } onClickListener?.onClick(node, edge, edgeNodePair) return InputResult.PROCESSED diff --git a/src/main/kotlin/com/xfastgames/witness/utils/guava/Graph.kt b/src/main/kotlin/com/xfastgames/witness/utils/guava/Graph.kt index 817eeee..b912fd3 100644 --- a/src/main/kotlin/com/xfastgames/witness/utils/guava/Graph.kt +++ b/src/main/kotlin/com/xfastgames/witness/utils/guava/Graph.kt @@ -6,7 +6,10 @@ import com.google.common.graph.Graph import com.google.common.graph.GraphBuilder import com.google.common.graph.MutableGraph -val Graph.adjacencyMatrix: List> +fun Graph.hasEdgeConnecting(thisNode: N, thatNode: N): Boolean = + this.adjacentNodes(thisNode).contains(thatNode) + +val Graph.adjacencyMatrix: List> get() = this.nodes().map { thisNode -> this.nodes().map { thatNode -> this.hasEdgeConnecting(thisNode, thatNode) diff --git a/src/main/kotlin/com/xfastgames/witness/utils/guava/MutableValueGraph.kt b/src/main/kotlin/com/xfastgames/witness/utils/guava/MutableValueGraph.kt new file mode 100644 index 0000000..49a6397 --- /dev/null +++ b/src/main/kotlin/com/xfastgames/witness/utils/guava/MutableValueGraph.kt @@ -0,0 +1,8 @@ +package com.xfastgames.witness.utils.guava + +import com.google.common.graph.EndpointPair +import com.google.common.graph.MutableValueGraph + +@Suppress("UnstableApiUsage") +fun MutableValueGraph.putEdgeValue(pair: EndpointPair, edge: E) = + this.putEdgeValue(pair.nodeU(), pair.nodeV(), edge) \ No newline at end of file diff --git a/src/main/kotlin/com/xfastgames/witness/utils/guava/Traverser.kt b/src/main/kotlin/com/xfastgames/witness/utils/guava/Traverser.kt new file mode 100644 index 0000000..26333b7 --- /dev/null +++ b/src/main/kotlin/com/xfastgames/witness/utils/guava/Traverser.kt @@ -0,0 +1,19 @@ +package com.xfastgames.witness.utils.guava + +import com.google.common.graph.Graph + +@Suppress("UnstableApiUsage") +class Traverser(private val graph: Graph) { + + fun depthFirst(start: N, traversedNodes: MutableList = mutableListOf(start)): List { + val adjacentNodes: MutableSet = graph.adjacentNodes(start) + val nextNode: N? = adjacentNodes.firstOrNull { node -> node !in traversedNodes } + if (nextNode != null) traversedNodes.add(nextNode) + else return traversedNodes + return depthFirst(nextNode, traversedNodes) + } + + companion object { + fun forGraph(graph: Graph): Traverser = Traverser(graph) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/xfastgames/witness/utils/guava/ValueGraph.kt b/src/main/kotlin/com/xfastgames/witness/utils/guava/ValueGraph.kt index d606c8d..76d9323 100644 --- a/src/main/kotlin/com/xfastgames/witness/utils/guava/ValueGraph.kt +++ b/src/main/kotlin/com/xfastgames/witness/utils/guava/ValueGraph.kt @@ -2,20 +2,29 @@ package com.xfastgames.witness.utils.guava +import com.google.common.graph.EndpointPair import com.google.common.graph.MutableValueGraph import com.google.common.graph.ValueGraph import com.google.common.graph.ValueGraphBuilder -import com.xfastgames.witness.utils.value -val ValueGraph.adjacencyMatrix: List> +fun ValueGraph.edgeValueOf(u: N, v: N): E? = + edgeValueOrDefault(u, v, null) + +fun ValueGraph.edgeValueOf(pair: EndpointPair): E? = + edgeValueOf(pair.nodeU(), pair.nodeV()) + +fun ValueGraph.incidentEdges(node: N): List> = + this.edges().filter { endpointPair -> endpointPair.contains(node) } + +val ValueGraph.adjacencyMatrix: List> get() = this.nodes().map { thisNode -> - this.nodes().map { thatNode -> - this.edgeValue(thisNode, thatNode).value - } + this.nodes().map { thatNode -> this.edgeValueOf(thisNode, thatNode) } } -inline fun ValueGraph.edgeValues(): List = - this.edges().map { nodePair -> this.edgeValue(nodePair).orElse(null) }.filterIsInstance() +inline fun ValueGraph.edgeValues(): List = + this.edges() + .map { nodePair -> this.edgeValue(nodePair.nodeU(), nodePair.nodeV()) } + .filterIsInstance() /*** * Adds a [nodeList] to a existing graph with the given [adjacencyMatrix] diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 43a335c..366dee5 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -29,7 +29,6 @@ "fabricloader": ">=0.11.6", "fabric": "*", "fabric-language-kotlin": "*", - "libgui": "*", "nbtcrafting": "*", "minecraft": "1.17.x" }, diff --git a/src/test/kotlin/com/xfastgames/witness/items/data/GraphTests.kt b/src/test/kotlin/com/xfastgames/witness/items/data/GraphTests.kt index 9a6a958..396ebc7 100644 --- a/src/test/kotlin/com/xfastgames/witness/items/data/GraphTests.kt +++ b/src/test/kotlin/com/xfastgames/witness/items/data/GraphTests.kt @@ -12,8 +12,6 @@ import org.junit.jupiter.api.Test const val KEY_GRAPH = "testGraph" -enum class Person { Bob, Alice, Rob, Maria, Mark } - @Suppress("UnstableApiUsage") class GraphTests { @@ -21,6 +19,7 @@ class GraphTests { private val bottomLeft = Node(1f, 0f) private val topRight = Node(0f, 1f) private val topLeft = Node(1f, 1f, Modifier.END) + private val testGraph: MutableValueGraph = ValueGraphBuilder.undirected() .build().apply { putEdgeValue(bottomRight, topRight, Modifier.NORMAL) @@ -153,7 +152,7 @@ class GraphTests { @Test fun `Test nearest Edge from bottom right to middle`() { val actual: EdgeResult? = testGraph.nearestEdge(.5f, .5f, bottomRight) - val expect: EdgeResult = EdgeResult(.0f, .5f, EndpointPair.unordered(topRight, bottomRight)) + val expect = EdgeResult(.0f, .5f, EndpointPair.unordered(topRight, bottomRight)) assertThat(actual).isEqualTo(expect) } } diff --git a/src/test/kotlin/com/xfastgames/witness/utils/GuavaTests.kt b/src/test/kotlin/com/xfastgames/witness/utils/GuavaTests.kt new file mode 100644 index 0000000..36781b2 --- /dev/null +++ b/src/test/kotlin/com/xfastgames/witness/utils/GuavaTests.kt @@ -0,0 +1,69 @@ +package com.xfastgames.witness.utils + +import com.google.common.graph.MutableValueGraph +import com.google.common.graph.ValueGraphBuilder +import com.google.common.truth.Truth +import com.xfastgames.witness.utils.guava.Traverser +import com.xfastgames.witness.utils.guava.add +import com.xfastgames.witness.utils.guava.adjacencyMatrix +import org.junit.jupiter.api.DisplayName +import org.junit.jupiter.api.Nested +import org.junit.jupiter.api.Test + +enum class Person { Bob, Alice, Rob, Maria, Mark } + +@Suppress("UnstableApiUsage") +class ValueGraphTests { + private val testNodes: List = Person.values().toList() + + private val testAdjacencyMatrix: List> = listOf( + // Bob, Alice, Rob, Maria, Mark + listOf(null, 1.0, 0.75, null, null), // Bob + listOf(1.0, null, null, 0.75, 0.5), // Alice + listOf(0.75, null, null, 1.0, 0.5), // Rob + listOf(null, 0.75, 1.0, null, null), // Maria + listOf(null, 0.5, 0.5, null, null) // Mark + ) + + /** + * Based on ![graph](https://www.baeldung.com/wp-content/uploads/2018/11/graph3.jpg) + */ + private val testPersonGraph: MutableValueGraph = ValueGraphBuilder.undirected() + .build().apply { + putEdgeValue(Person.Bob, Person.Alice, 1.0) + putEdgeValue(Person.Bob, Person.Rob, 0.75) + putEdgeValue(Person.Alice, Person.Maria, 0.75) + putEdgeValue(Person.Maria, Person.Rob, 1.0) + putEdgeValue(Person.Alice, Person.Mark, .5) + putEdgeValue(Person.Mark, Person.Rob, .5) + } + + @Nested + @DisplayName("Test grid generation") + inner class ValueGraphTests { + @Test + fun `Test if the network adjacency matrix is setup correct`() { + val actual: List> = testPersonGraph.adjacencyMatrix + Truth.assertThat(actual).isEqualTo(testAdjacencyMatrix) + } + + @Test + fun `Test if the network can be build from a set of nodes and adjacency matrix`() { + val actual: MutableValueGraph = ValueGraphBuilder.undirected().build() + actual.add(testNodes, testAdjacencyMatrix) + Truth.assertThat(actual).isEqualTo(testPersonGraph) + } + } + + @Nested + @DisplayName("Test traverser") + inner class TraverserTests { + private val testTraverser: Traverser = Traverser.forGraph(testPersonGraph.asGraph()) + + @Test + fun `Test depth first`() { + val actual: List = testTraverser.depthFirst(Person.Alice) + println(actual) + } + } +} \ No newline at end of file diff --git a/src/test/kotlin/com/xfastgames/witness/utils/ValueGraphTests.kt b/src/test/kotlin/com/xfastgames/witness/utils/ValueGraphTests.kt deleted file mode 100644 index a24faff..0000000 --- a/src/test/kotlin/com/xfastgames/witness/utils/ValueGraphTests.kt +++ /dev/null @@ -1,56 +0,0 @@ -package com.xfastgames.witness.utils - -import com.google.common.graph.MutableValueGraph -import com.google.common.graph.ValueGraphBuilder -import com.google.common.truth.Truth -import com.xfastgames.witness.items.data.Person -import com.xfastgames.witness.utils.guava.add -import com.xfastgames.witness.utils.guava.adjacencyMatrix -import org.junit.jupiter.api.DisplayName -import org.junit.jupiter.api.Nested -import org.junit.jupiter.api.Test - -@Suppress("UnstableApiUsage") -class ValueGraphTests { - - @Nested - @DisplayName("Test grid generation") - inner class ValueGraphTests { - private val testNodes: List = Person.values().toList() - - private val testAdjacencyMatrix: List> = listOf( - // Bob, Alice, Rob, Maria, Mark - listOf(null, 1.0, 0.75, null, null), // Bob - listOf(1.0, null, null, 0.75, 0.5), // Alice - listOf(0.75, null, null, 1.0, 0.5), // Rob - listOf(null, 0.75, 1.0, null, null), // Maria - listOf(null, 0.5, 0.5, null, null) // Mark - ) - - /** - * Based on https://www.baeldung.com/wp-content/uploads/2018/11/graph3.jpg - */ - private val testPersonGraph: MutableValueGraph = ValueGraphBuilder.undirected() - .build().apply { - putEdgeValue(Person.Bob, Person.Alice, 1.0) - putEdgeValue(Person.Bob, Person.Rob, 0.75) - putEdgeValue(Person.Alice, Person.Maria, 0.75) - putEdgeValue(Person.Maria, Person.Rob, 1.0) - putEdgeValue(Person.Alice, Person.Mark, .5) - putEdgeValue(Person.Mark, Person.Rob, .5) - } - - @Test - fun `Test if the network adjacency matrix is setup correct`() { - val actual: List> = testPersonGraph.adjacencyMatrix - Truth.assertThat(actual).isEqualTo(testAdjacencyMatrix) - } - - @Test - fun `Test if the network can be build from a set of nodes and adjacency matrix`() { - val actual: MutableValueGraph = ValueGraphBuilder.undirected().build() - actual.add(testNodes, testAdjacencyMatrix) - Truth.assertThat(actual).isEqualTo(testPersonGraph) - } - } -} \ No newline at end of file