use of de.neemann.digital.analyse.quinemc.BoolTableByteArray 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.quinemc.BoolTableByteArray 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.quinemc.BoolTableByteArray in project Digital by hneemann.
the class TestReorderOutputs method testDeleteResult.
public void testDeleteResult() throws Exception {
TruthTable t = new TruthTable(3).addResult().addResult();
BoolTableByteArray col = (BoolTableByteArray) t.getResult(0);
for (int i = 0; i < t.getRows(); i++) col.set(i, i + 1);
ReorderOutputs reorderOutputs = new ReorderOutputs(t);
reorderOutputs.getItems().delete(1);
TruthTable newTable = reorderOutputs.reorder();
assertEquals(3, newTable.getVars().size());
assertEquals(1, newTable.getResultCount());
}
use of de.neemann.digital.analyse.quinemc.BoolTableByteArray in project Digital by hneemann.
the class ModelAnalyser method simpleFiller.
private void simpleFiller(TruthTable tt) throws NodeException, AnalyseException {
if (inputs.size() > MAX_INPUTS_ALLOWED)
throw new AnalyseException(Lang.get("err_toManyInputs_max_N0_is_N1", MAX_INPUTS_ALLOWED, inputs.size()));
BitSetter bitsetter = new BitSetter(inputs.size()) {
@Override
public void setBit(int row, int bit, boolean value) {
inputs.get(bit).getValue().setBool(value);
}
};
int rows = 1 << inputs.size();
ArrayList<BoolTableByteArray> data = new ArrayList<>();
for (Signal s : outputs) {
BoolTableByteArray e = new BoolTableByteArray(rows);
data.add(e);
tt.addResult(s.getName(), e);
}
model.init();
for (int row = 0; row < rows; row++) {
bitsetter.fill(row);
model.doStep();
for (int i = 0; i < outputs.size(); i++) {
data.get(i).set(row, outputs.get(i).getValue().getBool());
}
}
}
use of de.neemann.digital.analyse.quinemc.BoolTableByteArray in project Digital by hneemann.
the class BoolTableExpandedTest method testCombined.
public void testCombined() {
ArrayList<Signal> in1 = new Signals("b", "c").list();
ArrayList<Signal> in2 = new Signals("a", "b", "c", "d").list();
List<Variable> vars = new Vars("a", "b", "c", "d").list();
BoolTableExpanded bt = new BoolTableExpanded(new BoolTableByteArray(new byte[] { 1, 1, 0, 0 }), in1, in2);
TableReducer tr = new TableReducer(vars, bt);
assertTrue(tr.canReduce());
List<Variable> v = tr.getVars();
assertEquals(1, v.size());
assertEquals("b", v.get(0).getIdentifier());
BoolTable t1 = tr.getTable();
assertEquals(ThreeStateValue.one, t1.get(0));
assertEquals(ThreeStateValue.zero, t1.get(1));
}
Aggregations