aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/store-query/src/test/java/tools/refinery/store/query/literal/CallLiteralTest.java
blob: a01c65864f38b26da1acfca34c49f348b3eeeb34 (plain) (blame)
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
/*
 * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/>
 *
 * SPDX-License-Identifier: EPL-2.0
 */
package tools.refinery.store.query.literal;

import org.junit.jupiter.api.Test;
import tools.refinery.store.query.Constraint;
import tools.refinery.store.query.term.NodeVariable;
import tools.refinery.store.query.term.Parameter;
import tools.refinery.store.query.term.ParameterDirection;
import tools.refinery.store.query.term.Variable;

import java.util.List;
import java.util.Set;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.empty;
import static org.junit.jupiter.api.Assertions.assertAll;
import static tools.refinery.store.query.literal.Literals.not;

class CallLiteralTest {
	private static final NodeVariable p = Variable.of("p");
	private static final NodeVariable q = Variable.of("q");
	private static final NodeVariable r = Variable.of("r");
	private static final NodeVariable s = Variable.of("s");

	private static final Constraint fakeConstraint = new Constraint() {
		@Override
		public String name() {
			return getClass().getName();
		}

		@Override
		public List<Parameter> getParameters() {
			return List.of(
					new Parameter(null, ParameterDirection.IN),
					new Parameter(null, ParameterDirection.IN),
					new Parameter(null, ParameterDirection.OUT),
					new Parameter(null, ParameterDirection.OUT)
			);
		}
	};

	@Test
	void notRepeatedPositiveDirectionTest() {
		var literal = fakeConstraint.call(p, q, r, s);
		assertAll(
				() -> assertThat(literal.getOutputVariables(), containsInAnyOrder(r, s)),
				() -> assertThat(literal.getInputVariables(Set.of()), containsInAnyOrder(p, q)),
				() -> assertThat(literal.getInputVariables(Set.of(p, q, r)), containsInAnyOrder(p, q)),
				() -> assertThat(literal.getPrivateVariables(Set.of()), empty()),
				() -> assertThat(literal.getPrivateVariables(Set.of(p, q, r)), empty())
		);
	}

	@Test
	void notRepeatedNegativeDirectionTest() {
		var literal = not(fakeConstraint.call(p, q, r, s));
		assertAll(
				() -> assertThat(literal.getOutputVariables(), empty()),
				() -> assertThat(literal.getInputVariables(Set.of()), containsInAnyOrder(p, q)),
				() -> assertThat(literal.getInputVariables(Set.of(p, q, r)), containsInAnyOrder(p, q, r)),
				() -> assertThat(literal.getPrivateVariables(Set.of()), containsInAnyOrder(r, s)),
				() -> assertThat(literal.getPrivateVariables(Set.of(p, q, r)), containsInAnyOrder(s))
		);
	}

	@Test
	void repeatedPositiveDirectionTest() {
		var literal = fakeConstraint.call(p, p, q, q);
		assertAll(
				() -> assertThat(literal.getOutputVariables(), containsInAnyOrder(q)),
				() -> assertThat(literal.getInputVariables(Set.of()), containsInAnyOrder(p)),
				() -> assertThat(literal.getInputVariables(Set.of(p, q)), containsInAnyOrder(p)),
				() -> assertThat(literal.getPrivateVariables(Set.of()), empty()),
				() -> assertThat(literal.getPrivateVariables(Set.of(p, q)), empty())
		);
	}

	@Test
	void repeatedNegativeDirectionTest() {
		var literal = not(fakeConstraint.call(p, p, q, q));
		assertAll(
				() -> assertThat(literal.getOutputVariables(), empty()),
				() -> assertThat(literal.getInputVariables(Set.of()), containsInAnyOrder(p)),
				() -> assertThat(literal.getInputVariables(Set.of(p, q)), containsInAnyOrder(p, q)),
				() -> assertThat(literal.getPrivateVariables(Set.of()), containsInAnyOrder(q)),
				() -> assertThat(literal.getPrivateVariables(Set.of(p, q)), empty())
		);
	}
}