-
Notifications
You must be signed in to change notification settings - Fork 7
/
tests.cpp
331 lines (284 loc) · 16.9 KB
/
tests.cpp
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include "primes.h"
#include "ellipticcurve.h"
#include "tests.h"
#include "small_primes.h"
#include "curvesnist.h"
using namespace std;
void PrimesTest::setUp()
{
p = gen.generate_prime(100);
q = 3;
}
void PrimesTest::tearDown()
{
}
void PrimesTest::test_legendre_symbol(){
int p1 = 587;
int p1_residues[] = {0, 1, -1, 1, 1, -1, -1, 1, -1, 1, 1, -1, 1, -1, -1, -1, 1, 1, -1, -1, -1, 1, 1, -1, -1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, 1, -1, 1, -1, 1, -1, -1, 1, -1, -1, 1, 1, 1, 1, -1, 1, -1, 1, -1, 1, -1, -1, -1, 1, -1, -1, -1, 1, 1, 1, 1, 1, 1, -1, 1, -1, -1, 1, 1, 1, -1, -1, 1, 1, -1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, -1, -1, 1, -1, 1, -1, -1, -1, -1, 1, 1, -1, -1, 1, -1, -1, -1, 1, -1, -1, -1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, -1, 1, -1, -1, -1, -1, 1, -1, -1, -1, -1, -1, -1, -1, 1, 1, -1, -1, 1, 1, 1, 1, -1, -1, 1, -1, 1, -1, 1, 1, 1, 1, -1, -1, -1, -1, 1, 1, -1, -1, 1, -1, 1, -1, 1, -1, 1, 1, -1, 1, -1, -1, 1, -1, 1, -1, 1, -1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, -1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, -1, 1, -1, -1, 1, 1, 1, 1, -1, 1, 1, -1, 1, -1, -1, -1, 1, -1, -1, -1, 1, 1, -1, 1, 1, -1, -1, -1, -1, -1, 1, -1, -1, 1, 1, -1, 1, 1, -1, 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, 1, -1, 1, -1, 1, 1, 1, 1, 1, -1, 1, -1, -1, -1, -1, -1, 1, 1, 1, 1, -1, 1, -1, 1, -1, -1, -1, 1, 1, -1, 1, 1, -1, -1, 1, -1, -1, 1, 1, 1, -1, 1, -1, 1, -1, -1, -1, -1, 1, 1, 1, 1, 1, -1, 1, -1, -1, -1, -1, -1, 1, -1, 1, -1, -1, -1, 1, 1, -1, -1, 1, -1, -1, -1, 1, -1, -1, 1, -1, -1, 1, 1, -1, 1, 1, 1, 1, 1, -1, -1, 1, -1, -1, 1, 1, 1, -1, 1, 1, 1, -1, 1, -1, -1, 1, -1, -1, -1, -1, 1, 1, -1, 1, -1, -1, -1, -1, 1, 1, -1, -1, -1, -1, 1, -1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, -1, -1, 1, 1, -1, -1, 1, -1, -1, 1, -1, 1, -1, 1, -1, 1, 1, -1, 1, -1, -1, 1, -1, 1, -1, 1, -1, 1, 1, -1, -1, 1, 1, 1, 1, -1, -1, -1, -1, 1, -1, 1, -1, 1, 1, -1, -1, -1, -1, 1, 1, -1, -1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, -1, 1, -1, -1, -1, -1, 1, 1, -1, -1, -1, -1, -1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, 1, 1, -1, 1, -1, 1, 1, -1, -1, -1, -1, 1, 1, -1, -1, -1, -1, 1, -1, -1, 1, 1, -1, -1, -1, 1, 1, -1, 1, -1, -1, -1, -1, -1, -1, 1, 1, 1, -1, 1, 1, 1, -1, 1, -1, 1, -1, 1, -1, -1, -1, -1, 1, 1, -1, 1, 1, -1, 1, -1, 1, -1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, 1, 1, -1, -1, 1, 1, 1, -1, -1, 1, 1, 1, -1, 1, -1, -1, 1, -1, 1, 1, -1, -1, 1, -1}; //computed directly via an external script
for (int i=0; i<p1; i++){
CPPUNIT_ASSERT(legendre_symbol(i,p1) == p1_residues[i]);
}
mpz_class temp_number = gen.rand(p);
CPPUNIT_ASSERT((temp_number % p == 0) || legendre_symbol(temp_number*temp_number,p) == 1);
CPPUNIT_ASSERT(legendre_symbol(temp_number*temp_number*temp_number,p) == legendre_symbol(temp_number,p));
mpz_class mod = p % 3;
switch(mod.get_ui()){ // -3 is QR modulo p iff p = 1 (mod 3)
case 0:
case 2: CPPUNIT_ASSERT(legendre_symbol(p-3,p) == -1); break;
case 1: CPPUNIT_ASSERT(legendre_symbol(p-3,p) == 1); break;
}
}
void PrimesTest::test_square_root(){
int number_of_primes = 3;
int primes[3] = {587, 653, 1033}; // chosen to cover all cases
for (int i = 0; i<number_of_primes; i++){
mpz_class n = gen.rand(primes[i]);
mpz_class root = modular_square_root((n*n) % primes[i],primes[i]);
// cout << "n, root, p=" << n <<", " << root << ", "<<primes[i]<<endl;
CPPUNIT_ASSERT(n == root || primes[i]-n == root);
}
}
void PrimesTest::test_small_primes(){
for (int i=0; i<10; i++){
mpz_class p = gen.generate_prime(10);
for (int j=2; j<p / 2 ; j++) //as naive as it gets
CPPUNIT_ASSERT(p % j != 0);
}
}
void PrimesTest::test_rand(){
mpz_class a = gen.rand_binary_digits(100);
mpz_class b = gen.rand_binary_digits(100);
CPPUNIT_ASSERT(a != b); //if this happens, our PRNG sucks.
}
void PrimesTest::test_is_odd()
{
CPPUNIT_ASSERT((p % 2) == 1);
CPPUNIT_ASSERT((q % 2) == 1);
}
void PrimesTest::test_generate_prime_for_discriminant(){
//TODO: this test OFTEN FAILS. check why.
mpz_class D = gen.rand(100);
mpz_class s,t;
mpz_class p = gen.generate_prime_for_discriminant(10,D,t,s);
// CPPUNIT_ASSERT(4*p == t*t+s*s*D);
}
void PrimesTest::test_is_near_prime(){
mpz_class p = gen.generate_prime(100);
mpz_class min_size = p;
mpz_class temp = p;
CPPUNIT_ASSERT(is_near_prime(p,-1,min_size) == true);
for (int i=0; i<NUM_SMALL_PRIMES; i++){
if (rand() % 2 == 0)
temp *= small_primes[i];
}
CPPUNIT_ASSERT(is_near_prime(temp,-1,min_size) == true);
CPPUNIT_ASSERT(is_near_prime(p*small_primes[NUM_SMALL_PRIMES - 10],NUM_SMALL_PRIMES - 10,min_size) == false);
}
void PrimesTest::test_extended_cornacchia(){
mpz_class t,s;
CPPUNIT_ASSERT(extended_cornacchia(31,-3,t,s) == true && t == 7 && s == 5);
CPPUNIT_ASSERT(extended_cornacchia(281,-28,t,s) == true && t == 26 && s == 4);
CPPUNIT_ASSERT(extended_cornacchia(11719,-43,t,s) == true && t == 7 && s == 33);
CPPUNIT_ASSERT(extended_cornacchia(577,-9,t,s) == true && t == 2 && s == 16);
CPPUNIT_ASSERT(extended_cornacchia(73,-37,t,s) == true && t == 12 && s == 2);
}
void EllipticCurveTest::setUp()
{
random_curve = ECPrime::randomCurve(10, gen);
}
void EllipticCurveTest::tearDown()
{
}
void EllipticCurveTest::test_get_point()
{
ZpCoordinate P = ZpCoordinate::infinity();
zp_int x;
while (P == ZpCoordinate::infinity()){
x = gen.generate_modulu_p(random_curve.mod);
P = random_curve.getPoint(x);
}
//test if P is really on the curve
// cout << "x, y = " << P.X << ", " << P.Y << endl;
// cout << "p, a, b = " << random_curve.mod << ", " << random_curve.ECC_a << ", " <<random_curve.ECC_b << endl;
CPPUNIT_ASSERT((P.Y*P.Y) == (P.X*P.X*P.X + random_curve.ECC_a*P.X + random_curve.ECC_b));
//test if getPoint really knows to return the "negative" value
CPPUNIT_ASSERT(P.Y + random_curve.getPoint(x,true).Y == 0);
}
void EllipticCurveTest::test_doubling_vs_addition()
{
ZpCoordinate P = random_curve.get_random_point();
ZpCoordinate Q,R;
// cout << "(test) P.Y.p = " << P.Y.get_p() << endl;
Q = random_curve.doubling(P);
//first check if P+P == 2P (P+P should be computed by reduction to the computation of 2P, so shouldn't be a problem
CPPUNIT_ASSERT(random_curve.addition(P,P) == Q);
//now check if P + Q + P + Q == 2(P+Q)
ZpCoordinate temp = P;
temp = random_curve.addition(temp,Q); // P != Q, so ok
temp = random_curve.addition(temp,P); // P+Q != P, so ok
temp = random_curve.addition(temp,Q); // temp = P+Q+P+Q
CPPUNIT_ASSERT(temp == random_curve.doubling(random_curve.addition(P,Q)));
}
void EllipticCurveTest::test_repeated_doubling(){
ZpCoordinate P = ZpCoordinate::infinity();
while (P == ZpCoordinate::infinity())
P = random_curve.getPoint(gen.generate_modulu_p(random_curve.mod));
ZpCoordinate temp = P;
for (int m=1; m<10; m++){
temp = random_curve.doubling(temp);
CPPUNIT_ASSERT(temp == random_curve.repeatedDoubling(P,m));
}
}
void EllipticCurveTest::test_point_multiplication(){
ZpCoordinate P = ZpCoordinate::infinity();
while (P == ZpCoordinate::infinity())
P = random_curve.getPoint(gen.generate_modulu_p(random_curve.mod));
CPPUNIT_ASSERT(ZpCoordinate::infinity() == random_curve.pointMultiplication(P,0));
CPPUNIT_ASSERT(P == random_curve.pointMultiplication(P,1));
ZpCoordinate temp = random_curve.doubling(P);
CPPUNIT_ASSERT(temp == random_curve.pointMultiplication(P,2));
CPPUNIT_ASSERT(random_curve.addition(P,temp) == random_curve.pointMultiplication(P,3));
mpz_class goal = 2 + gen.rand(50);
for (int i=2; i< goal; i++)
temp = random_curve.addition(P,temp);
CPPUNIT_ASSERT(temp == random_curve.pointMultiplication(P,goal));
}
void EllipticCurveTest::test_check_order() {
CurveNISTp192 p192;
CPPUNIT_ASSERT(p192.check_order(p192.getOrder()));
CurveNISTp224 p224;
CPPUNIT_ASSERT(p224.check_order(p224.getOrder()));
CurveNISTp256 p256;
CPPUNIT_ASSERT(p256.check_order(p256.getOrder()));
CurveNISTp384 p384;
CPPUNIT_ASSERT(p384.check_order(p384.getOrder()));
CurveNISTp521 p521;
CPPUNIT_ASSERT(p521.check_order(p521.getOrder()));
}
void EllipticCurveTest::test_coordinate_compressed_form(){
ZpCoordinate P = random_curve.get_random_point();
string form = P.toCompressedForm();
ZpCoordinate Q = random_curve.getPointFromCompressedForm(form);
CPPUNIT_ASSERT(P == Q);
}
void PolynomialTest::setUp(){
p = gen.generate_prime(10);
for (int i=0; i<ROOTS_ARRAY_LENGTH; i++)
random_roots.push_back(gen.generate_modulu_p(p));
sort(random_roots.begin(), random_roots.end());
random_roots.erase(unique(random_roots.begin(), random_roots.end()),random_roots.end());
}
void PolynomialTest::tearDown(){
}
void PolynomialTest::test_input_output(){
#define S_ARRAY_LENGTH 5
string s_array[S_ARRAY_LENGTH] = {"1", "x", "x^7", "2x^2 + 3","x^5 + 17x + 543"};
for (int i=0; i< S_ARRAY_LENGTH; i++){
ModularPolynomial p(s_array[i], 100000);
CPPUNIT_ASSERT(s_array[i] == p.to_string());
}
}
void PolynomialTest::test_addition_substraction(){
CPPUNIT_ASSERT(ModularPolynomial("x",100) + ModularPolynomial("x",100) == ModularPolynomial("2x",100));
CPPUNIT_ASSERT(ModularPolynomial("x",100) + ModularPolynomial("1",100) == ModularPolynomial("x + 1",100));
CPPUNIT_ASSERT(ModularPolynomial("x^2",100) + ModularPolynomial("55",100) == ModularPolynomial("x^2 + 55",100));
CPPUNIT_ASSERT(ModularPolynomial("x^2 + 3x + 7",100) + ModularPolynomial("3x^2 + 5x + 12",100) == ModularPolynomial("4x^2 + 8x + 19",100));
CPPUNIT_ASSERT(ModularPolynomial("x^2",100) - ModularPolynomial("x^2",100) == ModularPolynomial("0",100));
CPPUNIT_ASSERT(ModularPolynomial("x^2",100) - ModularPolynomial("x",100) == ModularPolynomial("x^2 + 99x",100));
}
void PolynomialTest::test_multiplication(){
CPPUNIT_ASSERT(ModularPolynomial("x",100) * ModularPolynomial("x",100) == ModularPolynomial("x^2",100));
CPPUNIT_ASSERT(ModularPolynomial("1",100) * ModularPolynomial("x",100) == ModularPolynomial("x",100));
CPPUNIT_ASSERT(ModularPolynomial("x + 1",100) * ModularPolynomial("x",100) == ModularPolynomial("x^2 + x",100));
CPPUNIT_ASSERT(ModularPolynomial("x + 1",100) * ModularPolynomial("x + 1",100) == ModularPolynomial("x^2 + 2x + 1",100));
CPPUNIT_ASSERT(ModularPolynomial("0",113) * ModularPolynomial("0",113) == ModularPolynomial("0",113));
CPPUNIT_ASSERT((ModularPolynomial("x",113).modular_exponent(4,ModularPolynomial("x^2",113))) == ModularPolynomial("0",113));
CPPUNIT_ASSERT((ModularPolynomial("x^4 + 790*x^3 + 463*x^2 + 755*x + 641",821)*ModularPolynomial("x^4 + 790*x^3 + 463*x^2 + 755*x + 641",821)) == ModularPolynomial("x^8 + 759x^7 + 245x^6 + 718x^5 + 536x^4 + 125x^3 + 234x^2 + 772x + 381",821));
CPPUNIT_ASSERT((ModularPolynomial("x + 1",113).modular_exponent(2,ModularPolynomial("x^2",113))) == ModularPolynomial("2x + 1",113));
CPPUNIT_ASSERT((ModularPolynomial("x^2 + 3",113).modular_exponent(8,ModularPolynomial("x^3 + 5x",113))) == ModularPolynomial("18x^2 + 7",113));
CPPUNIT_ASSERT((ModularPolynomial("x^2 + 3",113).modular_exponent(17,ModularPolynomial("x^3 + 5x",113))) == ModularPolynomial("73x^2 + 34",113));
CPPUNIT_ASSERT((ModularPolynomial("x^2 + 3",113).modular_exponent(100,ModularPolynomial("x^3 + 5x",113))) == ModularPolynomial("80x^2 + 57",113));
CPPUNIT_ASSERT((ModularPolynomial("x^2 + 3",113).modular_exponent(1000,ModularPolynomial("x^3 + 5x",113))) == ModularPolynomial("100x^2 + 97",113));
CPPUNIT_ASSERT((ModularPolynomial("x^2 + 3",113).modular_exponent(10000,ModularPolynomial("x^3 + 5x",113))) == ModularPolynomial("25x^2 + 28",113));
CPPUNIT_ASSERT((ModularPolynomial("x^2 + 3",113).modular_exponent(100000,ModularPolynomial("x^3 + 5x",113))) == ModularPolynomial("23x^2 + 30",113));
CPPUNIT_ASSERT((ModularPolynomial("x^2 + 3",113).modular_exponent(1000000,ModularPolynomial("x^3 + 5x",113))) == ModularPolynomial("83x^2 + 106",113));
CPPUNIT_ASSERT((ModularPolynomial("x + 608",821).modular_exponent(410,ModularPolynomial("x^6 + 257x^5 + 812x^4 + 190x^3 + 280x^2 + 142x + 708",821))) == ModularPolynomial("784*x^5 + 656*x^4 + 109*x^3 + 502*x^2 + 482*x + 808",821));
}
void PolynomialTest::test_divisons(){
CPPUNIT_ASSERT(ModularPolynomial("x^2",113) / ModularPolynomial("x",113) == ModularPolynomial("x",113));
CPPUNIT_ASSERT(ModularPolynomial("x^2 + 3",113) / ModularPolynomial("x",113) == ModularPolynomial("x",113));
CPPUNIT_ASSERT(ModularPolynomial("2x^5",113) / ModularPolynomial("x^5",113) == ModularPolynomial("2",113));
CPPUNIT_ASSERT(ModularPolynomial("x^2 + x",100) % ModularPolynomial("x^2",100) == ModularPolynomial("x",100));
CPPUNIT_ASSERT(ModularPolynomial("x^2 + x",100) % ModularPolynomial("x",100) == ModularPolynomial("0",100));
CPPUNIT_ASSERT(ModularPolynomial("x^2 + 2x + 7",100) % ModularPolynomial("x + 1",100) == ModularPolynomial("6",100));
CPPUNIT_ASSERT(ModularPolynomial("x^2 + 2x + 7",100) % ModularPolynomial("x + 1",100) == ModularPolynomial("6",100));
CPPUNIT_ASSERT(ModularPolynomial("x^3 + 4x + 10",113) % ModularPolynomial("3x + 5",113) == ModularPolynomial("28",113));
CPPUNIT_ASSERT(ModularPolynomial("x^7 + 34x^5 + 15x^4 + 95x^3 + 17",113) % ModularPolynomial("3x^6 + 5x^3",113) == ModularPolynomial("34x^5 + 51x^4 + 95x^3 + 17",113));
CPPUNIT_ASSERT(ModularPolynomial("0",113) % ModularPolynomial("x",113) == ModularPolynomial("0",113));
CPPUNIT_ASSERT(ModularPolynomial("x^3 + 169x^2 + 256x + 118",503) % ModularPolynomial("x^2 + 329x + 406",503) == ModularPolynomial("178x + 191",503));
CPPUNIT_ASSERT(ModularPolynomial("x^3 + 169x^2 + 256x + 118",503) % ModularPolynomial("x^2 + 329x + 406",503) == ModularPolynomial("178x + 191",503));
CPPUNIT_ASSERT(gcd(ModularPolynomial("x",113),ModularPolynomial("x",113)) == ModularPolynomial("x",113));
CPPUNIT_ASSERT(gcd(ModularPolynomial("x^5 + 3x^2 + x",113),ModularPolynomial("3x^4 + 2x^3 + 17",113)) == ModularPolynomial("1",113));
CPPUNIT_ASSERT((ModularPolynomial("x^8 + 759x^7 + 245x^6 + 718x^5 + 536x^4 + 125x^3 + 234x^2 + 772x + 381",821) % ModularPolynomial("x^6 + 257x^5 + 812x^4 + 190x^3 + 280x^2 + 708",821)) == ModularPolynomial("214x^5 + 524x^4 + 198x^3 + 574x^2 + 28x + 263",821));
CPPUNIT_ASSERT(((ModularPolynomial("x^4 + 790*x^3 + 463*x^2 + 755*x + 641",821)*ModularPolynomial("x^4 + 790*x^3 + 463*x^2 + 755*x + 641",821)) % ModularPolynomial("x^6 + 257x^5 + 812x^4 + 190x^3 + 280x^2 + 708",821)) == ModularPolynomial("214x^5 + 524x^4 + 198x^3 + 574x^2 + 28x + 263",821));
}
void PolynomialTest::test_evaluations(){
// cout << ModularPolynomial("0",113)(4) << endl;
CPPUNIT_ASSERT(ModularPolynomial("0",113)(4) == 0);
CPPUNIT_ASSERT(ModularPolynomial("x",113)(4) == 4);
CPPUNIT_ASSERT(ModularPolynomial("x^2",113)(4) == 16);
CPPUNIT_ASSERT(ModularPolynomial("x^8",113)(4) == 109);
CPPUNIT_ASSERT(ModularPolynomial("x^8 + 7x^3 + 53",113)(4) == 45);
}
void PolynomialTest::test_root_finding(){
NumberArray roots;
roots = ModularPolynomial("x + 33",113).find_roots();
for (NumberArray::iterator i = roots.begin(); i<roots.end(); i++)
CPPUNIT_ASSERT(*i == 80);
roots = ModularPolynomial("x^2 - 1",113).find_roots();
for (NumberArray::iterator i = roots.begin(); i<roots.end(); i++)
CPPUNIT_ASSERT(*i == 1 || *i == 112);
ModularPolynomial p_x = ModularPolynomial::build_from_roots(random_roots,p);
roots = p_x.find_roots();
sort(roots.begin(), roots.end());
NumberArray::iterator i;
NumberArray::iterator j;
for (i = roots.begin(), j = random_roots.begin(); i< roots.end() || j<random_roots.end(); i++, j++)
CPPUNIT_ASSERT(*i == *j);
p_x = ModularPolynomial::build_hcp_from_discriminant(-31,2147483647);
roots = p_x.find_roots(); //to check if we get an infinite loop (had a bug that caused this once)
}
void ZpIntTest::setUp(){
for (int i=0; i<NUMBER_ARRAY_LENGTH; i++)
numbers[i] = gen.generate_modulu_p(gen.generate_prime(100));
}
void ZpIntTest::tearDown(){
}
void ZpIntTest::test_arithmetic(){
// zp_int a(0,100);
// zp_int b(1,100);
// cout << endl;
// cout << "a-b = " << a-b << endl;
CPPUNIT_ASSERT(zp_int(6,17)/2 == zp_int(3,17));
CPPUNIT_ASSERT(zp_int(-2,17) == zp_int(15,17));
for (int i=0; i<NUMBER_ARRAY_LENGTH; i++){
zp_int a = numbers[i];
zp_int zero = zp_int(0,0);
CPPUNIT_ASSERT(a == (a + a ) - a);
CPPUNIT_ASSERT(zero == (a - a ));
CPPUNIT_ASSERT(a*2 == (a + a ));
CPPUNIT_ASSERT(a*7 == (a*3 + a + a + a*2));
CPPUNIT_ASSERT(a*13 == (a*54 - a*41));
if (a != 0){
CPPUNIT_ASSERT(1 == (a / a));
CPPUNIT_ASSERT(2 == (a*2 / a));
}
CPPUNIT_ASSERT(a == (a^1));
CPPUNIT_ASSERT(1 == (a^0));
CPPUNIT_ASSERT(a*a*a == (a^3));
CPPUNIT_ASSERT(a == (a+a)/2);
}
}