-
Notifications
You must be signed in to change notification settings - Fork 0
/
polynomial_test.go
44 lines (35 loc) · 1003 Bytes
/
polynomial_test.go
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
package tcrsa
import (
"math/big"
"testing"
)
const polynomialTestDegree = 3
// Tests the degree of the polynomial created is equal to the argument provided.
func TestPolynomial(t *testing.T) {
p := newPolynomial(polynomialTestDegree)
if p.getDegree() != polynomialTestDegree {
t.Errorf("degree of polynomial is not the provided")
}
}
func TestCreateRandomPolynomial(t *testing.T) {
p, err := createRandomPolynomial(polynomialTestDegree, big.NewInt(10), big.NewInt(1024))
if err != nil {
t.Errorf("could not create a random polynomial")
return
}
if p.getDegree() != polynomialTestDegree {
t.Errorf("degree of polynomial is not the provided")
}
}
func TestPolynomial_Eval(t *testing.T) {
p := newPolynomial(polynomialTestDegree)
p[3] = big.NewInt(7)
p[2] = big.NewInt(5)
p[1] = big.NewInt(9)
p[0] = big.NewInt(1)
expected := big.NewInt(7591)
res := p.eval(big.NewInt(10))
if expected.Cmp(res) != 0 {
t.Errorf("The evaluations is not providing a correct result")
}
}