use of de.neemann.digital.analyse.expression.Expression 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));
}
use of de.neemann.digital.analyse.expression.Expression in project Digital by hneemann.
the class IndependentCheckerTest method testRemoveVar.
public void testRemoveVar() {
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);
BoolTable btr = ic.removeVar(3);
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.Expression in project Digital by hneemann.
the class MinimizerRegressionTest method performTestCalculation.
/**
* Generates a expression from the table and then checks if
* the expression reproduces the given table.
* Does not test if the expression is minimal.
*
* @param n the number of variables
* @param tab the truth table
* @throws ExpressionException
*/
private static void performTestCalculation(int n, byte[] tab, MinimizerInterface minimizer) throws ExpressionException, FormatterException {
ArrayList<Variable> v = vars(n);
final ExpressionListenerStore listener = new ExpressionListenerStore(null);
minimizer.minimize(v, new BoolTableByteArray(tab), "Y", listener);
Expression e = listener.getFirst();
assertNotNull(e);
ContextFiller context = new ContextFiller(v);
for (int i = 0; i < tab.length; i++) {
if (tab[i] <= 1)
assertEquals(tab[i] == 1, e.calculate(context.setContextTo(i)));
}
}
use of de.neemann.digital.analyse.expression.Expression in project Digital by hneemann.
the class SimplifyTest method testSimplify.
public void testSimplify() throws Exception, FormatterException {
Variable a = v("a");
Variable b = v("b");
Expression e = or(and(a, b), a);
Expression s = QuineMcCluskey.simplify(e);
assertEquals("a", FormatToExpression.FORMATTER_UNICODE.format(s));
}
use of de.neemann.digital.analyse.expression.Expression in project Digital by hneemann.
the class SimplifyTest method testSimplify3.
public void testSimplify3() throws Exception {
Variable a = v("a");
Variable b = v("b");
Variable c = v("c");
Expression e = and(or(a, b), c);
Expression s = QuineMcCluskey.simplify(e);
assertTrue(s == e);
}
Aggregations