use of de.neemann.digital.analyse.expression.Expression in project Digital by hneemann.
the class CircuitBuilderTest method testBuilderSequentialJK_JequalsK.
public void testBuilderSequentialJK_JequalsK() throws Exception {
Variable y0 = new Variable("Y_0");
Variable y1 = new Variable("Y_1");
// counter
Expression y0s = not(y0);
Expression y1s = or(and(not(y0), y1), and(y0, not(y1)));
ElementLibrary library = new ElementLibrary();
Circuit circuit = new CircuitBuilder(new ShapeFactory(library), true).addSequential("Y_0", y0s).addSequential("Y_1", y1s).createCircuit();
ModelCreator m = new ModelCreator(circuit, library);
TestExecuter te = new TestExecuter(m.createModel(false)).setUp(m);
te.check(0, 0);
te.checkC(1, 0);
te.checkC(0, 1);
te.checkC(1, 1);
te.checkC(0, 0);
}
use of de.neemann.digital.analyse.expression.Expression in project Digital by hneemann.
the class FuseMapFillerTest method testFillExpression.
public void testFillExpression() throws Exception {
FuseMap fuseMap = new FuseMap(16);
Variable a = new Variable("A");
Variable b = new Variable("B");
Variable c = new Variable("C");
Variable d = new Variable("D");
Expression e = or(and(a, b, c, d), and(not(a), not(b), not(c), not(d)));
new FuseMapFiller(fuseMap, 4).addVariable(0, a).addVariable(1, b).addVariable(2, c).addVariable(3, d).fillExpression(0, e, 2);
byte[] data = fuseMap.getFuseData();
assertEquals(0xAA, data[0] & 0xff);
assertEquals(0x55, data[1] & 0xff);
}
use of de.neemann.digital.analyse.expression.Expression in project Digital by hneemann.
the class KarnaughMapTest method testSimple2_singleVar.
public void testSimple2_singleVar() throws IOException, ParseException, KarnaughException {
Expression exp = new Parser("A").parse().get(0);
KarnaughMap c = new KarnaughMap(Variable.vars(2), exp);
assertEquals(1, c.size());
for (KarnaughMap.Cover co : c) assertEquals(2, co.getSize());
}
use of de.neemann.digital.analyse.expression.Expression in project Digital by hneemann.
the class KarnaughMapTest method testIndex.
/**
* Creates bool tables with one "one".
* Calculates the KV map.
* Tests if the covered cell belongs to the single "one" in the table!
*/
public void testIndex() throws IOException, ParseException, KarnaughException, ExpressionException {
for (int vars = 2; vars <= 4; vars++) {
int rows = 1 << vars;
for (int row = 0; row < rows; row++) {
// create bool table
BoolTableBoolArray t = new BoolTableBoolArray(rows);
// put one one to the tabel
t.set(row, true);
Expression exp = new QuineMcCluskey(Variable.vars(vars)).fillTableWith(t).simplify(new PrimeSelectorDefault()).getExpression();
// create the KV covers
KarnaughMap c = new KarnaughMap(Variable.vars(vars), exp);
// there is only on cover
assertEquals(1, c.size());
KarnaughMap.Cover cover = c.iterator().next();
// the size of the cover is one cell
assertEquals(1, cover.getSize());
KarnaughMap.Pos pos = cover.getPos();
// the row in the truth table is the row containing the one.
assertEquals(row, c.getCell(pos.getRow(), pos.getCol()).getBoolTableRow());
}
}
}
use of de.neemann.digital.analyse.expression.Expression in project Digital by hneemann.
the class KarnaughMapTest method testSimple4.
public void testSimple4() throws IOException, ParseException, KarnaughException {
Expression exp = new Parser("(¬A ¬C ¬D) ∨ (A B C) ∨ (A ¬B D) ∨ (¬A ¬B C) ∨ (¬B ¬C ¬D)").parse().get(0);
KarnaughMap c = new KarnaughMap(Variable.vars(4), exp);
assertEquals(5, c.size());
for (KarnaughMap.Cover co : c) assertEquals(2, co.getSize());
}
Aggregations