This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
polynomial_test.go
89 lines (71 loc) · 1.58 KB
/
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
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
package sss
import (
"bytes"
"testing"
)
var (
p = []byte{1, 0, 2, 3}
p2 = []byte{70, 32, 6}
)
func TestDegree(t *testing.T) {
if v, want := degree(p), 3; v != want {
t.Errorf("Was %v, but expected %v", v, want)
}
}
func TestEval(t *testing.T) {
if v, want := eval(p, 2), byte(17); v != want {
t.Errorf("Was %v, but expected %v", v, want)
}
}
func TestGenerate(t *testing.T) {
b := []byte{1, 2, 3}
expected := []byte{10, 1, 2, 3}
actual, err := generate(3, 10, bytes.NewReader(b))
if err != nil {
t.Error(err)
}
if !bytes.Equal(actual, expected) {
t.Errorf("Was %v, but expected %v", actual, expected)
}
}
func TestGenerateEOF(t *testing.T) {
b := []byte{1}
p, err := generate(3, 10, bytes.NewReader(b))
if p != nil {
t.Errorf("Was %v, but expected an error", p)
}
if err == nil {
t.Error("No error returned")
}
}
func TestGeneratePolyEOFFullSize(t *testing.T) {
b := []byte{1, 2, 0, 0, 0, 0}
p, err := generate(3, 10, bytes.NewReader(b))
if p != nil {
t.Errorf("Was %v, but xpected an error", p)
}
if err == nil {
t.Error("No error returned")
}
}
func TestGenerateFullSize(t *testing.T) {
b := []byte{1, 2, 0, 4}
expected := []byte{10, 1, 2, 4}
actual, err := generate(3, 10, bytes.NewReader(b))
if err != nil {
t.Error(err)
}
if !bytes.Equal(actual, expected) {
t.Errorf("Was %v but expected %v", actual, expected)
}
}
func TestInterpolate(t *testing.T) {
in := []pair{
pair{x: 1, y: 1},
pair{x: 2, y: 2},
pair{x: 3, y: 3},
}
if v, want := interpolate(in, 0), byte(0); v != want {
t.Errorf("Was %v, but expected %v", v, want)
}
}