Fixed Clock polarities to values where the Am2900 works
[Mograsim.git] / tests / net.mograsim.logic.tests / src / net / mograsim / logic / core / tests / TestCoreBitDisplay.java
1 package net.mograsim.logic.core.tests;
2
3 import static org.junit.jupiter.api.Assertions.assertArrayEquals;
4
5 import java.util.function.LongConsumer;
6
7 import net.mograsim.logic.core.components.CoreBitDisplay;
8 import net.mograsim.logic.core.timeline.Timeline;
9 import net.mograsim.logic.core.timeline.TimelineEventHandler;
10 import net.mograsim.logic.core.types.Bit;
11 import net.mograsim.logic.core.wires.CoreWire.ReadEnd;
12
13 public final class TestCoreBitDisplay extends CoreBitDisplay
14 {
15
16         public TestCoreBitDisplay(Timeline timeline, ReadEnd in)
17         {
18                 super(timeline, in);
19         }
20
21         public void assertDisplays(Bit... expected)
22         {
23                 assertArrayEquals(expected, getDisplayedValue().getBits());
24         }
25
26         public void assertAfterSimulationIs(Bit... expected)
27         {
28                 timeline.executeAll();
29                 assertDisplays(expected);
30         }
31
32         public void assertAfterSimulationIs(LongConsumer r, Bit... expected)
33         {
34                 while (timeline.hasNext())
35                 {
36                         timeline.executeNext();
37                         r.accept(timeline.getSimulationTime());
38                 }
39                 assertDisplays(expected);
40         }
41
42         @Override
43         protected TimelineEventHandler compute()
44         {
45                 TimelineEventHandler handler = super.compute();
46                 return e ->
47                 {
48                         handler.handle(e);
49                         System.out.println("update: value is " + getDisplayedValue());
50                 };
51         }
52 }