diff options
author | 2019-05-10 17:27:13 -0400 | |
---|---|---|
committer | 2019-05-10 17:27:13 -0400 | |
commit | 9670538a0e5630edecab8aaf4ba38ae6c81e8606 (patch) | |
tree | 155c4dc953dec6d99b5c89ae1029863b3db9ca94 /Tests/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.tests/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/tests | |
parent | More aggregation operators (diff) | |
download | VIATRA-Generator-9670538a0e5630edecab8aaf4ba38ae6c81e8606.tar.gz VIATRA-Generator-9670538a0e5630edecab8aaf4ba38ae6c81e8606.tar.zst VIATRA-Generator-9670538a0e5630edecab8aaf4ba38ae6c81e8606.zip |
Interval power and aggregator fix
Diffstat (limited to 'Tests/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.tests/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/tests')
-rw-r--r-- | Tests/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.tests/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/tests/interval/MinAggregatorTest.xtend | 67 | ||||
-rw-r--r-- | Tests/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.tests/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/tests/interval/PowerTest.xtend | 43 | ||||
-rw-r--r-- | Tests/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.tests/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/tests/interval/SumAggregatorTest.xtend (renamed from Tests/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.tests/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/tests/interval/SumTest.xtend) | 2 |
3 files changed, 111 insertions, 1 deletions
diff --git a/Tests/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.tests/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/tests/interval/MinAggregatorTest.xtend b/Tests/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.tests/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/tests/interval/MinAggregatorTest.xtend new file mode 100644 index 00000000..7d46e16c --- /dev/null +++ b/Tests/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.tests/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/tests/interval/MinAggregatorTest.xtend | |||
@@ -0,0 +1,67 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.tests.interval | ||
2 | |||
3 | import com.google.common.collect.HashMultiset | ||
4 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.interval.Interval | ||
5 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.interval.IntervalAggregationMode | ||
6 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.interval.IntervalAggregationOperator | ||
7 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.interval.IntervalRedBlackNode | ||
8 | import java.math.BigDecimal | ||
9 | import java.util.Random | ||
10 | import org.junit.Assert | ||
11 | import org.junit.Before | ||
12 | import org.junit.Test | ||
13 | |||
14 | import static hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.interval.Interval.* | ||
15 | |||
16 | class MinAggregatorTest { | ||
17 | val aggregator = new IntervalAggregationOperator(IntervalAggregationMode.MIN) | ||
18 | var IntervalRedBlackNode value = null | ||
19 | |||
20 | @Before | ||
21 | def void reset() { | ||
22 | value = aggregator.createNeutral | ||
23 | } | ||
24 | |||
25 | @Test | ||
26 | def void emptyTest() { | ||
27 | assertEquals(EMPTY) | ||
28 | } | ||
29 | |||
30 | @Test | ||
31 | def void largeTest() { | ||
32 | val starts = #[null, new BigDecimal(-3), new BigDecimal(-2), new BigDecimal(-1)] | ||
33 | val ends = #[new BigDecimal(1), new BigDecimal(2), new BigDecimal(3), null] | ||
34 | val current = HashMultiset.create | ||
35 | val random = new Random(1) | ||
36 | for (var int i = 0; i < 1000; i++) { | ||
37 | val start = starts.get(random.nextInt(starts.size)) | ||
38 | val end = ends.get(random.nextInt(ends.size)) | ||
39 | val interval = Interval.of(start, end) | ||
40 | val isInsert = !current.contains(interval) || random.nextInt(3) == 0 | ||
41 | if (isInsert) { | ||
42 | current.add(interval) | ||
43 | } else { | ||
44 | current.remove(interval) | ||
45 | } | ||
46 | val expected = current.stream.reduce(aggregator.mode).orElse(EMPTY) | ||
47 | update(interval, isInsert) | ||
48 | assertEquals(expected) | ||
49 | } | ||
50 | } | ||
51 | |||
52 | private def update(Interval interval, boolean isInsert) { | ||
53 | value = aggregator.update(value, interval, isInsert) | ||
54 | val nodes = newArrayList | ||
55 | var node = value.min | ||
56 | while (node !== null) { | ||
57 | nodes += node | ||
58 | node = node.successor | ||
59 | } | ||
60 | value.assertSubtreeIsValid | ||
61 | } | ||
62 | |||
63 | private def assertEquals(Interval interval) { | ||
64 | val actual = aggregator.getAggregate(value) | ||
65 | Assert.assertEquals(interval, actual) | ||
66 | } | ||
67 | } | ||
diff --git a/Tests/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.tests/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/tests/interval/PowerTest.xtend b/Tests/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.tests/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/tests/interval/PowerTest.xtend new file mode 100644 index 00000000..c842d90d --- /dev/null +++ b/Tests/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.tests/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/tests/interval/PowerTest.xtend | |||
@@ -0,0 +1,43 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.tests.interval | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.interval.Interval | ||
4 | import java.util.Collection | ||
5 | import org.junit.Assert | ||
6 | import org.junit.Test | ||
7 | import org.junit.runner.RunWith | ||
8 | import org.junit.runners.Parameterized | ||
9 | import org.junit.runners.Parameterized.Parameter | ||
10 | import org.junit.runners.Parameterized.Parameters | ||
11 | |||
12 | import static hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.interval.Interval.* | ||
13 | |||
14 | @RunWith(Parameterized) | ||
15 | class PowerTest { | ||
16 | @Parameters(name="{index}: {0} ** {1} = {2}") | ||
17 | static def Collection<Object[]> data() { | ||
18 | #[ | ||
19 | #[EMPTY, EMPTY, EMPTY], | ||
20 | #[EMPTY, between(-1, 1), EMPTY], | ||
21 | #[between(-1, 1), EMPTY, EMPTY], | ||
22 | #[upTo(-1), between(-1, 2), EMPTY], | ||
23 | #[upTo(0), between(-1, 2), between(0, 0)], | ||
24 | #[upTo(2), between(-1, 2), above(0)], | ||
25 | #[upTo(2), between(1, 2), between(0, 4)], | ||
26 | #[above(1), between(1, 2), above(1)], | ||
27 | #[between(2, 4), upTo(1), between(0, 4)], | ||
28 | #[between(0.25, 0.5), upTo(1), above(0.25)], | ||
29 | #[between(2, 3), above(1), above(2)], | ||
30 | #[between(0.25, 0.5), above(1), between(0, 0.5)], | ||
31 | #[between(1, 2), between(-1, 2), between(0.5, 4)] | ||
32 | ] | ||
33 | } | ||
34 | |||
35 | @Parameter(0) public var Interval a | ||
36 | @Parameter(1) public var Interval b | ||
37 | @Parameter(2) public var Interval result | ||
38 | |||
39 | @Test | ||
40 | def void powerTest() { | ||
41 | Assert.assertEquals(result, a ** b) | ||
42 | } | ||
43 | } | ||
diff --git a/Tests/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.tests/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/tests/interval/SumTest.xtend b/Tests/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.tests/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/tests/interval/SumAggregatorTest.xtend index 530c081c..56172b6c 100644 --- a/Tests/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.tests/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/tests/interval/SumTest.xtend +++ b/Tests/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.tests/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/tests/interval/SumAggregatorTest.xtend | |||
@@ -13,7 +13,7 @@ import org.junit.Test | |||
13 | 13 | ||
14 | import static hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.interval.Interval.* | 14 | import static hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.interval.Interval.* |
15 | 15 | ||
16 | class SumTest { | 16 | class SumAggregatorTest { |
17 | val aggregator = new IntervalAggregationOperator(IntervalAggregationMode.SUM) | 17 | val aggregator = new IntervalAggregationOperator(IntervalAggregationMode.SUM) |
18 | var IntervalRedBlackNode value = null | 18 | var IntervalRedBlackNode value = null |
19 | 19 | ||