Skip to content

Commit 99f9df5

Browse files
committed
feat: specification for Configure
1 parent 66e0970 commit 99f9df5

2 files changed

Lines changed: 60 additions & 7 deletions

File tree

src/main/java/org/variantsync/diffdetective/variation/tree/view/relevance/Configure.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
import org.prop4j.Node;
44
import org.prop4j.NodeWriter;
5-
import org.variantsync.diffdetective.analysis.logic.SAT;
65
import org.variantsync.diffdetective.util.fide.FixTrueFalse;
76
import org.variantsync.diffdetective.util.fide.FixTrueFalse.Formula;
87
import org.variantsync.diffdetective.variation.tree.VariationNode;
98

109
import java.util.Map;
1110
import java.util.Map.Entry;
1211
import java.util.function.Consumer;
12+
import org.variantsync.diffdetective.variation.tree.view.relevance.spec.ConfigureSpec;
1313

1414
/**
1515
* Relevance predicate that generates (partial) variants from variation trees.
@@ -73,12 +73,8 @@ public Configure(final Map<String, Boolean> assignment) {
7373

7474
@Override
7575
public boolean test(VariationNode<?, ?> v) {
76-
return SAT.isSatisfiable(
77-
FixTrueFalse.Formula.and(
78-
configuration,
79-
FixTrueFalse.EliminateTrueAndFalse(v.getPresenceCondition())
80-
)
81-
);
76+
return ConfigureSpec.test(configuration, v);
77+
}
8278
}
8379

8480
@Override
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package org.variantsync.diffdetective.variation.tree.view.relevance.spec;
2+
3+
import org.prop4j.Node;
4+
import org.prop4j.NodeWriter;
5+
import org.variantsync.diffdetective.analysis.logic.SAT;
6+
import org.variantsync.diffdetective.util.fide.FixTrueFalse;
7+
import org.variantsync.diffdetective.util.fide.FixTrueFalse.Formula;
8+
import org.variantsync.diffdetective.variation.tree.VariationNode;
9+
import org.variantsync.diffdetective.variation.tree.view.relevance.Relevance;
10+
11+
/**
12+
* This class serves as a specification for {@link org.variantsync.diffdetective.variation.tree.view.relevance.Configure}.
13+
* Both classes must act semantically equivalent as a {@link Relevance} predicate.
14+
* Whereas Configure is an implementation optimized to avoid SAT calls where necessary, the implementation in ConfigureSpec
15+
* is kept simple by design to remain verifiable.
16+
* ConfigureSpec tests a partial configuration against a variation tree or diff by checking each node individually.
17+
* To this end ConfigureSpec uses the default, naive implementations of {@link Relevance} instead of providing
18+
* optimized implementations for tree traversal as Configure does.
19+
*
20+
* This class is not intended for production use and rather is supposed to be used in tests.
21+
*
22+
* @author Paul Bittner
23+
*/
24+
public record ConfigureSpec(Formula config) implements Relevance {
25+
public static boolean test(Formula formula, VariationNode<?, ?> v) {
26+
return SAT.isSatisfiable(
27+
Formula.and(
28+
formula,
29+
FixTrueFalse.EliminateTrueAndFalse(v.getPresenceCondition())
30+
)
31+
);
32+
}
33+
34+
public ConfigureSpec(final Node configuration) {
35+
this(FixTrueFalse.EliminateTrueAndFalse(configuration));
36+
}
37+
38+
@Override
39+
public boolean test(VariationNode<?, ?> t) {
40+
return test(config, t);
41+
}
42+
43+
@Override
44+
public String getFunctionName() {
45+
return "configure_spec";
46+
}
47+
48+
@Override
49+
public String parametersToString() {
50+
return config.get().toString(NodeWriter.logicalSymbols);
51+
}
52+
53+
@Override
54+
public String toString() {
55+
return Relevance.toString(this);
56+
}
57+
}

0 commit comments

Comments
 (0)