-
Notifications
You must be signed in to change notification settings - Fork 0
/
WipeOutRFMTest.java
135 lines (106 loc) · 5.7 KB
/
WipeOutRFMTest.java
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
* WipeOutR: Automated Redundancy Detection for Feature Models
*
* Copyright (c) 2022-2022 AIG team, Institute for Software Technology,
* Graz University of Technology, Austria
*
* Contact: http://ase.ist.tugraz.at/ASE/
*/
package at.tugraz.ist.ase.wipeoutr.algorithm;
import at.tugraz.ist.ase.cacdr.checker.ChocoConsistencyChecker;
import at.tugraz.ist.ase.fm.core.FeatureModel;
import at.tugraz.ist.ase.fm.core.FeatureModelException;
import at.tugraz.ist.ase.fm.core.RelationshipType;
import at.tugraz.ist.ase.kb.core.Constraint;
import at.tugraz.ist.ase.wipeoutr.model.WipeOutRFMModel;
import at.tugraz.ist.ase.wipeoutr.testmodel.WipeOutR_FM_Model1;
import at.tugraz.ist.ase.wipeoutr.testmodel.WipeOutR_FM_Model2;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import static at.tugraz.ist.ase.common.ConstraintUtils.convertToString;
import static at.tugraz.ist.ase.eval.PerformanceEvaluator.reset;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author Viet-Man Le (vietman.le@ist.tugraz.at)
* Migrated to CA-CDR-V2
*/
class WipeOutRFMTest {
@Test
void test1() throws IOException {
WipeOutR_FM_Model1 testCaseModel = new WipeOutR_FM_Model1();
testCaseModel.initialize();
System.out.println("=========================================");
System.out.println("Constraints translated from the text file:");
System.out.println(convertToString(testCaseModel.getPossiblyFaultyConstraints()));
System.out.println("=========================================");
ChocoConsistencyChecker checker = new ChocoConsistencyChecker(testCaseModel);
List<Constraint> CF = new LinkedList<>(testCaseModel.getPossiblyFaultyConstraints());
WipeOutR_FM wipeOut = new WipeOutR_FM(checker);
reset();
List<Constraint> newCF = wipeOut.run(CF);
assertEquals(newCF, testCaseModel.getNonRedundantConstraints());
System.out.println("Result constraints:");
newCF.forEach(System.out::println);
}
@Test
void test2() throws IOException {
WipeOutR_FM_Model2 testCaseModel = new WipeOutR_FM_Model2();
testCaseModel.initialize();
System.out.println("=========================================");
System.out.println("Constraints translated from the text file:");
System.out.println(convertToString(testCaseModel.getPossiblyFaultyConstraints()));
System.out.println("=========================================");
ChocoConsistencyChecker checker = new ChocoConsistencyChecker(testCaseModel);
List<Constraint> CF = new LinkedList<>(testCaseModel.getPossiblyFaultyConstraints());
WipeOutR_FM wipeOut = new WipeOutR_FM(checker);
reset();
List<Constraint> newCF = wipeOut.run(CF);
assertEquals(newCF, testCaseModel.getNonRedundantConstraints());
System.out.println("Result constraints:");
newCF.forEach(System.out::println);
}
@Test
void test3() throws FeatureModelException {
FeatureModel fm = new FeatureModel();
fm.addFeature("survey", "survey");
fm.addFeature("pay", "pay");
fm.addFeature("ABtesting", "ABtesting");
fm.addFeature("statistics", "statistics");
fm.addFeature("qa", "qa");
fm.addFeature("license", "license");
fm.addFeature("nonlicense", "nonlicense");
fm.addFeature("multiplechoice", "multiplechoice");
fm.addFeature("singlechoice", "singlechoice");
fm.addRelationship(RelationshipType.MANDATORY, fm.getFeature("survey"), Collections.singletonList(fm.getFeature("pay")));
fm.addRelationship(RelationshipType.OPTIONAL, fm.getFeature("ABtesting"), Collections.singletonList(fm.getFeature("survey")));
fm.addRelationship(RelationshipType.MANDATORY, fm.getFeature("survey"), Collections.singletonList(fm.getFeature("statistics")));
fm.addRelationship(RelationshipType.MANDATORY, fm.getFeature("survey"), Collections.singletonList(fm.getFeature("qa")));
fm.addRelationship(RelationshipType.ALTERNATIVE, fm.getFeature("pay"), List.of(fm.getFeature("license"), fm.getFeature("nonlicense")));
fm.addRelationship(RelationshipType.OR, fm.getFeature("qa"), List.of(fm.getFeature("multiplechoice"), fm.getFeature("singlechoice")));
fm.addConstraint(RelationshipType.REQUIRES, fm.getFeature("ABtesting"), Collections.singletonList(fm.getFeature("statistics")));
fm.addConstraint(RelationshipType.EXCLUDES, fm.getFeature("ABtesting"), Collections.singletonList(fm.getFeature("nonlicense")));
WipeOutRFMModel testCaseModel = new WipeOutRFMModel(fm);
testCaseModel.initialize();
System.out.println("=========================================");
System.out.println("Constraints translated from the text file:");
System.out.println(convertToString(testCaseModel.getPossiblyFaultyConstraints()));
// for (Constraint c : testCaseModel.getPossiblyFaultyConstraints()) {
// System.out.println(c);
// c.getChocoConstraints().forEach(System.out::println);
// }
System.out.println("=========================================");
ChocoConsistencyChecker checker = new ChocoConsistencyChecker(testCaseModel);
List<Constraint> CF = new LinkedList<>(testCaseModel.getPossiblyFaultyConstraints());
WipeOutR_FM wipeOut = new WipeOutR_FM(checker);
reset();
List<Constraint> newCF = wipeOut.run(CF);
// test
CF.remove(1); // remove the constraint "ABtesting -> statistics"
assertEquals(newCF, CF);
System.out.println("Result constraints:");
newCF.forEach(System.out::println);
}
}