Search in sources :

Example 1 with TestExecuter

use of de.neemann.digital.TestExecuter in project Digital by hneemann.

the class TestAnd method testAnd2.

/**
 * Same test as above written more simple
 *
 * @throws Exception
 */
public void testAnd2() throws Exception {
    TestExecuter te = TestExecuter.createFromFile("dig/and.dig", library);
    te.check(0, 0, 0);
    te.check(0, 1, 0);
    te.check(1, 0, 0);
    te.check(1, 1, 1);
    // only a single And-Node
    assertEquals(1, te.getModel().getNodes().size());
    // every calculation needs a single micro step
    assertEquals(4, te.getModel().getStepCounter());
}
Also used : TestExecuter(de.neemann.digital.TestExecuter)

Example 2 with TestExecuter

use of de.neemann.digital.TestExecuter in project Digital by hneemann.

the class TestAnd method testAnd.

/**
 * Reads a file and sets up a model from it.
 * After that the model - a simple AND gate - is tested to be a working AND gate.
 *
 * @throws Exception
 */
public void testAnd() throws Exception {
    File filename = new File(Resources.getRoot(), "dig/and.dig");
    Circuit circuit = Circuit.loadCircuit(filename, new ShapeFactory(new ElementLibrary()));
    ModelCreator md = new ModelCreator(circuit, library);
    Model model = md.createModel(false);
    List<Node> nodes = model.getNodes();
    assertEquals(1, nodes.size());
    // get inputs and outputs
    List<ModelEntry> inputs = md.getEntries("In");
    assertEquals(2, inputs.size());
    List<ModelEntry> outputs = md.getEntries("Out");
    assertEquals(1, outputs.size());
    // check the inputs state: the input itself has an output
    assertEquals(0, inputs.get(0).getIoState().inputCount());
    assertEquals(1, inputs.get(0).getIoState().outputCount());
    assertEquals(0, inputs.get(1).getIoState().inputCount());
    assertEquals(1, inputs.get(1).getIoState().outputCount());
    // check the output state: the output itself has an input
    assertEquals(1, outputs.get(0).getIoState().inputCount());
    assertEquals(0, outputs.get(0).getIoState().outputCount());
    // setup the test executer
    TestExecuter te = new TestExecuter(model).setInputs(inputs).setOutputs(outputs);
    te.check(0, 0, 0);
    te.check(0, 1, 0);
    te.check(1, 0, 0);
    te.check(1, 1, 1);
}
Also used : ModelEntry(de.neemann.digital.draw.model.ModelEntry) ElementLibrary(de.neemann.digital.draw.library.ElementLibrary) Node(de.neemann.digital.core.Node) Model(de.neemann.digital.core.Model) ShapeFactory(de.neemann.digital.draw.shapes.ShapeFactory) Circuit(de.neemann.digital.draw.elements.Circuit) TestExecuter(de.neemann.digital.TestExecuter) File(java.io.File) ModelCreator(de.neemann.digital.draw.model.ModelCreator)

Example 3 with TestExecuter

use of de.neemann.digital.TestExecuter in project Digital by hneemann.

the class TestNesting method runTheAndTest.

/**
 * Loads a file and ensures it is a simple and gate.
 *
 * @param file the filename
 * @throws IOException
 * @throws NodeException
 * @throws PinException
 */
private void runTheAndTest(String file) throws IOException, NodeException, PinException, ElementNotFoundException {
    TestExecuter te = createTestExecuterForNesting(file);
    te.check(0, 0, 0);
    te.check(0, 1, 0);
    te.check(1, 0, 0);
    te.check(1, 1, 1);
    // only a single And-Node
    assertEquals(1, te.getModel().getNodes().size());
    // every calculation needs a single micro step
    assertEquals(4, te.getModel().getStepCounter());
}
Also used : TestExecuter(de.neemann.digital.TestExecuter)

Example 4 with TestExecuter

use of de.neemann.digital.TestExecuter in project Digital by hneemann.

the class TestNesting method testMSFF.

/**
 * Nested JK-FF. One output from nested model is not used!
 *
 * @throws Exception
 */
public void testMSFF() throws Exception {
    TestExecuter te = createTestExecuterForNesting("dig/nestedMSFF.dig");
    // C  J  K  Q
    // initial state is undefined
    te.checkZ(0, 0, 0, IGNORE);
    te.checkZ(1, 0, 1, IGNORE);
    te.check(0, 0, 0, 0);
    te.check(1, 1, 0, 0);
    te.check(0, 0, 0, 1);
    te.check(1, 1, 1, 1);
    te.check(0, 1, 1, 0);
    te.check(1, 1, 1, 0);
    te.check(0, 1, 1, 1);
}
Also used : TestExecuter(de.neemann.digital.TestExecuter)

Example 5 with TestExecuter

use of de.neemann.digital.TestExecuter in project Digital by hneemann.

the class DecoderTest method testDecoder.

public void testDecoder() throws Exception {
    Model model = new Model();
    ObservableValue sel = new ObservableValue("sel", 2);
    Decoder decoder = model.add(new Decoder(new ElementAttributes().set(Keys.SELECTOR_BITS, 2)));
    decoder.setInputs(sel.asList());
    TestExecuter te = new TestExecuter(model).setInputs(sel).setOutputs(decoder.getOutputs());
    te.check(0, 1, 0, 0, 0);
    te.check(1, 0, 1, 0, 0);
    te.check(2, 0, 0, 1, 0);
    te.check(3, 0, 0, 0, 1);
}
Also used : Model(de.neemann.digital.core.Model) ObservableValue(de.neemann.digital.core.ObservableValue) ElementAttributes(de.neemann.digital.core.element.ElementAttributes) TestExecuter(de.neemann.digital.TestExecuter)

Aggregations

TestExecuter (de.neemann.digital.TestExecuter)80 ObservableValue (de.neemann.digital.core.ObservableValue)61 ElementAttributes (de.neemann.digital.core.element.ElementAttributes)61 Model (de.neemann.digital.core.Model)49 ObservableValues (de.neemann.digital.core.ObservableValues)16 Circuit (de.neemann.digital.draw.elements.Circuit)5 ElementLibrary (de.neemann.digital.draw.library.ElementLibrary)5 ModelCreator (de.neemann.digital.draw.model.ModelCreator)5 ShapeFactory (de.neemann.digital.draw.shapes.ShapeFactory)5 Expression (de.neemann.digital.analyse.expression.Expression)4 Variable (de.neemann.digital.analyse.expression.Variable)4 Node (de.neemann.digital.core.Node)1 FanIn (de.neemann.digital.core.basic.FanIn)1 Delay (de.neemann.digital.core.wiring.Delay)1 ModelEntry (de.neemann.digital.draw.model.ModelEntry)1 File (java.io.File)1