use of de.neemann.digital.analyse.expression.ContextFiller in project Digital by hneemann.
the class TruthTableFormatterLaTeX method format.
@Override
public String format(TruthTable truthTable) throws ExpressionException {
StringBuilder sb = new StringBuilder();
sb.append("\\begin{center}\n\\begin{tabular}{");
for (Variable v : truthTable.getVars()) sb.append("c");
sb.append("|");
for (int i = 0; i < truthTable.getResultCount(); i++) sb.append("c");
sb.append("}\n");
for (Variable v : truthTable.getVars()) sb.append("$").append(formatVar(v.getIdentifier())).append("$&");
for (int i = 0; i < truthTable.getResultCount(); i++) {
sb.append("$").append(formatVar(truthTable.getResultName(i))).append("$");
if (i < truthTable.getResultCount() - 1)
sb.append("&");
}
sb.append("\\\\\n");
sb.append("\\hline\n");
ContextFiller cf = new ContextFiller(truthTable.getVars());
for (int i = 0; i < cf.getRowCount(); i++) {
cf.setContextTo(i);
for (Variable v : cf) sb.append(format(cf.get(v))).append("&");
for (int j = 0; j < truthTable.getResultCount(); j++) {
ThreeStateValue r = truthTable.getResult(j).get(i);
sb.append(format(r));
if (j < truthTable.getResultCount() - 1)
sb.append("&");
}
sb.append("\\\\\n");
}
sb.append("\\end{tabular}\n\\end{center}\n");
return sb.toString();
}
use of de.neemann.digital.analyse.expression.ContextFiller in project Digital by hneemann.
the class TestReorderInputs method testDeleteVar.
public void testDeleteVar() throws Exception {
TruthTable t = new TruthTable(3).addResult();
BoolTableByteArray col = (BoolTableByteArray) t.getResult(0);
for (int i = 0; i < t.getRows(); i++) col.set(i, i + 1);
ReorderInputs reorderInputs = new ReorderInputs(t);
reorderInputs.getItems().delete(2);
TruthTable newTable = reorderInputs.reorder();
assertEquals(2, newTable.getVars().size());
assertEquals(1, newTable.getResultCount());
ContextFiller cf = new ContextFiller(newTable.getVars());
cf.set(t.getVars().get(2), false);
for (int i = 0; i < newTable.getRows(); i++) {
cf.setContextTo(i);
assertEquals(newTable.getByContext(0, cf), t.getByContext(0, cf));
}
}
use of de.neemann.digital.analyse.expression.ContextFiller in project Digital by hneemann.
the class TestReorderInputs method testReorder.
public void testReorder() throws Exception {
TruthTable t = new TruthTable(5).addResult();
BoolTableByteArray col = (BoolTableByteArray) t.getResult(0);
for (int i = 0; i < t.getRows(); i++) col.set(i, i + 1);
ReorderInputs reorderInputs = new ReorderInputs(t);
reorderInputs.getItems().swap(1, 2);
TruthTable newTable = reorderInputs.reorder();
ContextFiller cf = new ContextFiller(t.getVars());
for (int i = 0; i < t.getRows(); i++) {
cf.setContextTo(i);
assertEquals(newTable.getByContext(0, cf), t.getByContext(0, cf));
}
}
use of de.neemann.digital.analyse.expression.ContextFiller in project Digital by hneemann.
the class TableReducerTest method testReduce2.
public void testReduce2() {
List<Variable> vars = new ArrayList<>();
vars.add(a);
vars.add(b);
vars.add(c);
vars.add(d);
Expression ex = and(a, c, d);
ContextFiller cf = new ContextFiller(vars);
BoolTableExpression bte = new BoolTableExpression(ex, cf);
TableReducer tr = new TableReducer(vars, bte);
assertTrue(tr.canReduce());
vars = tr.getVars();
assertEquals(3, vars.size());
assertEquals(a, vars.get(0));
assertEquals(c, vars.get(1));
assertEquals(d, vars.get(2));
}
use of de.neemann.digital.analyse.expression.ContextFiller in project Digital by hneemann.
the class TableReducerTest method testReduce.
public void testReduce() {
List<Variable> vars = new ArrayList<>();
vars.add(a);
vars.add(b);
vars.add(c);
vars.add(d);
Expression ex = and(a, b, c);
ContextFiller cf = new ContextFiller(vars);
BoolTableExpression bte = new BoolTableExpression(ex, cf);
TableReducer tr = new TableReducer(vars, bte);
assertTrue(tr.canReduce());
vars = tr.getVars();
assertEquals(3, vars.size());
assertEquals(a, vars.get(0));
assertEquals(b, vars.get(1));
assertEquals(c, vars.get(2));
}
Aggregations