-
Notifications
You must be signed in to change notification settings - Fork 9
/
wire_test.ml
35 lines (28 loc) · 852 Bytes
/
wire_test.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
open Wire;;
let () =
assert (10 = tap [
("z", fun wires -> tap wires "a" + tap wires "b") ;
("a", fun _ -> 3) ;
("b", fun _ -> 7) ;
] "z");
assert (10 = tap [
("z", plus "a" "b") ;
("a", constant 3) ;
("b", constant 7) ;
] "z");
(* Make a half-adder from inputs a and b *)
let make_half_adder = fun a -> fun b -> [
("d", or_ "a" "b") ;
("c", and_ "a" "b") ;
("e", not_ "c") ;
("s", and_ "d" "e") ;
("a", constant a) ;
("b", constant b)
] in
(* Test the sum and carry bits *)
assert (1 = tap (make_half_adder 1 1) "c");
assert (0 = tap (make_half_adder 1 1) "s");
assert (0 = tap (make_half_adder 1 0) "c");
assert (1 = tap (make_half_adder 1 0) "s");
assert (0 = tap (make_half_adder 0 0) "c");
assert (0 = tap (make_half_adder 0 0) "s");