Search in sources :

Example 1 with Delay

use of de.neemann.digital.core.wiring.Delay in project Digital by hneemann.

the class DelayTest method testDelayVar.

public void testDelayVar() throws Exception {
    for (int delayTime = 0; delayTime < 5; delayTime++) {
        ObservableValue in = new ObservableValue("in", 1);
        Model model = new Model();
        Delay delay = model.add(new Delay(new ElementAttributes().set(Keys.DELAY_TIME, delayTime)));
        delay.setInputs(in.asList());
        assertEquals(1, delay.getOutputs().size());
        ObservableValue out = delay.getOutputs().get(0);
        model.init();
        in.setValue(0);
        model.doStep();
        assertEquals(0, out.getValue());
        in.setValue(1);
        for (int i = 1; i < delayTime; i++) {
            assertTrue(model.needsUpdate());
            model.doMicroStep(false);
            assertEquals(0, out.getValue());
        }
        assertTrue(model.needsUpdate());
        model.doMicroStep(false);
        assertEquals(1, out.getValue());
        assertFalse(model.needsUpdate());
    }
}
Also used : ObservableValue(de.neemann.digital.core.ObservableValue) Model(de.neemann.digital.core.Model) ElementAttributes(de.neemann.digital.core.element.ElementAttributes) Delay(de.neemann.digital.core.wiring.Delay)

Example 2 with Delay

use of de.neemann.digital.core.wiring.Delay in project Digital by hneemann.

the class DelayTest method testDelay.

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

Aggregations

Model (de.neemann.digital.core.Model)2 ObservableValue (de.neemann.digital.core.ObservableValue)2 ElementAttributes (de.neemann.digital.core.element.ElementAttributes)2 Delay (de.neemann.digital.core.wiring.Delay)2 TestExecuter (de.neemann.digital.TestExecuter)1