Search in sources :

Example 11 with TestExecuter

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

the class FlipflopRSAsyncTest method testFlipFlop.

public void testFlipFlop() throws Exception {
    ObservableValue s = new ObservableValue("s", 1);
    ObservableValue r = new ObservableValue("r", 1);
    Model model = new Model();
    FlipflopRSAsync out = model.add(new FlipflopRSAsync(new ElementAttributes()));
    out.setInputs(ovs(s, r));
    TestExecuter sc = new TestExecuter(model).setInputs(s, r).setOutputs(out.getOutputs());
    // S  R  Q  ~Q
    sc.check(0, 0, 0, 1);
    sc.check(1, 0, 1, 0);
    sc.check(0, 0, 1, 0);
    sc.check(0, 1, 0, 1);
    sc.check(0, 0, 0, 1);
    sc.check(1, 1, 1, 1);
    sc.check(1, 0, 1, 0);
    sc.check(1, 1, 1, 1);
    sc.check(0, 1, 0, 1);
    ObservableValue q = out.getOutputs().get(0);
    ObservableValue qn = out.getOutputs().get(1);
    for (int i = 0; i < 100; i++) {
        s.setValue(1);
        r.setValue(1);
        model.doStep();
        assertTrue(q.getBool());
        assertTrue(qn.getBool());
        s.setValue(0);
        r.setValue(0);
        model.doStep();
        assertTrue(q.getBool() ^ qn.getBool());
    }
}
Also used : ObservableValue(de.neemann.digital.core.ObservableValue) Model(de.neemann.digital.core.Model) ElementAttributes(de.neemann.digital.core.element.ElementAttributes) TestExecuter(de.neemann.digital.TestExecuter)

Example 12 with TestExecuter

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

the class FlipflopRSTest method testFlipFlop.

public void testFlipFlop() throws Exception {
    ObservableValue s = new ObservableValue("s", 1);
    ObservableValue c = new ObservableValue("c", 1);
    ObservableValue r = new ObservableValue("r", 1);
    Model model = new Model();
    FlipflopRS out = model.add(new FlipflopRS(new ElementAttributes()));
    out.setInputs(ovs(s, c, r));
    TestExecuter sc = new TestExecuter(model).setInputs(s, c, r).setOutputs(out.getOutputs());
    // S  C  R  Q  ~Q
    sc.check(0, 0, 0, 0, 1);
    sc.check(1, 0, 0, 0, 1);
    sc.check(0, 1, 0, 0, 1);
    sc.check(1, 0, 0, 0, 1);
    sc.check(1, 1, 0, 1, 0);
    sc.check(1, 0, 0, 1, 0);
    sc.check(0, 1, 1, 0, 1);
    sc.check(0, 0, 1, 0, 1);
    ObservableValue q = out.getOutputs().get(0);
    ObservableValue qn = out.getOutputs().get(1);
    s.setValue(1);
    r.setValue(1);
    for (int i = 0; i < 100; i++) {
        c.setValue(1);
        model.doStep();
        final boolean qBool = q.getBool();
        final boolean qnBool = qn.getBool();
        assertTrue(qBool ^ qnBool);
        c.setValue(0);
        model.doStep();
        assertEquals(qBool, q.getBool());
        assertEquals(qnBool, qn.getBool());
    }
}
Also used : ObservableValue(de.neemann.digital.core.ObservableValue) Model(de.neemann.digital.core.Model) ElementAttributes(de.neemann.digital.core.element.ElementAttributes) TestExecuter(de.neemann.digital.TestExecuter)

Example 13 with TestExecuter

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

the class NAndTest method testAnd.

public void testAnd() throws Exception {
    ObservableValue a = new ObservableValue("a", 1);
    ObservableValue b = new ObservableValue("b", 1);
    Model model = new Model();
    FanIn out = model.add(new NAnd(new ElementAttributes().setBits(1)));
    out.setInputs(ovs(a, b));
    TestExecuter sc = new TestExecuter(model).setInputs(a, b).setOutputs(out.getOutputs());
    sc.check(0, 0, 1);
    sc.check(1, 0, 1);
    sc.check(0, 1, 1);
    sc.check(1, 1, 0);
    sc.check(1, 0, 1);
    sc.check(0, 1, 1);
}
Also used : ObservableValue(de.neemann.digital.core.ObservableValue) Model(de.neemann.digital.core.Model) ElementAttributes(de.neemann.digital.core.element.ElementAttributes) TestExecuter(de.neemann.digital.TestExecuter)

Example 14 with TestExecuter

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

the class NOrTest method testNOr.

public void testNOr() throws Exception {
    ObservableValue a = new ObservableValue("a", 1);
    ObservableValue b = new ObservableValue("b", 1);
    Model model = new Model();
    NOr nor = model.add(new NOr(new ElementAttributes().setBits(1)));
    nor.setInputs(ovs(a, b));
    TestExecuter sc = new TestExecuter(model).setInputs(a, b).setOutputs(nor.getOutputs());
    sc.check(0, 0, 1);
    sc.check(1, 0, 0);
    sc.check(0, 1, 0);
    sc.check(1, 1, 0);
    sc.check(1, 0, 0);
    sc.check(0, 1, 0);
    sc.check(0, 0, 1);
}
Also used : ObservableValue(de.neemann.digital.core.ObservableValue) Model(de.neemann.digital.core.Model) ElementAttributes(de.neemann.digital.core.element.ElementAttributes) TestExecuter(de.neemann.digital.TestExecuter)

Example 15 with TestExecuter

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

the class NotTest method testNot.

public void testNot() throws Exception {
    ObservableValue a = new ObservableValue("a", 2);
    Model model = new Model();
    Not out = model.add(new Not(new ElementAttributes().setBits(2)));
    out.setInputs(a.asList());
    TestExecuter sc = new TestExecuter(model).setInputs(a).setOutputs(out.getOutputs());
    sc.check(0, 3);
    sc.check(1, 2);
    sc.check(2, 1);
    sc.check(3, 0);
}
Also used : ObservableValue(de.neemann.digital.core.ObservableValue) Model(de.neemann.digital.core.Model) 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