summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2017-10-25 18:37:03 -0700
committerLi Haoyi <haoyi.sg@gmail.com>2017-10-25 18:37:03 -0700
commite277bc8143de898f5e013bbfc28d0ff071ff75cb (patch)
treec5a5f091e52fa7b820c5f694a0f198309e54aea3 /src
parent8175b657bd5d008db67fc5d4f28e8463acb8d1ad (diff)
downloadmill-e277bc8143de898f5e013bbfc28d0ff071ff75cb.tar.gz
mill-e277bc8143de898f5e013bbfc28d0ff071ff75cb.tar.bz2
mill-e277bc8143de898f5e013bbfc28d0ff071ff75cb.zip
Flesh out `evaluate` tests for `diamond` and `anonDiamond` cases
Diffstat (limited to 'src')
-rw-r--r--src/test/scala/forge/ForgeTests.scala89
1 files changed, 63 insertions, 26 deletions
diff --git a/src/test/scala/forge/ForgeTests.scala b/src/test/scala/forge/ForgeTests.scala
index cf903461..51df4c5f 100644
--- a/src/test/scala/forge/ForgeTests.scala
+++ b/src/test/scala/forge/ForgeTests.scala
@@ -160,55 +160,92 @@ object ForgeTests extends TestSuite{
}
}
- 'evaluate - {
- def check(targets: Seq[Target[_]],
- expectedValues: Seq[Any],
- expectedEvaluated: Seq[Target[_]]) = {
- val Evaluator.Results(returnedValues, returnedEvaluated) = evaluator.evaluate(targets)
+ 'evaluateSingle - {
+ def check(target: Target[_],
+ expValue: Any,
+ expEvaled: Seq[Target[_]]) = {
+ val Evaluator.Results(returnedValues, returnedEvaluated) = evaluator.evaluate(Seq(target))
assert(
- returnedValues == expectedValues,
- returnedEvaluated == expectedEvaluated
+ returnedValues == Seq(expValue),
+ returnedEvaluated == expEvaled
+ )
+ // Second time the value is already cached, so no evaluation needed
+ val Evaluator.Results(returnedValues2, returnedEvaluated2) = evaluator.evaluate(Seq(target))
+ assert(
+ returnedValues2 == returnedValues,
+ returnedEvaluated2 == Nil
)
-
}
+
'singleton - {
import Singleton._
// First time the target is evaluated
- check(Seq(single), expectedValues = Seq(0), expectedEvaluated = Seq(single))
- // Second time the value is already cached, so no evaluation needed
- check(Seq(single), expectedValues = Seq(0), expectedEvaluated = Seq())
+ check(single, expValue = 0, expEvaled = Seq(single))
+
single.counter += 1
// After incrementing the counter, it forces re-evaluation
- check(Seq(single), expectedValues = Seq(1), expectedEvaluated = Seq(single))
- // Then it's cached again
- check(Seq(single), expectedValues = Seq(1), expectedEvaluated = Seq())
+ check(single, expValue = 1, expEvaled = Seq(single))
}
'pair - {
import Pair._
- check(Seq(down), expectedValues = Seq(0), expectedEvaluated = Seq(up, down))
- check(Seq(down), expectedValues = Seq(0), expectedEvaluated = Seq())
+ check(down, expValue = 0, expEvaled = Seq(up, down))
down.counter += 1
- check(Seq(down), expectedValues = Seq(1), expectedEvaluated = Seq(down))
- check(Seq(down), expectedValues = Seq(1), expectedEvaluated = Seq())
+ check(down, expValue = 1, expEvaled = Seq(down))
up.counter += 1
- check(Seq(down), expectedValues = Seq(2), expectedEvaluated = Seq(up, down))
- check(Seq(down), expectedValues = Seq(2), expectedEvaluated = Seq())
+ check(down, expValue = 2, expEvaled = Seq(up, down))
}
'anonTriple - {
import AnonTriple._
val middle = down.inputs(0)
- check(Seq(down), expectedValues = Seq(0), expectedEvaluated = Seq(up, middle, down))
- check(Seq(down), expectedValues = Seq(0), expectedEvaluated = Seq())
+ check(down, expValue = 0, expEvaled = Seq(up, middle, down))
+
+ down.counter += 1
+ check(down, expValue = 1, expEvaled = Seq(down))
+
+ up.counter += 1
+ check(down, expValue = 2, expEvaled = Seq(up, middle, down))
+
+ middle.asInstanceOf[Target.Test].counter += 1
+
+ check(down, expValue = 3, expEvaled = Seq(middle, down))
+ }
+ 'diamond - {
+ import Diamond._
+ check(down, expValue = 0, expEvaled = Seq(up, left, right, down))
+
+ down.counter += 1
+ check(down, expValue = 1, expEvaled = Seq(down))
+
+ up.counter += 1
+ // Increment by 2 because up is referenced twice: once by left once by right
+ check(down, expValue = 3, expEvaled = Seq(up, left, right, down))
+
+ left.counter += 1
+ check(down, expValue = 4, expEvaled = Seq(left, down))
+
+ right.counter += 1
+ check(down, expValue = 5, expEvaled = Seq(right, down))
+ }
+ 'anoniamond - {
+ import AnonDiamond._
+ val left = down.inputs(0).asInstanceOf[Target.Test]
+ val right = down.inputs(1).asInstanceOf[Target.Test]
+ check(down, expValue = 0, expEvaled = Seq(up, left, right, down))
down.counter += 1
- check(Seq(down), expectedValues = Seq(1), expectedEvaluated = Seq(down))
- check(Seq(down), expectedValues = Seq(1), expectedEvaluated = Seq())
+ check(down, expValue = 1, expEvaled = Seq(down))
up.counter += 1
- check(Seq(down), expectedValues = Seq(2), expectedEvaluated = Seq(up, middle, down))
- check(Seq(down), expectedValues = Seq(2), expectedEvaluated = Seq())
+ // Increment by 2 because up is referenced twice: once by left once by right
+ check(down, expValue = 3, expEvaled = Seq(up, left, right, down))
+
+ left.counter += 1
+ check(down, expValue = 4, expEvaled = Seq(left, down))
+
+ right.counter += 1
+ check(down, expValue = 5, expEvaled = Seq(right, down))
}
}