|
1 | 1 | import { assertEquals } from "jsr:@std/assert"; |
2 | | -import Bit from "./bit.ts"; |
3 | | -import clock from "../clock/clock.ts"; // Adjust as needed |
| 2 | +import Bit from "./bit.ts"; // Adjust the import as needed |
4 | 3 |
|
5 | 4 | Deno.test("Bit: outputs 0 initially", () => { |
6 | | - const bit = Bit(); |
7 | | - assertEquals(bit(0, 0), 0); |
8 | | - assertEquals(bit(1, 0), 0); |
| 5 | + const bit = Bit(0, 0); |
| 6 | + assertEquals(bit.value, 0); |
9 | 7 | }); |
10 | 8 |
|
11 | 9 | Deno.test("Bit: loads and stores a 1", () => { |
12 | | - const bit = Bit(); |
13 | | - assertEquals(bit(1, 1), 0); // Set input=1, load=1, output still 0 |
14 | | - clock.tick(); |
15 | | - clock.tock(); |
16 | | - assertEquals(bit(0, 0), 1); // Output updates to 1 |
| 10 | + const bit = Bit(0, 0); |
| 11 | + assertEquals(bit.value, 0); |
| 12 | + |
| 13 | + bit.in = 1; |
| 14 | + bit.load = 1; |
| 15 | + bit.tick(); |
| 16 | + bit.tock(); |
| 17 | + |
| 18 | + assertEquals(bit.value, 1); |
17 | 19 | }); |
18 | 20 |
|
19 | 21 | Deno.test("Bit: holds value when load is 0", () => { |
20 | | - const bit = Bit(); |
21 | | - bit(1, 1); // Prepare to store 1 |
22 | | - clock.tick(); |
23 | | - clock.tock(); |
24 | | - assertEquals(bit(0, 0), 1); // Output is 1 |
25 | | - |
26 | | - bit(0, 0); // load=0, input=0, should not change |
27 | | - clock.tick(); |
28 | | - clock.tock(); |
29 | | - assertEquals(bit(0, 0), 1); // Output still 1 |
| 22 | + const bit = Bit(0, 0); |
| 23 | + |
| 24 | + bit.in = 1; |
| 25 | + bit.load = 1; |
| 26 | + bit.tick(); |
| 27 | + bit.tock(); |
| 28 | + assertEquals(bit.value, 1); |
| 29 | + |
| 30 | + bit.in = 0; |
| 31 | + bit.load = 0; |
| 32 | + bit.tick(); |
| 33 | + bit.tock(); |
| 34 | + assertEquals(bit.value, 1); // Should still hold the previous value |
30 | 35 | }); |
31 | 36 |
|
32 | 37 | Deno.test("Bit: can reset to 0 when load is 1", () => { |
33 | | - const bit = Bit(); |
34 | | - bit(1, 1); |
35 | | - clock.tick(); |
36 | | - clock.tock(); |
37 | | - assertEquals(bit(0, 0), 1); |
38 | | - |
39 | | - bit(0, 1); // load=1, input=0, should store 0 |
40 | | - clock.tick(); |
41 | | - clock.tock(); |
42 | | - assertEquals(bit(0, 0), 0); |
| 38 | + const bit = Bit(0, 0); |
| 39 | + |
| 40 | + bit.in = 1; |
| 41 | + bit.load = 1; |
| 42 | + bit.tick(); |
| 43 | + bit.tock(); |
| 44 | + assertEquals(bit.value, 1); |
| 45 | + |
| 46 | + bit.in = 0; |
| 47 | + bit.load = 1; |
| 48 | + bit.tick(); |
| 49 | + bit.tock(); |
| 50 | + assertEquals(bit.value, 0); |
43 | 51 | }); |
44 | 52 |
|
45 | 53 | Deno.test("Bit: does not change output until tock", () => { |
46 | | - const bit = Bit(); |
47 | | - bit(1, 1); |
48 | | - clock.tick(); |
49 | | - assertEquals(bit(0, 0), 0); // Output not updated yet |
50 | | - clock.tock(); |
51 | | - assertEquals(bit(0, 0), 1); // Output updated after tock |
| 54 | + const bit = Bit(0, 0); |
| 55 | + |
| 56 | + bit.in = 1; |
| 57 | + bit.load = 1; |
| 58 | + bit.tick(); |
| 59 | + assertEquals(bit.value, 0); // Output not updated yet |
| 60 | + bit.tock(); |
| 61 | + assertEquals(bit.value, 1); // Output updated after tock |
52 | 62 | }); |
0 commit comments