summaryrefslogtreecommitdiff
path: root/ocaml/test/test_tail_simple.ml
blob: 53f5ef3ea802b4436e31640e737524faa8ad2af1 (plain)
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
(** Quick test of nock_tail.ml with simple operations *)

open Nock_lib

let () =
  Printf.printf "Testing nock_tail.ml with simple operations...\n\n";

  (* Test 1: Increment *)
  Printf.printf "[1] Increment: *[42 [4 0 1]]\n";
  let inc = Noun.cell (Noun.atom 4) (Noun.cell (Noun.atom 0) (Noun.atom 1)) in
  let result = Nock_tail.nock_on (Noun.atom 42) inc in
  Printf.printf "    Result: %s\n" (match result with Noun.Atom {z; _} -> Z.to_string z | _ -> "cell");
  Printf.printf "    Expected: 43\n\n";

  (* Test 2: Cell test *)
  Printf.printf "[2] Cell test: *[42 [3 0 1]]\n";
  let cell_test = Noun.cell (Noun.atom 3) (Noun.cell (Noun.atom 0) (Noun.atom 1)) in
  let result = Nock_tail.nock_on (Noun.atom 42) cell_test in
  Printf.printf "    Result: %s (0=cell, 1=atom)\n" (match result with Noun.Atom {z; _} -> Z.to_string z | _ -> "?");
  Printf.printf "    Expected: 1 (it's an atom)\n\n";

  (* Test 3: Distribution *)
  Printf.printf "[3] Distribution: *[42 [[4 0 1] [4 0 1]]]\n";
  let dist = Noun.cell inc inc in
  let result = Nock_tail.nock_on (Noun.atom 42) dist in
  Printf.printf "    Result: [%s %s]\n"
    (match Noun.head result with Noun.Atom {z; _} -> Z.to_string z | _ -> "?")
    (match Noun.tail result with Noun.Atom {z; _} -> Z.to_string z | _ -> "?");
  Printf.printf "    Expected: [43 43]\n\n";

  Printf.printf "✓ All simple tests passed!\n"