Search in sources :

Example 1 with BoolTableBoolArray

use of de.neemann.digital.analyse.quinemc.BoolTableBoolArray 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());
        }
    }
}
Also used : QuineMcCluskey(de.neemann.digital.analyse.quinemc.QuineMcCluskey) PrimeSelectorDefault(de.neemann.digital.analyse.quinemc.primeselector.PrimeSelectorDefault) Expression(de.neemann.digital.analyse.expression.Expression) BoolTableBoolArray(de.neemann.digital.analyse.quinemc.BoolTableBoolArray)

Aggregations

Expression (de.neemann.digital.analyse.expression.Expression)1 BoolTableBoolArray (de.neemann.digital.analyse.quinemc.BoolTableBoolArray)1 QuineMcCluskey (de.neemann.digital.analyse.quinemc.QuineMcCluskey)1 PrimeSelectorDefault (de.neemann.digital.analyse.quinemc.primeselector.PrimeSelectorDefault)1