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