diff options
Diffstat (limited to 'subprojects/logic/src/test/java/tools/refinery/logic/dnf/HashCodeTest.java')
-rw-r--r-- | subprojects/logic/src/test/java/tools/refinery/logic/dnf/HashCodeTest.java | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/subprojects/logic/src/test/java/tools/refinery/logic/dnf/HashCodeTest.java b/subprojects/logic/src/test/java/tools/refinery/logic/dnf/HashCodeTest.java new file mode 100644 index 00000000..e140be1e --- /dev/null +++ b/subprojects/logic/src/test/java/tools/refinery/logic/dnf/HashCodeTest.java | |||
@@ -0,0 +1,64 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: EPL-2.0 | ||
5 | */ | ||
6 | package tools.refinery.logic.dnf; | ||
7 | |||
8 | import org.junit.jupiter.api.Test; | ||
9 | import tools.refinery.logic.Constraint; | ||
10 | import tools.refinery.logic.term.NodeVariable; | ||
11 | import tools.refinery.logic.term.Variable; | ||
12 | import tools.refinery.logic.tests.FakeKeyOnlyView; | ||
13 | |||
14 | import static org.hamcrest.MatcherAssert.assertThat; | ||
15 | import static org.hamcrest.Matchers.is; | ||
16 | import static org.hamcrest.Matchers.not; | ||
17 | |||
18 | class HashCodeTest { | ||
19 | private static final Constraint personView = new FakeKeyOnlyView("Person", 1); | ||
20 | private static final Constraint friendView = new FakeKeyOnlyView("friend", 2); | ||
21 | private static final NodeVariable p = Variable.of("p"); | ||
22 | private static final NodeVariable q = Variable.of("q"); | ||
23 | |||
24 | @Test | ||
25 | void flatEqualsTest() { | ||
26 | var expected = Dnf.builder("Expected").parameters(q).clause(personView.call(q)).build(); | ||
27 | var actual = Dnf.builder("Actual").parameters(p).clause(personView.call(p)).build(); | ||
28 | |||
29 | assertThat(actual.hashCodeWithSubstitution(), is(expected.hashCodeWithSubstitution())); | ||
30 | } | ||
31 | |||
32 | @Test | ||
33 | void flatNotEqualsTest() { | ||
34 | var expected = Dnf.builder("Expected").parameters(q).clause(friendView.call(q, q)).build(); | ||
35 | var actual = Dnf.builder("Actual").parameters(p).clause(friendView.call(p, q)).build(); | ||
36 | |||
37 | assertThat(actual.hashCodeWithSubstitution(), not(expected.hashCodeWithSubstitution())); | ||
38 | } | ||
39 | |||
40 | @Test | ||
41 | void deepEqualsTest() { | ||
42 | var expected2 = Dnf.builder("Expected2").parameters(p).clause(personView.call(p)).build(); | ||
43 | var expected = Dnf.builder("Expected").parameters(q).clause( | ||
44 | expected2.call(q) | ||
45 | ).build(); | ||
46 | var actual = Dnf.builder("Actual").parameters(q).clause( | ||
47 | expected2.call(q) | ||
48 | ).build(); | ||
49 | |||
50 | assertThat(actual.hashCodeWithSubstitution(), is(expected.hashCodeWithSubstitution())); | ||
51 | } | ||
52 | |||
53 | @Test | ||
54 | void deepNotEqualsTest() { | ||
55 | var expected = Dnf.builder("Expected").parameters(q).clause( | ||
56 | Dnf.builder("Expected2").parameters(p).clause(personView.call(p)).build().call(q) | ||
57 | ).build(); | ||
58 | var actual = Dnf.builder("Actual").parameters(q).clause( | ||
59 | Dnf.builder("Actual2").parameters(p).clause(personView.call(p)).build().call(q) | ||
60 | ).build(); | ||
61 | |||
62 | assertThat(actual.hashCodeWithSubstitution(), not(expected.hashCodeWithSubstitution())); | ||
63 | } | ||
64 | } | ||