-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtests.c
101 lines (81 loc) · 2.2 KB
/
tests.c
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
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include "sprp64.h"
#include "sprp32.h"
#include "myrand.h"
int test_modular_inverse64()
{
uint64_t a;
int i;
for (a=3; a < 5000000; a+=2) {
uint64_t received = modular_inverse64(a);
int64_t received_minus_one = received * a;
if (received_minus_one != -1) {
printf("expected: -1, received: %" PRIu64 ", argument: %" PRIu64 "\n", received_minus_one, a);
return 1;
}
}
for (a = UINT64_MAX; a > UINT64_MAX - 5000000; a -= 2) {
uint64_t received = modular_inverse64(a);
int64_t received_minus_one = received * a;
if (received_minus_one != -1) {
printf("expected: -1, received: %" PRIu64 ", argument: %" PRIu64 "\n", received_minus_one, a);
return 1;
}
}
myseed();
for (i=0; i < 5000000; i++) {
a = myrand64() | 1;
uint64_t received = modular_inverse64(a);
int64_t received_minus_one = received * a;
if (received_minus_one != -1) {
printf("expected: -1, received: %" PRIu64 ", argument: %" PRIu64 "\n", received_minus_one, a);
return 1;
}
}
return 0;
}
int test_modular_inverse32()
{
uint32_t a;
int i;
for (a = 3; a < 5000000; a += 2) {
uint32_t received = modular_inverse32(a);
int32_t received_minus_one = received * a;
if (received_minus_one != -1) {
printf("expected: -1, received: %" PRIu32 ", argument: %" PRIu32 "\n", received_minus_one, a);
return 1;
}
}
for (a = UINT32_MAX; a > UINT32_MAX - 5000000; a -= 2) {
uint32_t received = modular_inverse32(a);
int32_t received_minus_one = received * a;
if (received_minus_one != -1) {
printf("expected: -1, received: %" PRIu32 ", argument: %" PRIu32 "\n", received_minus_one, a);
return 1;
}
}
myseed();
for (i=0; i < 5000000; i++) {
a = myrand32() | 1;
uint32_t received = modular_inverse32(a);
int32_t received_minus_one = received * a;
if (received_minus_one != -1) {
printf("expected: -1, received: %" PRIu32 ", argument: %" PRIu32 "\n", received_minus_one, a);
return 1;
}
}
return 0;
}
int main()
{
int res = test_modular_inverse64();
res |= test_modular_inverse32();
if (res == 0) {
printf("All tests completed successfully - no errors.\n");
} else {
printf("Error running tests.\n");
}
return res;
}