use of de.neemann.digital.analyse.expression.ContextFiller in project Digital by hneemann.
the class IndependentCheckerTest method testRemoveVar2.
public void testRemoveVar2() {
Expression ex = and(a, c, d);
ContextFiller cf = new ContextFiller(a, b, c, d);
BoolTableExpression bte = new BoolTableExpression(ex, cf);
IndependentChecker ic = new IndependentChecker(bte);
BoolTable btr = ic.removeVar(1);
assertEquals(8, btr.size());
for (int i = 0; i < 7; i++) assertEquals(ThreeStateValue.zero, btr.get(i));
assertEquals(ThreeStateValue.one, btr.get(7));
}
use of de.neemann.digital.analyse.expression.ContextFiller in project Digital by hneemann.
the class QuineMcCluskeyRegressionTest method testRegression3.
public void testRegression3() throws Exception {
Variable a = new Variable("A");
Variable b = new Variable("B");
Variable c = new Variable("C");
Variable d = new Variable("D");
ArrayList<Variable> vars = new ArrayList<>();
vars.add(a);
vars.add(b);
vars.add(c);
vars.add(d);
QuineMcCluskey t = new QuineMcCluskey(vars);
Expression ex = or(a, c);
t.fillTableWith(new BoolTableExpression(ex, new ContextFiller(vars)));
// System.out.println("--");
while (!t.isFinished()) {
// System.out.println(FormatToExpression.FORMATTER_JAVA.format(t.getExpression()));
t.simplifyStep();
}
t.simplifyPrimes(new PrimeSelectorDefault());
assertEquals("A || C", FormatToExpression.FORMATTER_JAVA.format(t.getExpression()));
// System.out.println("--");
}
use of de.neemann.digital.analyse.expression.ContextFiller in project Digital by hneemann.
the class QuineMcCluskeyRegressionTest method testRegression.
private static void testRegression(int n, int j) throws Exception {
int size = 1 << n;
boolean[] table = new boolean[size];
ArrayList<Integer> index = new ArrayList<>();
for (int i = 0; i < size; i++) index.add(i);
Collections.shuffle(index);
for (int i = 0; i < j; i++) table[index.get(i)] = true;
ArrayList<Variable> var = Variable.vars(n);
Expression expression = new QuineMcCluskey(var).fillTableWith(new BoolTableBoolArray(table)).simplify().getExpression();
ContextFiller cf = new ContextFiller(var);
for (int i = 0; i < table.length; i++) assertEquals(table[i], expression.calculate(cf.setContextTo(i)));
}
use of de.neemann.digital.analyse.expression.ContextFiller in project Digital by hneemann.
the class IndependentCheckerTest method testSimple.
public void testSimple() {
Expression ex = and(a, b, c);
ContextFiller cf = new ContextFiller(a, b, c, d);
BoolTableExpression bte = new BoolTableExpression(ex, cf);
IndependentChecker ic = new IndependentChecker(bte);
assertEquals(4, ic.getVars());
assertFalse(ic.isIndependentFrom(0));
assertFalse(ic.isIndependentFrom(1));
assertFalse(ic.isIndependentFrom(2));
assertTrue(ic.isIndependentFrom(3));
}
use of de.neemann.digital.analyse.expression.ContextFiller in project Digital by hneemann.
the class IndependentCheckerTest method testSimple2.
public void testSimple2() {
Expression ex = and(a, c, d);
ContextFiller cf = new ContextFiller(a, b, c, d);
BoolTableExpression bte = new BoolTableExpression(ex, cf);
IndependentChecker ic = new IndependentChecker(bte);
assertEquals(4, ic.getVars());
assertFalse(ic.isIndependentFrom(0));
assertTrue(ic.isIndependentFrom(1));
assertFalse(ic.isIndependentFrom(2));
assertFalse(ic.isIndependentFrom(3));
}
Aggregations