File: Test149.ML

package info (click to toggle)
polyml 5.6-8
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 31,892 kB
  • ctags: 34,453
  • sloc: cpp: 44,983; ansic: 24,520; asm: 14,850; sh: 11,730; makefile: 551; exp: 484; python: 253; awk: 91; sed: 9
file content (26 lines) | stat: -rw-r--r-- 573 bytes parent folder | download | duplicates (5)
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
(* Some tests for the HashArray structure. *)

open HashArray;
val a = hash 10: int hash;
update(a, "a", 1);
update(a, "b", 2);
update(a, "k", 3); (* Happens to hash to the same as "a" *)
update(a, "l", 4);

val sum = fold (fn (_, a, b) => a+b) 0;

fun verify true = () | verify false = raise Fail "failed";

verify(sub(a, "a") = SOME 1);
verify(sub(a, "b") = SOME 2);
verify(sub(a, "c") = NONE);
verify(sub(a, "k") = SOME 3);
verify(sub(a, "l") = SOME 4);
verify(sum a = 10);

delete(a, "a");
verify(sub(a, "a") = NONE);
verify(sub(a, "k") = SOME 3);

verify(sum a = 9);