Skip to content

Commit

Permalink
chore(deps): update dependency featureide to v3.8.3 (#6)
Browse files Browse the repository at this point in the history
* chore(deps): update dependency featureide to v3.8.3

* feat: migrate to featureide v3.8.3 (#13)

* feat: new version

* test: unify tests

* feat: more migration code

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Michael Kriese <[email protected]>
  • Loading branch information
renovate[bot] and viceice authored Jun 22, 2022
1 parent c3c0eb4 commit 0284696
Show file tree
Hide file tree
Showing 11 changed files with 511 additions and 74 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"java.configuration.updateBuildConfiguration": "interactive"
"java.configuration.updateBuildConfiguration": "automatic"
}
16 changes: 10 additions & 6 deletions java/build.gradle
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
plugins {
id 'java-library'
id 'java-library'
}

repositories {
mavenCentral()
mavenCentral()
}

java {
toolchain {
languageVersion = JavaLanguageVersion.of(11)
}
toolchain {
languageVersion = JavaLanguageVersion.of(11)
}
}

version = '0.0.1'

test {
useJUnitPlatform()
useJUnitPlatform()
// testLogging {
// showStandardStreams = true
// events = ['standard_out']
// }
}

dependencies {
Expand Down
101 changes: 101 additions & 0 deletions java/src/test/java/AlternateModelTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.prop4j.Implies;
import org.prop4j.Literal;
import org.prop4j.Not;
import org.prop4j.Or;

import de.ovgu.featureide.fm.core.analysis.cnf.formula.FeatureModelFormula;
import de.ovgu.featureide.fm.core.base.IFeatureModel;
import de.ovgu.featureide.fm.core.base.IFeatureStructure;
import de.ovgu.featureide.fm.core.configuration.Configuration;
import de.ovgu.featureide.fm.core.configuration.ConfigurationAnalyzer;
import de.ovgu.featureide.fm.core.configuration.Selection;

class AlternateModelTests {

private IFeatureModel model;
private IFeatureStructure root;

@BeforeEach
void BeforeEach() {
model = Utils.CreateModel();
root = Utils.addFeature(model, "Root", true);
root.setMandatory(true);
model.getStructure().setRoot(root);
}

@Test
void simple() {
root.addChild(Utils.addFeature(model, "CORE1"));
root.addChild(Utils.addFeature(model, "CORE2"));
root.changeToAlternative();

var formula = new FeatureModelFormula(model);
var config = new Configuration(formula);
var configAnalyzer = new ConfigurationAnalyzer(formula, config);

configAnalyzer.update(true);

System.out.println(formula.getCNFNode().toString());

assertTrue(configAnalyzer.canBeValid(), "canbeValid");
assertFalse(configAnalyzer.isValid(), "isValid");
}

@Test
void canBeValid() {
root.addChild(Utils.addFeature(model, "CORE1"));
root.addChild(Utils.addFeature(model, "CORE2"));

Utils.add(model, new Or(
new Literal("CORE1"),
new Literal("CORE2")));
Utils.add(model, new Implies(
new Literal("CORE1"),
new Not(
new Literal("CORE2"))));
Utils.add(model, new Implies(
new Literal("CORE2"),
new Not(
new Literal("CORE1"))));

var formula = new FeatureModelFormula(model);
var config = new Configuration(formula);
var configAnalyzer = new ConfigurationAnalyzer(formula, config);

configAnalyzer.update(true);

System.out.println(formula.getCNFNode().toString());

assertTrue(configAnalyzer.canBeValid(), "canbeValid");
assertFalse(configAnalyzer.isValid(), "isValid");
}

@Test
void shouldBeValid() {
root.addChild(Utils.addFeature(model, "CORE"));

Utils.add(model, new Or(new Literal("CORE")));

var formula = new FeatureModelFormula(model);
var config = new Configuration(formula);
var configAnalyzer = new ConfigurationAnalyzer(formula, config);

configAnalyzer.update(true);

System.out.println(formula.getCNFNode().toString());

assertTrue(configAnalyzer.canBeValid(), "canBeValid");
assertTrue(configAnalyzer.isValid(), "isValid");

var sfCore = config.getSelectableFeature("CORE");
assertNotNull(sfCore);
assertEquals(Selection.SELECTED, sfCore.getAutomatic(), "isAutoSelected");
}
}
110 changes: 90 additions & 20 deletions java/src/test/java/Tests.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.prop4j.And;
import org.prop4j.Implies;
import org.prop4j.Literal;
import org.prop4j.Not;
import org.prop4j.Or;

import de.ovgu.featureide.fm.core.analysis.cnf.formula.FeatureModelFormula;
import de.ovgu.featureide.fm.core.base.IFeatureModel;
import de.ovgu.featureide.fm.core.base.IFeatureStructure;
import de.ovgu.featureide.fm.core.configuration.Configuration;
import de.ovgu.featureide.fm.core.configuration.ConfigurationAnalyzer;
import de.ovgu.featureide.fm.core.configuration.Selection;

class Tests {
Expand All @@ -28,16 +32,17 @@ void BeforeEach() {
model.getStructure().setRoot(root);

cores = Utils.addFeature(model, "CoreModules", true);
cores.changeToAlternative();
// change to alternate
cores.setAlternative();
cores.setMandatory(true);
root.addChild(cores);

mods = Utils.addFeature(model, "Modules", true);
mods.changeToOr();
mods.setOr();
root.addChild(mods);

devs = Utils.addFeature(model, "Devices", true);
devs.changeToOr();
mods.setOr();
root.addChild(devs);
}

Expand All @@ -46,33 +51,82 @@ void canBeValid() {
cores.addChild(Utils.addFeature(model, "CORE1"));
cores.addChild(Utils.addFeature(model, "CORE2"));

var config = new Configuration(model, false);
config.setPropagate(true);
config.update(true, null);
var formula = new FeatureModelFormula(model);
var config = new Configuration(formula);
var configAnalyzer = new ConfigurationAnalyzer(formula, config);

assertTrue(config.canBeValid(), "canbeValid");
assertFalse(config.isValid(), "isValid");
configAnalyzer.update(true);

System.out.println(formula.getCNFNode().toString());

assertTrue(configAnalyzer.canBeValid(), "canbeValid");
assertFalse(configAnalyzer.isValid(), "isValid");
}

@Test
void shouldBeValid() {
cores.addChild(Utils.addFeature(model, "CORE"));

var config = new Configuration(model, false);
config.setPropagate(true);
config.update(true, null);
var formula = new FeatureModelFormula(model);
var config = new Configuration(formula);
var configAnalyzer = new ConfigurationAnalyzer(formula, config);

configAnalyzer.update(true);

assertTrue(config.canBeValid(), "canBeValid");
assertTrue(config.isValid(), "isValid");
System.out.println(formula.getCNFNode().toString());

var sfCore = config.getSelectablefeature("CORE");
assertTrue(configAnalyzer.canBeValid(), "canBeValid");
assertTrue(configAnalyzer.isValid(), "isValid");

var sfCore = config.getSelectableFeature("CORE");
assertNotNull(sfCore);
assertEquals(Selection.SELECTED, sfCore.getAutomatic(), "isAutoSelected");
}

@Test
void complex() {
cores.addChild(Utils.addFeature(model, "CORE"));
cores.getFirstChild().setMandatory(true);

mods.addChild(Utils.addFeature(model, "M1"));
mods.addChild(Utils.addFeature(model, "M2"));
mods.addChild(Utils.addFeature(model, "M3"));
mods.addChild(Utils.addFeature(model, "M4"));

devs.addChild(Utils.addFeature(model, "D1"));
devs.addChild(Utils.addFeature(model, "D2"));
devs.addChild(Utils.addFeature(model, "D3"));
devs.addChild(Utils.addFeature(model, "D4"));

Utils.add(model, new Implies(
new Literal("M2"),
new Not(
new Literal("M3"))));

Utils.add(model, new Implies(
new Literal("D1"),
new Not(
new Literal("M3"))));

var formula = new FeatureModelFormula(model);
var config = new Configuration(formula);
var configAnalyzer = new ConfigurationAnalyzer(formula, config);

configAnalyzer.update(true);

System.out.println(formula.getCNFNode().toString());

assertTrue(configAnalyzer.canBeValid(), "canBeValid");
assertTrue(configAnalyzer.isValid(), "isValid");

var sfCore = config.getSelectableFeature("CORE");
assertNotNull(sfCore);
assertEquals(Selection.SELECTED, sfCore.getAutomatic(), "isAutoSelected");
}

@Test
void complex2() {
cores.addChild(Utils.addFeature(model, "CORE"));

mods.addChild(Utils.addFeature(model, "M1"));
mods.addChild(Utils.addFeature(model, "M2"));
Expand All @@ -84,6 +138,14 @@ void complex() {
devs.addChild(Utils.addFeature(model, "D3"));
devs.addChild(Utils.addFeature(model, "D4"));

Utils.add(model, new Implies(
new Literal("CORE"),
new Or(
new And(new Literal("M4"), new Literal("M2")),
new And(new Literal("M4"), new Literal("M3"))
)
));

Utils.add(model, new Implies(
new Literal("M2"),
new Not(
Expand All @@ -94,16 +156,24 @@ void complex() {
new Not(
new Literal("M3"))));

var config = new Configuration(model, false);
config.setPropagate(true);
config.update(true, null);
var formula = new FeatureModelFormula(model);
var config = new Configuration(formula);
var configAnalyzer = new ConfigurationAnalyzer(formula, config);

configAnalyzer.update(true);

assertTrue(config.canBeValid(), "canBeValid");
assertTrue(config.isValid(), "isValid");
System.out.println(formula.getCNFNode().toString());

var sfCore = config.getSelectablefeature("CORE");
assertTrue(configAnalyzer.canBeValid(), "canBeValid");
assertFalse(configAnalyzer.isValid(), "isValid");

var sfCore = config.getSelectableFeature("CORE");
assertNotNull(sfCore);
assertEquals(Selection.SELECTED, sfCore.getAutomatic(), "isAutoSelected");

var sfM4 = config.getSelectableFeature("M4");
assertNotNull(sfM4);
assertEquals(Selection.SELECTED, sfM4.getAutomatic(), "isAutoSelected");
}

}
8 changes: 7 additions & 1 deletion java/src/test/java/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@
import de.ovgu.featureide.fm.core.base.IConstraint;
import de.ovgu.featureide.fm.core.base.IFeatureModel;
import de.ovgu.featureide.fm.core.base.IFeatureStructure;
import de.ovgu.featureide.fm.core.base.impl.ConfigurationFactoryManager;
import de.ovgu.featureide.fm.core.base.impl.DefaultConfigurationFactory;
import de.ovgu.featureide.fm.core.base.impl.DefaultFeatureModelFactory;

public class Utils {

private static DefaultFeatureModelFactory FACTORY = new DefaultFeatureModelFactory();

static {
ConfigurationFactoryManager.getInstance().addExtension(DefaultConfigurationFactory.getInstance());
}

public static IFeatureModel CreateModel() {
return FACTORY.createFeatureModel();
return FACTORY.create();
}

public static IFeatureStructure addFeature(IFeatureModel self, String feature) {
Expand Down
22 changes: 15 additions & 7 deletions test/de.ovgu.featureide.fm.test/Prop4jTests.cs
Original file line number Diff line number Diff line change
@@ -1,36 +1,44 @@
using org.prop4j;
using org.prop4j.explain.solvers;

namespace de.ovgu.featureide.fm.test
{
internal class Prop4jTests
{
private readonly long Timeout = (long)TimeSpan.FromSeconds(5).TotalMilliseconds;
private org.prop4j.explain.solvers.SatSolver solver;

[SetUp]
public void Setup()
{
solver = SatSolverFactory.getDefault().getSatSolver();
}

[Test]
public void Simple()
{
var formula = new And();

var solver = new SatSolver(formula, Timeout);


Expect(solver.isSatisfiable()).To.Be.True();

solver.addFormula(formula);

Expect(solver.isSatisfiable()).To.Be.True();
}

[Test]
public void CanBeValid()
{
var formula = new And(
new Implies(new Literal("CORE1"), new Not(new Literal("CORE2"))),
new Implies(new Literal("CORE2"), new Not(new Literal("CORE1")))
);
var solver = new SatSolver(formula, Timeout);
solver.addFormula(new Implies(new Literal("CORE1"), new Not(new Literal("CORE2"))));
solver.addFormula(new Implies(new Literal("CORE2"), new Not(new Literal("CORE1"))));

Expect(solver.isSatisfiable()).To.Be.True();


var map = solver.getAssumptions();
var m = solver.getModel();
Console.WriteLine("assumptions: " + map.keySet().Cast<string>().ToArray());
}
}
}
Loading

0 comments on commit 0284696

Please sign in to comment.