blob: 536b0599320263e3324f4312070bbd462651bfd7 (
plain)
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
|
module Fp = Plonkers.Fp
let fp = Testable.make Fp.to_string Fp.equal
let f = Fp.of_string
let test_add () =
Alcotest.(check fp)
"equals"
(f
"5034212870056682811541563993093442956024207074167934414259669251040086104221")
(Fp.add
(f
"3019612232293951348432769707427639303474751231631017441050730061639747788964")
(f
"2014600637762731463108794285665803652549455842536916973208939189400338315257"));
Alcotest.(check fp)
"equals" Fp.zero
(Fp.add
(f
"21888242871839275222246405745257275088696311157297823662689037894645226208582")
Fp.one);
Alcotest.(check fp)
"equals"
(f
"7363893478117210948657131929839491162862302555393162961985689652909776739235")
(Fp.add
(f
"7363893478117210948657131929839491162862302555393162961985689652909776739235")
Fp.zero)
let test_sub () =
Alcotest.(check fp)
"equals"
(f
"1647997538064335793847192302859723563372189463772006638527106196094592175035")
(Fp.sub
(f
"17522329235179667504196475280824254606128390327458085261948007699233694805172")
(f
"15874331697115331710349282977964531042756200863686078623420901503139102630137"));
Alcotest.(check fp)
"equals"
(f
"21888242871839275222246405745257275088696311157297823662689037894645226208582")
(Fp.sub Fp.zero Fp.one);
Alcotest.(check fp)
"equals"
(f
"1550460075629904631277637708383660261580971272511193857451434052003108082807")
(Fp.add
(f
"1550460075629904631277637708383660261580971272511193857451434052003108082807")
Fp.zero)
let test_mul () =
Alcotest.(check fp)
"equals"
(f
"20539703399960180369319660518633290048071922000666914740466234074847854697757")
(Fp.mul
(f
"16652515618518207323315643285221741056245295412987863357779458647516886387587")
(f
"15388577223719168739739036375931130294575142146897880107473273404618844312776"));
Alcotest.(check fp)
"equals" Fp.zero
(Fp.mul
(f
"10935302729977221140784701859408855206669147633587285404353277660075789680922")
Fp.zero)
let test_div () =
Alcotest.(check fp)
"equals"
(f
"7363953525538778156567393633860492517850968441297156550375719598579598367322")
(Fp.div
(f
"7363953525538778156567393633860492517850968441297156550375719598579598367322")
Fp.one)
let test_inv () =
Alcotest.(check fp)
"equals"
(f
"14812345552713361047837749161990489217154524375614120373819285291721752372748")
(Fp.inv
(f
"1160181877204925047836599448201084379181489517022839288462621953652233427695"));
Alcotest.(check fp)
"equals" Fp.one
(let a =
f
"17876831255806984619368587498426968568242044248616647019388897055879503636463"
in
Fp.mul a (Fp.inv a))
let tests =
Alcotest.
[
test_case "Addition" `Quick test_add;
test_case "Subtraction" `Quick test_sub;
test_case "Multiplication" `Quick test_mul;
test_case "Division" `Quick test_mul;
test_case "Multiplicative Inverse" `Quick test_inv;
]
|