X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.core%2Ftest%2Fnet%2Fmograsim%2Flogic%2Fcore%2Ftests%2FTestBitDisplay.java;fp=net.mograsim.logic.core%2Ftest%2Fnet%2Fmograsim%2Flogic%2Fcore%2Ftests%2FTestBitDisplay.java;h=015e257fd621cac297feb15c94da18abbbfa8a74;hb=f14ea37d69488dd51518a36413af7176916b8bd7;hp=0000000000000000000000000000000000000000;hpb=a84700145147c263ad6692c99117a7cf37832378;p=Mograsim.git diff --git a/net.mograsim.logic.core/test/net/mograsim/logic/core/tests/TestBitDisplay.java b/net.mograsim.logic.core/test/net/mograsim/logic/core/tests/TestBitDisplay.java new file mode 100644 index 00000000..015e257f --- /dev/null +++ b/net.mograsim.logic.core/test/net/mograsim/logic/core/tests/TestBitDisplay.java @@ -0,0 +1,47 @@ +package net.mograsim.logic.core.tests; + +import static org.junit.jupiter.api.Assertions.assertArrayEquals; + +import java.util.function.LongConsumer; + +import net.mograsim.logic.core.components.BitDisplay; +import net.mograsim.logic.core.timeline.Timeline; +import net.mograsim.logic.core.types.Bit; +import net.mograsim.logic.core.wires.Wire.ReadEnd; + +public final class TestBitDisplay extends BitDisplay +{ + + public TestBitDisplay(Timeline timeline, ReadEnd in) + { + super(timeline, in); + } + + public void assertDisplays(Bit... expected) + { + assertArrayEquals(expected, getDisplayedValue().getBits()); + } + + public void assertAfterSimulationIs(Bit... expected) + { + timeline.executeAll(); + assertDisplays(expected); + } + + public void assertAfterSimulationIs(LongConsumer r, Bit... expected) + { + while (timeline.hasNext()) + { + timeline.executeNext(); + r.accept(timeline.getSimulationTime()); + } + assertDisplays(expected); + } + + @Override + protected void compute() + { + super.compute(); + System.out.println("update: value is " + getDisplayedValue()); + } +}