1 module dcpu16.emulator.test;
2 
3 import dcpu16.emulator;
4 
5 unittest
6 {
7     enum blob = import("test.bin");
8 
9     auto comp = new Computer();
10     comp.load(cast(ubyte[]) blob, true);
11 
12     foreach(_; 0 .. 4000)
13     {
14         comp.cpu.step;
15     }
16 }
17 
18 unittest
19 {
20     enum blob = import("test_basic_stuff.bin");
21 
22     auto comp = new Computer();
23     comp.load(cast(ubyte[]) blob, true);
24 
25     foreach(_; 0 .. 1000)
26     {
27         comp.cpu.step;
28     }
29 
30     assert(comp.cpu.regs.x == 0x40);
31 }
32 
33 unittest
34 {
35     enum str = import("self-copy.bin");
36     auto blob = cast(ubyte[]) str;
37 
38     auto comp = new Computer();
39     comp.load(blob, true);
40 
41     const etalon = comp.mem[0x01 .. 0x19];
42 
43     foreach(_; 0 .. 1000)
44     {
45         comp.cpu.step;
46     }
47 
48     import std.algorithm.comparison;
49 
50     foreach(n; 0 .. 8)
51     {
52         size_t offset = 1 + (etalon.length-1) * n;
53         const copy = comp.mem[offset .. offset + etalon.length];
54 
55         assert(equal(etalon, copy));
56     }
57 }