generated from natanfudge/fabric-example-mod-kotlin
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove guava dependencies as gabe already has a lower version of it
- Loading branch information
Showing
15 changed files
with
134 additions
and
139 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
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 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 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 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
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/com/xfastgames/witness/utils/guava/MutableValueGraph.kt
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 |
---|---|---|
@@ -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 <N : Any, E : Any> MutableValueGraph<N, E>.putEdgeValue(pair: EndpointPair<N>, edge: E) = | ||
this.putEdgeValue(pair.nodeU(), pair.nodeV(), edge) |
19 changes: 19 additions & 0 deletions
19
src/main/kotlin/com/xfastgames/witness/utils/guava/Traverser.kt
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.xfastgames.witness.utils.guava | ||
|
||
import com.google.common.graph.Graph | ||
|
||
@Suppress("UnstableApiUsage") | ||
class Traverser<N : Any>(private val graph: Graph<N>) { | ||
|
||
fun depthFirst(start: N, traversedNodes: MutableList<N> = mutableListOf(start)): List<N> { | ||
val adjacentNodes: MutableSet<N> = 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 <N : Any> forGraph(graph: Graph<N>): Traverser<N> = Traverser(graph) | ||
} | ||
} |
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 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
69 changes: 69 additions & 0 deletions
69
src/test/kotlin/com/xfastgames/witness/utils/GuavaTests.kt
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 |
---|---|---|
@@ -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> = Person.values().toList() | ||
|
||
private val testAdjacencyMatrix: List<List<Double?>> = 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  | ||
*/ | ||
private val testPersonGraph: MutableValueGraph<Person, Double> = ValueGraphBuilder.undirected() | ||
.build<Person, Double>().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<List<Double?>> = 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<Person, Double> = ValueGraphBuilder.undirected().build() | ||
actual.add(testNodes, testAdjacencyMatrix) | ||
Truth.assertThat(actual).isEqualTo(testPersonGraph) | ||
} | ||
} | ||
|
||
@Nested | ||
@DisplayName("Test traverser") | ||
inner class TraverserTests { | ||
private val testTraverser: Traverser<Person> = Traverser.forGraph(testPersonGraph.asGraph()) | ||
|
||
@Test | ||
fun `Test depth first`() { | ||
val actual: List<Person> = testTraverser.depthFirst(Person.Alice) | ||
println(actual) | ||
} | ||
} | ||
} |
Oops, something went wrong.