use of de.neemann.digital.gui.components.table.ExpressionListenerStore in project Digital by hneemann.
the class QuineMcCluskeyExamTest method testMultipleSolutions.
public void testMultipleSolutions() throws ExpressionException, FormatterException {
ExpressionListenerStore results = new ExpressionListenerStore(null);
new MinimizerQuineMcCluskeyExam().minimize(Variable.vars(4), new BoolTableByteArray(new byte[] { 2, 0, 0, 0, 1, 2, 0, 0, 1, 1, 2, 0, 1, 1, 1, 2 }), "Y", results);
assertEquals(4, results.getResults().size());
int compl = -1;
for (ExpressionListenerStore.Result r : results.getResults()) {
assertEquals("Y", r.getName());
int c = r.getExpression().traverse(new ComplexityVisitor()).getComplexity();
if (compl < 0)
compl = c;
assertEquals(compl, c);
}
}
use of de.neemann.digital.gui.components.table.ExpressionListenerStore 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.gui.components.table.ExpressionListenerStore in project Digital by hneemann.
the class QuineMcCluskeyExamTest method testMinimal.
public void testMinimal() throws ExpressionException, FormatterException {
ExpressionListenerStore results = new ExpressionListenerStore(null);
new MinimizerQuineMcCluskeyExam().minimize(Variable.vars(4), new BoolTableByteArray(new byte[] { 1, 2, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1 }), "Y", results);
assertEquals(1, results.getResults().size());
}
use of de.neemann.digital.gui.components.table.ExpressionListenerStore in project Digital by hneemann.
the class CircuitBuilderTest method testBus.
public void testBus() throws Exception {
final ToBreakRunner runner = new ToBreakRunner("dig/circuitBuilder/busTest.dig", false);
// create truth table incl. ModelAnalyzerInfo
TruthTable tt = new ModelAnalyser(runner.getModel()).analyse();
assertEquals(8, tt.getVars().size());
assertEquals(8, tt.getResultCount());
// create expressions based on truth table
ExpressionListenerStore expr = new ExpressionListenerStore(null);
new ExpressionCreator(tt).create(expr);
// build a new circuit
CircuitBuilder circuitBuilder = new CircuitBuilder(runner.getLibrary().getShapeFactory(), false, tt.getVars()).setModelAnalyzerInfo(tt.getModelAnalyzerInfo());
new BuilderExpressionCreator(circuitBuilder).create(expr);
Circuit circuit = circuitBuilder.createCircuit();
// check
List<VisualElement> in = circuit.findElements(v -> v.equalsDescription(In.DESCRIPTION));
assertEquals(2, in.size());
checkPin(in.get(0), "A", "1,2,3,4");
checkPin(in.get(1), "B", "5,6,7,8");
List<VisualElement> out = circuit.findElements(v -> v.equalsDescription(Out.DESCRIPTION));
assertEquals(2, out.size());
checkPin(out.get(0), "S", "9,10,11,12");
checkPin(out.get(1), "U", "13,14,15,16");
}
Aggregations