1 functor Test (W
: WORD
) =
4 structure LW
= LargeWord
20 fun foreach (l
, f
) = List.app f l
22 fun for (f
: W
.word -> unit
) = foreach (words
, f
)
33 | Overflow
=> "Overflow"
34 |
Word w
=> W
.toString w
36 fun run (f
: unit
-> W
.word): t
=
38 handle General
.Div
=> Div
39 | General
.Overflow
=> Overflow
41 val equals
: t
* t
-> bool = op =
44 val m
= concat
["Word", Int.toString W
.wordSize
]
46 val _
= print (concat
["Testing ", m
, "\n"])
48 fun err msg
= print (concat
[m
, ": ", concat msg
, "\n"])
51 print (concat
[W
.toString w
, "\n",
52 "\t", W
.fmt
StringCvt.BIN w
, "\n",
53 "\t", W
.fmt
StringCvt.OCT w
, "\n",
54 "\t", W
.fmt
StringCvt.DEC w
, "\n",
55 "\t", W
.fmt
StringCvt.HEX w
, "\n"]))
62 ("andb", W
.andb
, LW
.andb
),
63 ("div", W
.div, LW
.div),
64 ("max", W
.max
, LW
.max
),
65 ("min", W
.min
, LW
.min
),
66 ("mod", W
.mod, LW
.mod),
67 ("orb", W
.orb
, LW
.orb
),
68 ("xorb", W
.xorb
, LW
.xorb
)],
75 val a
= Answer
.run (fn () => f (w
, w
'))
76 val a
' = Answer
.run (fn () =>
77 W
.fromLarge (f
' (W
.toLarge w
, W
.toLarge w
')))
80 if Answer
.equals (a
, a
')
82 else err
[W
.toString w
, " ", name
, " ", W
.toString w
',
83 " = ", Answer
.toString a
, " <> ", Answer
.toString a
']
88 if w
= valOf (W
.fromString (W
.toString w
))
90 else err
["{from,to}String"])
94 ([("<<", W
.<<, LW
.<<),
100 ([0w0
, 0w1
, 0w2
, 0w4
, 0w8
, 0w15
, 0w30
, 0wxFF
],
104 val a
' = W
.fromLarge (f
' (W
.toLarge w
, w
'))
108 else err
[W
.toString w
, " ", name
, " ", Word.toString w
',
109 " = ", W
.toString a
, " <> ", W
.toString a
']
114 ([("~>>", W
.~
>>, LW
.~
>>)],
119 ([0w0
, 0w1
, 0w2
, 0w4
, 0w8
, 0w15
, 0w30
, 0wxFF
],
123 val a
' = W
.fromLarge (f
' (W
.toLargeX w
, w
'))
127 else err
[W
.toString w
, " ", name
, " ", Word.toString w
',
128 " = ", W
.toString a
, " <> ", W
.toString a
']
136 (">=", W
.>=, LW
.>=)],
144 val b
' = f
' (W
.toLarge w
, W
.toLarge w
')
148 else err
[W
.toString w
, " ", name
, " ", W
.toString w
',
149 " = ", Bool.toString b
, " <> ", Bool.toString b
']
154 ([("compare", W
.compare
, LW
.compare
)],
162 val or
' = f
' (W
.toLarge w
, W
.toLarge w
')
166 else err
[W
.toString w
, " ", name
, " ", W
.toString w
']
172 if w
= W
.fromLargeInt (W
.toLargeInt w
)
173 andalso w
= W
.fromLargeInt (W
.toLargeIntX w
)
174 andalso (case SOME (W
.toInt w
) handle Overflow
=> NONE
of
176 | SOME i
=> w
= W
.fromInt i
)
177 andalso (case SOME (W
.toIntX w
) handle Overflow
=> NONE
of
179 | SOME i
=> w
= W
.fromInt i
)
181 else err
["{from,to}Large"])
187 val a
' = W
.fromLarge (LW
.notb (W
.toLarge w
))
191 else err
["notb ", W
.toString w
, " = ", W
.toString a
, " <> ",
197 if W
.~ w
= W
.- (zero
, w
)
203 structure Z
= Test (Word2
)
204 structure Z
= Test (Word3
)
205 structure Z
= Test (Word4
)
206 structure Z
= Test (Word7
)
207 structure Z
= Test (Word8)
208 structure Z
= Test (Word9
)
209 structure Z
= Test (Word13
)
210 structure Z
= Test (Word16
)
211 structure Z
= Test (Word17
)
212 structure Z
= Test (Word20
)
213 structure Z
= Test (Word25
)
214 structure Z
= Test (Word30
)
215 structure Z
= Test (Word31
)
216 structure Z
= Test (Word32
)
217 structure Z
= Test (Word64
)