1 package net.mograsim.machine.standard.memory;
3 import static org.junit.jupiter.api.Assertions.assertEquals;
5 import java.math.BigInteger;
6 import java.util.Random;
8 import org.junit.jupiter.api.Test;
10 import net.mograsim.logic.core.timeline.Timeline;
11 import net.mograsim.logic.core.types.Bit;
12 import net.mograsim.logic.core.types.BitVector;
13 import net.mograsim.logic.core.wires.CoreWire;
14 import net.mograsim.logic.core.wires.CoreWire.ReadWriteEnd;
15 import net.mograsim.machine.MainMemoryDefinition;
17 class WordAddressableMemoryTest
20 private Timeline t = new Timeline(10);
23 public void wordAddressableMemoryLargeTest()
25 CoreWire rW = new CoreWire(t, 1, 2);
26 CoreWire data = new CoreWire(t, 16, 2);
27 CoreWire address = new CoreWire(t, 64, 2);
28 ReadWriteEnd rWI = rW.createReadWriteEnd();
29 ReadWriteEnd dataI = data.createReadWriteEnd();
30 ReadWriteEnd addressI = address.createReadWriteEnd();
32 @SuppressWarnings("unused")
33 CoreWordAddressableMemory memory = new CoreWordAddressableMemory(t, 4,
34 new WordAddressableMemory(MainMemoryDefinition.create(64, 16, 4096L, Long.MAX_VALUE)), data.createReadWriteEnd(),
35 rW.createReadOnlyEnd(), address.createReadOnlyEnd());
37 Random r = new Random();
38 for (long j = 1; j > 0; j *= 2)
40 for (int i = 0; i < 50; i++)
42 String sAddress = String.format("%64s", BigInteger.valueOf(4096 + i + j).toString(2)).replace(' ', '0');
43 sAddress = new StringBuilder(sAddress).reverse().toString();
44 BitVector bAddress = BitVector.parse(sAddress);
45 addressI.feedSignals(bAddress);
47 String random = BigInteger.valueOf(Math.abs(r.nextInt())).toString(5);
48 random = random.substring(Integer.max(0, random.length() - 16));
49 random = String.format("%16s", random).replace(' ', '0');
50 random = random.replace('2', 'X').replace('3', 'Z').replace('4', 'U');
51 BitVector vector = BitVector.parse(random);
52 dataI.feedSignals(vector);
53 rWI.feedSignals(Bit.ZERO);
55 rWI.feedSignals(Bit.ONE);
60 assertEquals(dataI.getValues(), vector);