Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
test_groups.cpp File Reference
Include dependency graph for test_groups.cpp:

Go to the source code of this file.

Functions

template<typename GroupT >
void test_mixed_add ()
 
template<typename GroupT >
void test_group ()
 
template<typename GroupT >
void test_mul_by_q ()
 
template<typename GroupT >
void test_output ()
 
int main (void)
 

Function Documentation

◆ main()

int main ( void )

Definition at line 140 of file test_groups.cpp.

141{
148
155
162
169
170#ifdef CURVE_BN128 // BN128 has fancy dependencies so it may be disabled
176#endif
177}
static void init_public_params()
static void init_public_params()
Definition bn128_pp.cpp:13
static void init_public_params()
static void init_public_params()
Definition mnt4_pp.cpp:18
static void init_public_params()
Definition mnt6_pp.cpp:18
void test_group()
void test_output()
void test_mul_by_q()
Here is the call graph for this function:

◆ test_group()

template<typename GroupT >
void test_group ( )

Definition at line 58 of file test_groups.cpp.

59{
60 bigint<1> rand1 = bigint<1>("76749407");
61 bigint<1> rand2 = bigint<1>("44410867");
62 bigint<1> randsum = bigint<1>("121160274");
63
64 GroupT zero = GroupT::zero();
65 assert(zero == zero);
66 GroupT one = GroupT::one();
67 assert(one == one);
68 GroupT two = bigint<1>(2l) * GroupT::one();
69 assert(two == two);
70 GroupT five = bigint<1>(5l) * GroupT::one();
71
72 GroupT three = bigint<1>(3l) * GroupT::one();
73 GroupT four = bigint<1>(4l) * GroupT::one();
74
75 assert(two+five == three+four);
76
77 GroupT a = GroupT::random_element();
78 GroupT b = GroupT::random_element();
79
80 assert(one != zero);
81 assert(a != zero);
82 assert(a != one);
83
84 assert(b != zero);
85 assert(b != one);
86
87 assert(a.dbl() == a + a);
88 assert(b.dbl() == b + b);
89 assert(one.add(two) == three);
90 assert(two.add(one) == three);
91 assert(a + b == b + a);
92 assert(a - a == zero);
93 assert(a - b == a + (-b));
94 assert(a - b == (-b) + a);
95
96 // handle special cases
97 assert(zero + (-a) == -a);
98 assert(zero - a == -a);
99 assert(a - zero == a);
100 assert(a + zero == a);
101 assert(zero + a == a);
102
103 assert((a + b).dbl() == (a + b) + (b + a));
104 assert(bigint<1>("2") * (a + b) == (a + b) + (b + a));
105
106 assert((rand1 * a) + (rand2 * a) == (randsum * a));
107
108 assert(GroupT::order() * a == zero);
109 assert(GroupT::order() * one == zero);
110 assert((GroupT::order() * a) - a != zero);
111 assert((GroupT::order() * one) - one != zero);
112
114}
std::string one()
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181
void test_mixed_add()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_mixed_add()

template<typename GroupT >
void test_mixed_add ( )

Definition at line 22 of file test_groups.cpp.

23{
24 GroupT base, el, result;
25
26 base = GroupT::zero();
27 el = GroupT::zero();
28 el.to_special();
29 result = base.mixed_add(el);
30 assert(result == base + el);
31
32 base = GroupT::zero();
33 el = GroupT::random_element();
34 el.to_special();
35 result = base.mixed_add(el);
36 assert(result == base + el);
37
38 base = GroupT::random_element();
39 el = GroupT::zero();
40 el.to_special();
41 result = base.mixed_add(el);
42 assert(result == base + el);
43
44 base = GroupT::random_element();
45 el = GroupT::random_element();
46 el.to_special();
47 result = base.mixed_add(el);
48 assert(result == base + el);
49
50 base = GroupT::random_element();
51 el = base;
52 el.to_special();
53 result = base.mixed_add(el);
54 assert(result == base.dbl());
55}
Here is the caller graph for this function:

◆ test_mul_by_q()

template<typename GroupT >
void test_mul_by_q ( )

Definition at line 117 of file test_groups.cpp.

118{
119 GroupT a = GroupT::random_element();
120 assert((GroupT::base_field_char()*a) == a.mul_by_q());
121}
Here is the caller graph for this function:

◆ test_output()

template<typename GroupT >
void test_output ( )

Definition at line 124 of file test_groups.cpp.

125{
126 GroupT g = GroupT::zero();
127
128 for (size_t i = 0; i < 1000; ++i)
129 {
130 std::stringstream ss;
131 ss << g;
132 GroupT gg;
133 ss >> gg;
134 assert(g == gg);
135 /* use a random point in next iteration */
136 g = GroupT::random_element();
137 }
138}
static const Segment ss(Segment::ss)
Here is the caller graph for this function: