Skip to content

Commit

Permalink
Merge pull request #35 from kleis-technology/fix/trace-depth-map
Browse files Browse the repository at this point in the history
fix/trace depth map
  • Loading branch information
pevab authored Oct 3, 2024
2 parents d21e407 + 6858b14 commit 64bea04
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ class EvaluationTrace<Q> {

private fun updateDepthMap(port: MatrixColumnIndex<Q>, depth: Int) {
depthMap[port] = depthMap[port]?.let {
if (it >= depth - 1) max(it, depth)
else it
max(it, depth)
} ?: depth
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,57 @@ class EvaluationTraceTest {
}

@Test
fun trace_productOrder2() {
// given
val oneKg = QuantityValueFixture.oneKilogram
val product1 = ProductValueFixture.product("product1")
val product2 = ProductValueFixture.product("product2")
val product3 = ProductValueFixture.product("product3")
val product4 = ProductValueFixture.product("product4")

val p1 = ProcessValue(
name = "p1",
products = listOf(TechnoExchangeValue(oneKg, product1)),
inputs = listOf(
TechnoExchangeValue(oneKg, product2),
TechnoExchangeValue(oneKg, product4),
),
)
val p2 = ProcessValue(
name = "p2",
products = listOf(TechnoExchangeValue(oneKg, product2)),
inputs = listOf(
TechnoExchangeValue(oneKg, product3),
),
)
val p3 = ProcessValue(
name = "p3",
products = listOf(TechnoExchangeValue(oneKg, product3)),
inputs = listOf(
TechnoExchangeValue(oneKg, product4),
)
)
val trace = EvaluationTrace<BasicNumber>()
trace.addProcess(p1)
trace.commit()
trace.addProcess(p2)
trace.commit()
trace.addProcess(p3)
trace.commit()

// when
val actual = trace.getComparator()

// then
assert(actual.compare(product1, product2) < 0)
assert(actual.compare(product1, product3) < 0)
assert(actual.compare(product1, product4) < 0)
assert(actual.compare(product2, product3) < 0)
assert(actual.compare(product2, product4) < 0)
assert(actual.compare(product3, product4) < 0)
}

// Cannot satisfy both this test and the previous one
fun trace_productOrder_withLongCycle() {
// given
val oneKg = QuantityValueFixture.oneKilogram
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ javaVersion=17
gradleVersion=7.6
org.gradle.jvmargs=-Xmx4096m
lcaacGroup=ch.kleis.lcaac
lcaacVersion=1.7.5
lcaacVersion=1.7.6

0 comments on commit 64bea04

Please sign in to comment.