use of de.neemann.digital.analyse.expression.Variable in project Digital by hneemann.
the class FormatToExpressionTest method testFormatNamesExp.
public void testFormatNamesExp() throws Exception {
Variable a = v("A");
Variable b = v("B");
Expression e = and(a, b);
NamedExpression n = new NamedExpression("U", e);
assertEquals("U = A ∧ B", FormatToExpression.FORMATTER_UNICODE.format(n));
n = new NamedExpression("V", n);
assertEquals("V = U = A ∧ B", FormatToExpression.FORMATTER_UNICODE.format(n));
}
use of de.neemann.digital.analyse.expression.Variable in project Digital by hneemann.
the class FormatToExpressionTest method testFormatExpLaTeX.
public void testFormatExpLaTeX() throws Exception {
Variable a = new Variable("A_n");
Variable b = new Variable("B_n");
Expression e = new NamedExpression("Y_n+1", and(a, not(b)));
assertEquals("Y_{n+1} = A_{n} \\und \\nicht{B_{n}}", FormatToExpression.FORMATTER_LATEX.format(e));
}
use of de.neemann.digital.analyse.expression.Variable 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.Variable in project Digital by hneemann.
the class TruthTableTest method testGetByContext.
public void testGetByContext() throws Exception {
ArrayList<Variable> vars = Variable.vars(5);
TruthTable t = new TruthTable(vars).addResult();
BoolTableByteArray result = (BoolTableByteArray) t.getResult(0);
for (int i = 0; i < t.getRows(); i++) {
result.set(i, i % 3);
}
ContextFiller fc = new ContextFiller(vars);
for (int i = 0; i < t.getRows(); i++) {
fc.setContextTo(i);
assertEquals(i % 3, t.getByContext(0, fc));
}
}
use of de.neemann.digital.analyse.expression.Variable in project Digital by hneemann.
the class TruthTableTest method testHexExportTwo.
public void testHexExportTwo() throws Exception {
ArrayList<Variable> vars = Variable.vars(3);
TruthTable t = new TruthTable(vars).addResult();
BoolTableByteArray result = (BoolTableByteArray) t.getResult(0);
for (int i = 0; i < t.getRows(); i++) {
result.set(i, i % 2);
}
t.addResult();
result = (BoolTableByteArray) t.getResult(1);
for (int i = 0; i < t.getRows(); i++) {
result.set(i, (i + 1) % 2);
}
StringWriter w = new StringWriter();
t.saveHex(w);
w.close();
assertEquals("v2.0 raw\n" + "2\n" + "1\n" + "2\n" + "1\n" + "2\n" + "1\n" + "2\n" + "1\n", w.toString());
}
Aggregations