Search in sources :

Example 1 with ValueTable

use of de.neemann.digital.data.ValueTable in project Digital by hneemann.

the class TestResultTest method testResultError.

public void testResultError() throws Exception {
    Model model = getModel("A+B");
    TestCaseDescription data = new TestCaseDescription("A B Y\n" + "0 0 0\n" + "0 1 1\n" + "1 0 1\n" + "1 1 0\n");
    TestExecutor te = new TestExecutor(data).create(model);
    ValueTable tr = te.getResult();
    assertEquals(4, tr.getRows());
    assertFalse(te.allPassed());
    assertEquals(true, ((MatchedValue) tr.getValue(0, 2)).isPassed());
    assertEquals(true, ((MatchedValue) tr.getValue(1, 2)).isPassed());
    assertEquals(true, ((MatchedValue) tr.getValue(2, 2)).isPassed());
    assertEquals(false, ((MatchedValue) tr.getValue(3, 2)).isPassed());
}
Also used : ValueTable(de.neemann.digital.data.ValueTable) Model(de.neemann.digital.core.Model)

Example 2 with ValueTable

use of de.neemann.digital.data.ValueTable in project Digital by hneemann.

the class TestResultTest method testResultDontCare2.

public void testResultDontCare2() throws Exception {
    Model model = getModel("A+B");
    TestCaseDescription data = new TestCaseDescription("A B Y\n" + "0 0 x\n" + "0 1 1\n" + "1 0 1\n" + "1 1 1\n");
    TestExecutor te = new TestExecutor(data).create(model);
    ValueTable tr = te.getResult();
    assertEquals(4, tr.getRows());
    assertTrue(te.allPassed());
}
Also used : ValueTable(de.neemann.digital.data.ValueTable) Model(de.neemann.digital.core.Model)

Example 3 with ValueTable

use of de.neemann.digital.data.ValueTable in project Digital by hneemann.

the class TestResultTest method testResultDontCare.

public void testResultDontCare() throws Exception {
    Model model = getModel("A+B");
    TestCaseDescription data = new TestCaseDescription("A B Y\n" + "0 0 0\n" + "0 1 1\n" + "1 0 1\n" + "1 1 x\n");
    TestExecutor te = new TestExecutor(data).create(model);
    ValueTable tr = te.getResult();
    assertEquals(4, tr.getRows());
    assertTrue(te.allPassed());
}
Also used : ValueTable(de.neemann.digital.data.ValueTable) Model(de.neemann.digital.core.Model)

Example 4 with ValueTable

use of de.neemann.digital.data.ValueTable in project Digital by hneemann.

the class TestCaseDescription method testData.

/**
 * Runs a 4 bit counter build from JK flip flops 16 ticks.
 * The 4 output signals are recoded in a DataSet.
 *
 * @throws Exception
 */
public void testData() throws Exception {
    ToBreakRunner toBreakRunner = new ToBreakRunner("dig/data.dig").runToBreak(29);
    // check recorded data
    ValueTable dataSet = toBreakRunner.getModel().getObserver(ValueTableObserver.class).getLogData();
    assertEquals(29, dataSet.getRows());
    int i = 0;
    for (Value[] ds : dataSet) {
        // clock
        assertEquals((~i) & 1, ds[0].getValue());
        int s = i / 2 + 1;
        // q_0
        assertEquals(s & 1, ds[1].getValue());
        // q_1
        assertEquals((s >> 1) & 1, ds[2].getValue());
        // q_2
        assertEquals((s >> 2) & 1, ds[3].getValue());
        // q_3
        assertEquals((s >> 3) & 1, ds[4].getValue());
        i++;
    }
    // try to write data to graphics instance
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    new Export(toBreakRunner.getCircuit(), (out) -> new GraphicsImage(out, "PNG", 1)).export(baos);
    assertTrue(baos.size() > 15000);
    // export data to CSV
    StringWriter w = new StringWriter();
    dataSet.saveCSV(new BufferedWriter(w));
    assertEquals("\"step\",\"C\",\"q_0n\",\"q_1n\",\"q_2n\",\"q_3n\"\n" + "\"0\",\"1\",\"1\",\"0\",\"0\",\"0\"\n" + "\"1\",\"0\",\"1\",\"0\",\"0\",\"0\"\n" + "\"2\",\"1\",\"0\",\"1\",\"0\",\"0\"\n" + "\"3\",\"0\",\"0\",\"1\",\"0\",\"0\"\n" + "\"4\",\"1\",\"1\",\"1\",\"0\",\"0\"\n" + "\"5\",\"0\",\"1\",\"1\",\"0\",\"0\"\n" + "\"6\",\"1\",\"0\",\"0\",\"1\",\"0\"\n" + "\"7\",\"0\",\"0\",\"0\",\"1\",\"0\"\n" + "\"8\",\"1\",\"1\",\"0\",\"1\",\"0\"\n" + "\"9\",\"0\",\"1\",\"0\",\"1\",\"0\"\n" + "\"10\",\"1\",\"0\",\"1\",\"1\",\"0\"\n" + "\"11\",\"0\",\"0\",\"1\",\"1\",\"0\"\n" + "\"12\",\"1\",\"1\",\"1\",\"1\",\"0\"\n" + "\"13\",\"0\",\"1\",\"1\",\"1\",\"0\"\n" + "\"14\",\"1\",\"0\",\"0\",\"0\",\"1\"\n" + "\"15\",\"0\",\"0\",\"0\",\"0\",\"1\"\n" + "\"16\",\"1\",\"1\",\"0\",\"0\",\"1\"\n" + "\"17\",\"0\",\"1\",\"0\",\"0\",\"1\"\n" + "\"18\",\"1\",\"0\",\"1\",\"0\",\"1\"\n" + "\"19\",\"0\",\"0\",\"1\",\"0\",\"1\"\n" + "\"20\",\"1\",\"1\",\"1\",\"0\",\"1\"\n" + "\"21\",\"0\",\"1\",\"1\",\"0\",\"1\"\n" + "\"22\",\"1\",\"0\",\"0\",\"1\",\"1\"\n" + "\"23\",\"0\",\"0\",\"0\",\"1\",\"1\"\n" + "\"24\",\"1\",\"1\",\"0\",\"1\",\"1\"\n" + "\"25\",\"0\",\"1\",\"0\",\"1\",\"1\"\n" + "\"26\",\"1\",\"0\",\"1\",\"1\",\"1\"\n" + "\"27\",\"0\",\"0\",\"1\",\"1\",\"1\"\n" + "\"28\",\"1\",\"1\",\"1\",\"1\",\"1\"\n", w.toString());
}
Also used : Value(de.neemann.digital.data.Value) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedWriter(java.io.BufferedWriter) StringWriter(java.io.StringWriter) GraphicsImage(de.neemann.digital.draw.graphics.GraphicsImage) TestCase(junit.framework.TestCase) Export(de.neemann.digital.draw.graphics.Export) ValueTable(de.neemann.digital.data.ValueTable) ValueTableObserver(de.neemann.digital.gui.components.data.ValueTableObserver) GraphicsImage(de.neemann.digital.draw.graphics.GraphicsImage) StringWriter(java.io.StringWriter) ValueTable(de.neemann.digital.data.ValueTable) Value(de.neemann.digital.data.Value) Export(de.neemann.digital.draw.graphics.Export) ValueTableObserver(de.neemann.digital.gui.components.data.ValueTableObserver) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedWriter(java.io.BufferedWriter)

Example 5 with ValueTable

use of de.neemann.digital.data.ValueTable in project Digital by hneemann.

the class TestResultTest method testResultDontCareInput2.

public void testResultDontCareInput2() throws Exception {
    Model model = getModel("A*0+B*0+C");
    TestCaseDescription data = new TestCaseDescription("A B C Y\n" + "x x 0 0\n" + "x x 1 1\n");
    TestExecutor te = new TestExecutor(data).create(model);
    ValueTable tr = te.getResult();
    assertEquals(8, tr.getRows());
    assertTrue(te.allPassed());
}
Also used : ValueTable(de.neemann.digital.data.ValueTable) Model(de.neemann.digital.core.Model)

Aggregations

ValueTable (de.neemann.digital.data.ValueTable)6 Model (de.neemann.digital.core.Model)5 Value (de.neemann.digital.data.Value)1 Export (de.neemann.digital.draw.graphics.Export)1 GraphicsImage (de.neemann.digital.draw.graphics.GraphicsImage)1 ValueTableObserver (de.neemann.digital.gui.components.data.ValueTableObserver)1 BufferedWriter (java.io.BufferedWriter)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 StringWriter (java.io.StringWriter)1 TestCase (junit.framework.TestCase)1