diff options
author | Kristóf Marussy <kristof@marussy.com> | 2021-11-06 16:49:58 +0100 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2021-11-06 16:49:58 +0100 |
commit | 8131e670d8fc86d0f2b3035d8155d35ec6a80f9b (patch) | |
tree | 2d805f058ab6b4289d4338b8f6beb12c51c31d09 /language/src | |
parent | chore(lang): shorten keyword individual -> indiv (diff) | |
download | refinery-8131e670d8fc86d0f2b3035d8155d35ec6a80f9b.tar.gz refinery-8131e670d8fc86d0f2b3035d8155d35ec6a80f9b.tar.zst refinery-8131e670d8fc86d0f2b3035d8155d35ec6a80f9b.zip |
chore(lang): seralize assertions in short form
Prefer the ! and ? operators instead of : false and : unknown and omit
: true when serializing assertions.
Diffstat (limited to 'language/src')
-rw-r--r-- | language/src/main/java/tools/refinery/language/Problem.xtext | 10 | ||||
-rw-r--r-- | language/src/test/java/tools/refinery/language/tests/serializer/ProblemSerializerTest.java | 48 |
2 files changed, 37 insertions, 21 deletions
diff --git a/language/src/main/java/tools/refinery/language/Problem.xtext b/language/src/main/java/tools/refinery/language/Problem.xtext index e2723b55..26773047 100644 --- a/language/src/main/java/tools/refinery/language/Problem.xtext +++ b/language/src/main/java/tools/refinery/language/Problem.xtext | |||
@@ -109,12 +109,12 @@ ConstantArgument: | |||
109 | 109 | ||
110 | Assertion: | 110 | Assertion: |
111 | default?="default"? | 111 | default?="default"? |
112 | (relation=[Relation|QualifiedName] | 112 | (value=ShortLogicValue? |
113 | "(" (arguments+=AssertionArgument ("," arguments+=AssertionArgument)*)? ")" | ||
114 | ":" value=LogicValue | | ||
115 | value=ShortLogicValue? | ||
116 | relation=[Relation|QualifiedName] | 113 | relation=[Relation|QualifiedName] |
117 | "(" (arguments+=AssertionArgument ("," arguments+=AssertionArgument)*)? ")") | 114 | "(" (arguments+=AssertionArgument ("," arguments+=AssertionArgument)*)? ")" |
115 | | relation=[Relation|QualifiedName] | ||
116 | "(" (arguments+=AssertionArgument ("," arguments+=AssertionArgument)*)? ")" | ||
117 | ":" value=LogicValue) | ||
118 | "."; | 118 | "."; |
119 | 119 | ||
120 | AssertionArgument: | 120 | AssertionArgument: |
diff --git a/language/src/test/java/tools/refinery/language/tests/serializer/ProblemSerializerTest.java b/language/src/test/java/tools/refinery/language/tests/serializer/ProblemSerializerTest.java index 303da50f..802457cb 100644 --- a/language/src/test/java/tools/refinery/language/tests/serializer/ProblemSerializerTest.java +++ b/language/src/test/java/tools/refinery/language/tests/serializer/ProblemSerializerTest.java | |||
@@ -6,6 +6,7 @@ import static org.hamcrest.Matchers.equalTo; | |||
6 | import java.io.ByteArrayOutputStream; | 6 | import java.io.ByteArrayOutputStream; |
7 | import java.io.IOException; | 7 | import java.io.IOException; |
8 | import java.util.Map; | 8 | import java.util.Map; |
9 | import java.util.stream.Stream; | ||
9 | 10 | ||
10 | import org.eclipse.emf.common.util.URI; | 11 | import org.eclipse.emf.common.util.URI; |
11 | import org.eclipse.emf.ecore.resource.Resource; | 12 | import org.eclipse.emf.ecore.resource.Resource; |
@@ -15,6 +16,9 @@ import org.eclipse.xtext.testing.extensions.InjectionExtension; | |||
15 | import org.junit.jupiter.api.BeforeEach; | 16 | import org.junit.jupiter.api.BeforeEach; |
16 | import org.junit.jupiter.api.Test; | 17 | import org.junit.jupiter.api.Test; |
17 | import org.junit.jupiter.api.extension.ExtendWith; | 18 | import org.junit.jupiter.api.extension.ExtendWith; |
19 | import org.junit.jupiter.params.ParameterizedTest; | ||
20 | import org.junit.jupiter.params.provider.Arguments; | ||
21 | import org.junit.jupiter.params.provider.MethodSource; | ||
18 | 22 | ||
19 | import com.google.inject.Inject; | 23 | import com.google.inject.Inject; |
20 | 24 | ||
@@ -53,28 +57,36 @@ public class ProblemSerializerTest { | |||
53 | builtin = ProblemUtil.getBuiltInLibrary(problem).get(); | 57 | builtin = ProblemUtil.getBuiltInLibrary(problem).get(); |
54 | } | 58 | } |
55 | 59 | ||
56 | @Test | 60 | @ParameterizedTest |
57 | void implicitNodeTest() { | 61 | @MethodSource |
62 | void assertionTest(LogicValue value, String serializedAssertion) { | ||
58 | var pred = createPred(); | 63 | var pred = createPred(); |
59 | var node = ProblemFactory.eINSTANCE.createNode(); | 64 | var node = ProblemFactory.eINSTANCE.createNode(); |
60 | node.setName("a"); | 65 | node.setName("a"); |
61 | problem.getNodes().add(node); | 66 | var individualDeclaration = ProblemFactory.eINSTANCE.createIndividualDeclaration(); |
62 | createAssertion(pred, node); | 67 | individualDeclaration.getNodes().add(node); |
68 | problem.getStatements().add(individualDeclaration); | ||
69 | createAssertion(pred, node, value); | ||
63 | 70 | ||
64 | assertSerializedResult("pred foo ( node p ) . foo ( a ) : true ."); | 71 | assertSerializedResult("pred foo ( node p ) . indiv a . " + serializedAssertion); |
72 | } | ||
73 | |||
74 | static Stream<Arguments> assertionTest() { | ||
75 | return Stream.of(Arguments.of(LogicValue.TRUE, "foo ( a ) ."), | ||
76 | Arguments.of(LogicValue.FALSE, "! foo ( a ) ."), | ||
77 | Arguments.of(LogicValue.UNKNOWN, "? foo ( a ) ."), | ||
78 | Arguments.of(LogicValue.ERROR, "foo ( a ) : error .")); | ||
65 | } | 79 | } |
66 | 80 | ||
67 | @Test | 81 | @Test |
68 | void individualNodeTest() { | 82 | void implicitNodeTest() { |
69 | var pred = createPred(); | 83 | var pred = createPred(); |
70 | var node = ProblemFactory.eINSTANCE.createNode(); | 84 | var node = ProblemFactory.eINSTANCE.createNode(); |
71 | node.setName("a"); | 85 | node.setName("a"); |
72 | var individualDeclaration = ProblemFactory.eINSTANCE.createIndividualDeclaration(); | 86 | problem.getNodes().add(node); |
73 | individualDeclaration.getNodes().add(node); | ||
74 | problem.getStatements().add(individualDeclaration); | ||
75 | createAssertion(pred, node); | 87 | createAssertion(pred, node); |
76 | 88 | ||
77 | assertSerializedResult("pred foo ( node p ) . indiv a . foo ( a ) : true ."); | 89 | assertSerializedResult("pred foo ( node p ) . foo ( a ) ."); |
78 | } | 90 | } |
79 | 91 | ||
80 | private PredicateDefinition createPred() { | 92 | private PredicateDefinition createPred() { |
@@ -88,7 +100,7 @@ public class ProblemSerializerTest { | |||
88 | problem.getStatements().add(pred); | 100 | problem.getStatements().add(pred); |
89 | return pred; | 101 | return pred; |
90 | } | 102 | } |
91 | 103 | ||
92 | @Test | 104 | @Test |
93 | void newNodeTest() { | 105 | void newNodeTest() { |
94 | var classDeclaration = ProblemFactory.eINSTANCE.createClassDeclaration(); | 106 | var classDeclaration = ProblemFactory.eINSTANCE.createClassDeclaration(); |
@@ -99,16 +111,20 @@ public class ProblemSerializerTest { | |||
99 | problem.getStatements().add(classDeclaration); | 111 | problem.getStatements().add(classDeclaration); |
100 | createAssertion(classDeclaration, newNode); | 112 | createAssertion(classDeclaration, newNode); |
101 | 113 | ||
102 | assertSerializedResult("class Foo . Foo ( Foo::new ) : true ."); | 114 | assertSerializedResult("class Foo . Foo ( Foo::new ) ."); |
103 | } | 115 | } |
104 | 116 | ||
105 | private void createAssertion(Relation relation, Node node) { | 117 | private void createAssertion(Relation relation, Node node) { |
118 | createAssertion(relation, node, LogicValue.TRUE); | ||
119 | } | ||
120 | |||
121 | private void createAssertion(Relation relation, Node node, LogicValue value) { | ||
106 | var assertion = ProblemFactory.eINSTANCE.createAssertion(); | 122 | var assertion = ProblemFactory.eINSTANCE.createAssertion(); |
107 | assertion.setRelation(relation); | 123 | assertion.setRelation(relation); |
108 | var argument = ProblemFactory.eINSTANCE.createNodeAssertionArgument(); | 124 | var argument = ProblemFactory.eINSTANCE.createNodeAssertionArgument(); |
109 | argument.setNode(node); | 125 | argument.setNode(node); |
110 | assertion.getArguments().add(argument); | 126 | assertion.getArguments().add(argument); |
111 | assertion.setValue(LogicValue.TRUE); | 127 | assertion.setValue(value); |
112 | problem.getStatements().add(assertion); | 128 | problem.getStatements().add(assertion); |
113 | } | 129 | } |
114 | 130 | ||
@@ -149,7 +165,7 @@ public class ProblemSerializerTest { | |||
149 | atom.getArguments().add(arg2); | 165 | atom.getArguments().add(arg2); |
150 | return atom; | 166 | return atom; |
151 | } | 167 | } |
152 | 168 | ||
153 | @Test | 169 | @Test |
154 | void singletonVariableTest() { | 170 | void singletonVariableTest() { |
155 | var pred = ProblemFactory.eINSTANCE.createPredicateDefinition(); | 171 | var pred = ProblemFactory.eINSTANCE.createPredicateDefinition(); |
@@ -175,7 +191,7 @@ public class ProblemSerializerTest { | |||
175 | conjunction.getLiterals().add(atom); | 191 | conjunction.getLiterals().add(atom); |
176 | pred.getBodies().add(conjunction); | 192 | pred.getBodies().add(conjunction); |
177 | problem.getStatements().add(pred); | 193 | problem.getStatements().add(pred); |
178 | 194 | ||
179 | assertSerializedResult("pred foo ( node p ) <-> equals ( p , _q ) ."); | 195 | assertSerializedResult("pred foo ( node p ) <-> equals ( p , _q ) ."); |
180 | } | 196 | } |
181 | 197 | ||