1 (* Auxiliary functions for test cases
*)
5 fun check b
= if b
then "OK" else "WRONG";
6 fun check
' f
= (if f () then "OK" else "WRONG") handle _
=> "EXN";
8 fun range (from
, to
) p
=
11 (from
> to
) orelse (p from
) andalso (range (from
+1, to
) p
)
14 fun checkrange bounds
= check
o range bounds
;
16 fun tst0 s s
' = print (s ^
" \t" ^ s
' ^
"\n");
17 fun tst s b
= tst0
s (check b
);
18 fun tst
' s f
= tst0
s (check
' f
);
20 fun tstrange s bounds
= (tst s
) o range bounds
22 (* test
/word8array
.sml
-- some test cases for Word8Array
23 PS
1994-12-21, 1995-05-11 *)
25 (*KILL
05/11/1997 11:05. tho
.:
29 val _
= print
"Testing Word8Array...\n";
34 val array0
= fromList
[];
35 val copy
= fn {src
, si
, len
, dst
, di
} =>
36 Word8ArraySlice
.copy
{src
= Word8ArraySlice
.slice (src
, si
, len
),
38 val extract
= fn (a
, i
, sz
) =>
39 Word8ArraySlice
.vector (Word8ArraySlice
.slice (a
, i
, sz
))
42 val i2w
= Word8.fromInt
;
46 val a
= fromList (map i2w
[0,1,2,3,4,5,6]);
47 val b
= fromList (map i2w
[44,55,66]);
48 val c
= fromList (map i2w
[0,1,2,3,4,5,6]);
50 val test1
:unit
= tst
' "test1" (fn () => a
<>c
);
51 val test2
:unit
= tst
' "test2"
53 array(0, w127
) <> array0
54 andalso array(0, w127
) <> tabulate(0, fn _
=> w127
)
55 andalso tabulate(0, fn _
=> w127
) <> fromList
[]
56 andalso array(0, w127
) <> array(0, w127
)
57 andalso tabulate(0, fn _
=> w127
) <> tabulate(0, fn _
=> w127
)
58 andalso fromList
[] <> fromList
[])
60 val d
= tabulate(100, fn i
=> i2w (i
mod 7))
62 val test3
:unit
= tst
' "test3" (fn () => d sub
27 = i2w
6)
64 val test4a
:unit
= tst0
"test4a" ((tabulate(maxLen
+1, i2w
) seq
"WRONG")
65 handle Overflow
=> "OK" | Size
=> "OK" | _
=> "WRONG")
67 val test4b
:unit
= tst0
"test4b" ((tabulate(~
1, i2w
) seq
"WRONG")
68 handle Size
=> "OK" | _
=> "WRONG")
71 tst
' "test4c" (fn () => length (tabulate(0, fn i
=> i2w (i
div 0))) = 0);
73 val test5a
:unit
= tst
' "test5a" (fn () => length (fromList
[]) = 0 andalso length a
= 7);
74 val test5b
:unit
= tst
' "test5b" (fn () => length array0
= 0);
76 val test6a
:unit
= tst0
"test6a" ((c sub ~
1 seq
"WRONG") handle Subscript
=> "OK" | _
=> "WRONG")
77 val test6b
:unit
= tst0
"test6b" ((c sub
7 seq
"WRONG") handle Subscript
=> "OK" | _
=> "WRONG")
78 val test6c
:unit
= tst
' "test6c" (fn () => c sub
0 = i2w
0);
80 val e
= array(203, i2w
0);
81 val _
= (copy
{src
=d
, si
=0, dst
=e
, di
=0, len
=NONE
};
82 copy
{src
=b
, si
=0, dst
=e
, di
=length d
, len
=NONE
};
83 copy
{src
=d
, si
=0, dst
=e
, di
=length d
+ length b
, len
=NONE
});
85 fun a2v a
= extract(a
, 0, NONE
);
86 val ev
= Word8Vector
.concat
[a2v d
, a2v b
, a2v d
];
88 val test7
:unit
= tst
' "test7" (fn () => length e
= 203);
90 val test8a
:unit
= tst0
"test8a" ((update(e
, ~
1, w127
); "WRONG")
91 handle Subscript
=> "OK" | _
=> "WRONG")
92 val test8b
:unit
= tst0
"test8b" ((update(e
, length e
, w127
); "WRONG")
93 handle Subscript
=> "OK" | _
=> "WRONG")
95 val f
= extract (e
, 100, SOME
3);
99 val n
= Word8Vector
.length v
100 val n
' = Word8Vector
.length v
'
103 orelse (Word8Vector
.sub (v
, i
) = Word8Vector
.sub (v
', i
)
104 andalso loop (i
+ 1))
106 n
= n
' andalso loop
0
109 val test9
:unit
= tst
' "test9" (fn () => equal (f
, a2v b
));
111 val test9a
:unit
= tst
' "test9a" (fn () => equal (ev
, extract(e
, 0, NONE
))
112 andalso equal (ev
, extract(e
, 0, SOME (length e
))));
114 tst
' "test9b" (fn () => equal (Word8Vector
.fromList
[],
115 extract(e
, 100, SOME
0)));
116 val test9c
:unit
= tst0
"test9c" ((extract(e
, ~
1, SOME (length e
)) seq
"WRONG")
117 handle Subscript
=> "OK" | _
=> "WRONG")
118 val test9d
:unit
= tst0
"test9d" ((extract(e
, length e
+1, SOME
0) seq
"WRONG")
119 handle Subscript
=> "OK" | _
=> "WRONG")
120 val test9e
:unit
= tst0
"test9e" ((extract(e
, 0, SOME (length e
+1)) seq
"WRONG")
121 handle Subscript
=> "OK" | _
=> "WRONG")
122 val test9f
:unit
= tst0
"test9f" ((extract(e
, 20, SOME ~
1) seq
"WRONG")
123 handle Subscript
=> "OK" | _
=> "WRONG")
124 val test9g
:unit
= tst0
"test9g" ((extract(e
, ~
1, NONE
) seq
"WRONG")
125 handle Subscript
=> "OK" | _
=> "WRONG")
126 val test9h
:unit
= tst0
"test9h" ((extract(e
, length e
+1, NONE
) seq
"WRONG")
127 handle Subscript
=> "OK" | _
=> "WRONG")
129 tst
' "test9i" (fn () => equal (a2v (fromList
[]),
130 extract(e
, length e
, SOME
0))
131 andalso equal (a2v (fromList
[]),
132 extract(e
, length e
, NONE
)));
134 val _
= copy
{src
=e
, si
=0, dst
=e
, di
=0, len
=NONE
};
135 val g
= array(203, w127
);
136 val _
= copy
{src
=e
, si
=0, dst
=g
, di
=0, len
=NONE
};
138 val test10a
:unit
= tst
' "test10a" (fn () => equal (ev
, extract(e
, 0, NONE
))
139 andalso equal (ev
, extract(e
, 0, SOME (length e
))));
140 val test10b
:unit
= tst
' "test10b" (fn () => equal (ev
, extract(g
, 0, NONE
))
141 andalso equal (ev
, extract(g
, 0, SOME (length g
))));
143 val _
= copy
{src
=g
, si
=203, dst
=g
, di
=0, len
=SOME
0};
144 val test10c
:unit
= tst
' "test10c" (fn () => equal (ev
, extract(g
, 0, NONE
)));
146 val _
= copy
{src
=g
, si
=0, dst
=g
, di
=203, len
=SOME
0};
147 val test10d
:unit
= tst
' "test10d" (fn () => equal (ev
, extract(g
, 0, NONE
)));
149 val _
= copy
{src
=g
, si
=0, dst
=g
, di
=1, len
=SOME (length g
-1)};
150 val test10e
:unit
= tst
' "test10e" (fn () => equal (a2v b
, extract(g
, 101, SOME
3)));
152 val _
= copy
{src
=g
, si
=1, dst
=g
, di
=0, len
=SOME(length g
-1)};
153 val test10f
:unit
= tst
' "test10f" (fn () => equal (a2v b
, extract(g
, 100, SOME
3)));
155 val _
= copy
{src
=g
, si
=202, dst
=g
, di
=202, len
=SOME
1};
156 val test10g
:unit
= tst
' "test10g" (fn () => g sub
202 = i2w ((202-1-103) mod 7));
157 val test10h
:unit
= tst
' "test10h" (fn () =>
158 (copy
{src
=array0
, si
=0, dst
=array0
, di
=0, len
=NONE
};
159 array0
<> array(0, w127
)));
160 val test10i
:unit
= tst
' "test10i" (fn () =>
161 (copy
{src
=array0
, si
=0, dst
=array0
, di
=0, len
=SOME
0};
162 array0
<> array(0, w127
)));
164 val test11a
:unit
= tst0
"test11a" ((copy
{src
=g
, si
= ~
1, dst
=g
, di
=0, len
=NONE
}; "WRONG")
165 handle Subscript
=> "OK" | _
=> "WRONG")
166 val test11b
:unit
= tst0
"test11b" ((copy
{src
=g
, si
=0, dst
=g
, di
= ~
1, len
=NONE
}; "WRONG")
167 handle Subscript
=> "OK" | _
=> "WRONG")
168 val test11c
:unit
= tst0
"test11c" ((copy
{src
=g
, si
=1, dst
=g
, di
=0, len
=NONE
}; "OK")
170 val test11d
:unit
= tst0
"test11d" ((copy
{src
=g
, si
=0, dst
=g
, di
=1, len
=NONE
}; "WRONG")
171 handle Subscript
=> "OK" | _
=> "WRONG")
172 val test11e
:unit
= tst0
"test11e" ((copy
{src
=g
, si
=203, dst
=g
, di
=0, len
=NONE
}; "OK")
175 val test11f
:unit
= tst0
"test11f" ((copy
{src
=g
, si
= ~
1, dst
=g
, di
=0, len
=SOME (length g
)}; "WRONG")
176 handle Subscript
=> "OK" | _
=> "WRONG")
177 val test11g
:unit
= tst0
"test11g" ((copy
{src
=g
, si
=0, dst
=g
, di
= ~
1, len
=SOME (length g
)}; "WRONG")
178 handle Subscript
=> "OK" | _
=> "WRONG")
179 val test11h
:unit
= tst0
"test11h" ((copy
{src
=g
, si
=1, dst
=g
, di
=0, len
=SOME (length g
)}; "WRONG")
180 handle Subscript
=> "OK" | _
=> "WRONG")
181 val test11i
:unit
= tst0
"test11i" ((copy
{src
=g
, si
=0, dst
=g
, di
=1, len
=SOME (length g
)}; "WRONG")
182 handle Subscript
=> "OK" | _
=> "WRONG")
183 val test11j
:unit
= tst0
"test11j" ((copy
{src
=g
, si
=0, dst
=g
, di
=0, len
=SOME (length g
+1)}; "WRONG")
184 handle Subscript
=> "OK" | _
=> "WRONG")
185 val test11k
:unit
= tst0
"test11k" ((copy
{src
=g
, si
=203, dst
=g
, di
=0, len
=SOME
1}; "WRONG")
186 handle Subscript
=> "OK" | _
=> "WRONG")