1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
package tools.refinery.store.representation.cardinality;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import tools.refinery.store.representation.cardinality.CardinalityInterval;
import java.util.stream.Stream;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static tools.refinery.store.representation.cardinality.CardinalityIntervals.*;
class CardinalityIntervalTest {
@ParameterizedTest(name = "min({0}, {1}) == {2}")
@MethodSource
void minTest(CardinalityInterval a, CardinalityInterval b, CardinalityInterval expected) {
assertThat(a.min(b), equalTo(expected));
}
static Stream<Arguments> minTest() {
return Stream.of(
Arguments.of(atMost(1), atMost(1), atMost(1)),
Arguments.of(atMost(1), between(2, 3), atMost(1)),
Arguments.of(atMost(1), atLeast(2), atMost(1)),
Arguments.of(atMost(1), ERROR, ERROR),
Arguments.of(atLeast(1), atLeast(2), atLeast(1)),
Arguments.of(atLeast(1), ERROR, ERROR),
Arguments.of(ERROR, atLeast(2), ERROR),
Arguments.of(ERROR, ERROR, ERROR)
);
}
@ParameterizedTest(name = "max({0}, {1}) == {2}")
@MethodSource
void maxTest(CardinalityInterval a, CardinalityInterval b, CardinalityInterval expected) {
assertThat(a.max(b), equalTo(expected));
}
static Stream<Arguments> maxTest() {
return Stream.of(
Arguments.of(atMost(1), atMost(1), atMost(1)),
Arguments.of(atMost(1), between(2, 3), between(2, 3)),
Arguments.of(atMost(1), atLeast(2), atLeast(2)),
Arguments.of(atMost(1), ERROR, ERROR),
Arguments.of(atLeast(1), atLeast(2), atLeast(2)),
Arguments.of(atLeast(1), ERROR, ERROR),
Arguments.of(ERROR, atLeast(2), ERROR),
Arguments.of(ERROR, ERROR, ERROR)
);
}
@ParameterizedTest(name = "{0} + {1} == {2}")
@MethodSource
void addTest(CardinalityInterval a, CardinalityInterval b, CardinalityInterval expected) {
assertThat(a.add(b), equalTo(expected));
}
static Stream<Arguments> addTest() {
return Stream.of(
Arguments.of(atMost(1), atMost(1), atMost(2)),
Arguments.of(atMost(1), between(2, 3), between(2, 4)),
Arguments.of(atMost(1), atLeast(2), atLeast(2)),
Arguments.of(atMost(1), ERROR, ERROR),
Arguments.of(atLeast(1), atLeast(2), atLeast(3)),
Arguments.of(atLeast(1), ERROR, ERROR),
Arguments.of(ERROR, atLeast(2), ERROR),
Arguments.of(ERROR, ERROR, ERROR)
);
}
@ParameterizedTest(name = "{0} * {1} == {2}")
@MethodSource
void multiplyTest(CardinalityInterval a, CardinalityInterval b, CardinalityInterval expected) {
assertThat(a.multiply(b), equalTo(expected));
}
static Stream<Arguments> multiplyTest() {
return Stream.of(
Arguments.of(between(2, 3), between(4, 5), between(8, 15)),
Arguments.of(atLeast(2), between(4, 5), atLeast(8)),
Arguments.of(between(2, 3), atLeast(4), atLeast(8)),
Arguments.of(between(2, 3), ERROR, ERROR),
Arguments.of(ERROR, between(4, 5), ERROR),
Arguments.of(ERROR, ERROR, ERROR)
);
}
@ParameterizedTest(name = "{0} /\\ {1} == {2}")
@MethodSource
void meetTest(CardinalityInterval a, CardinalityInterval b, CardinalityInterval expected) {
assertThat(a.meet(b), equalTo(expected));
}
static Stream<Arguments> meetTest() {
return Stream.of(
Arguments.of(atMost(1), atMost(2), atMost(1)),
Arguments.of(atMost(2), between(1, 3), between(1, 2)),
Arguments.of(atMost(1), between(1, 3), exactly(1)),
Arguments.of(atMost(1), between(2, 3), ERROR),
Arguments.of(atMost(1), ERROR, ERROR),
Arguments.of(ERROR, atMost(1), ERROR),
Arguments.of(ERROR, ERROR, ERROR)
);
}
@ParameterizedTest(name = "{0} \\/ {1} == {2}")
@MethodSource
void joinTest(CardinalityInterval a, CardinalityInterval b, CardinalityInterval expected) {
assertThat(a.join(b), equalTo(expected));
}
static Stream<Arguments> joinTest() {
return Stream.of(
Arguments.of(atMost(1), atMost(2), atMost(2)),
Arguments.of(atMost(2), between(1, 3), atMost(3)),
Arguments.of(atMost(1), between(2, 3), atMost(3)),
Arguments.of(atMost(1), ERROR, atMost(1)),
Arguments.of(ERROR, atMost(1), atMost(1)),
Arguments.of(ERROR, ERROR, ERROR)
);
}
}
|