1lappend auto_path .
2package require Gmpz
3namespace import ::gmp::z*
4#
5# binary operators
6#
7set ntests 0
8set nfailures 0
9foreach {op op1 op2 result} {
10    zadd 1 1 2
11    zadd 11111111111111111 11111111111111111 22222222222222222
12    zsub 1 1 0
13    zsub 11111111111111111 11111111111111111 0
14    zmul 2 2 4
15    zmul 22222222222222222 22222222222222222 493827160493827150617283950617284
16    zdiv 4 2 2
17    zdiv 44444444444444444 22222222222222222 2
18    zrem 4 2 0
19    zrem 4 3 1
20    zmod 4 3 1
21    zgcd 22 33 11
22    zcmp 2 1 1
23    zcmp 1 2 -1
24    zcmp 2 2 0
25    zand 255 127 127
26    zior 128 1 129
27} {
28    if {[string compare [$op $op1 $op2] $result] != 0} {
29	puts "\[$op $op1 $op2\] == [$op $op1 $op2] instead of $result"
30	incr nfailures
31    }
32    incr ntests
33}
34#
35# unary operators
36#
37foreach {op op1 result} {
38    zneg 1 -1
39    zneg -1 1
40    zcom 128 -129
41    zabs -1 1
42    zabs 1 1
43    zsqrt 4 2
44    zsqrt 10 3
45    zsqrt 493827160493827150617283950617284 22222222222222222
46} {
47    if {[string compare [$op $op1] $result] != 0} {
48	puts "\[$op $op1\] == [$op $op1] instead of $result"
49	incr nfailures
50    }
51    incr ntests
52}
53#
54# base conversion
55#
56foreach {op ibase obase result} {
57    1010101 2 10 85
58    85 10 2 1010101
59    1777 8 10 1023
60    1023 10 8 1777
61} {
62    if {[string compare [zcvt $op $ibase $obase] $result] != 0} {
63	puts "\[zcvt $op $ibase $obase\] == [zcvt $op $ibase $obase] instead of $result"
64	incr nfailures
65    }
66    incr ntests
67}
68#
69# summary
70#
71puts "$nfailures failures in $ntests tests"
72