-
Notifications
You must be signed in to change notification settings - Fork 1
/
calc_test.go
116 lines (109 loc) · 2.15 KB
/
calc_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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package polygo
import (
"testing"
"github.com/stretchr/testify/assert"
)
func Test_PolyDerivative(t *testing.T) {
testCases := []struct {
name string
arg Poly
want Poly
}{
{
name: "zero",
arg: NewPolyZero(),
want: NewPolyZero(),
},
{
name: "nonzero const",
arg: NewPoly([]float64{3.1415}),
want: NewPolyZero(),
},
{
name: "linear",
arg: NewPoly([]float64{125124, 125123}),
want: NewPoly([]float64{125124}),
},
{
name: "quadratic",
arg: NewPoly([]float64{47346346, 734334, 2342366}),
want: NewPoly([]float64{47346346 * 2, 734334}),
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
got := tc.arg.Derivative()
assert.Equal(t, tc.want, got)
})
}
}
func Test_PolyDerivativeN(t *testing.T) {
testCases := []struct {
name string
argP Poly
argN int
want Poly
}{
{
name: "zero",
argP: NewPolyZero(),
argN: 1,
want: NewPolyZero(),
},
{
name: "nonzero const",
argP: NewPoly([]float64{3.1415}),
argN: 1,
want: NewPolyZero(),
},
{
name: "linear",
argP: NewPoly([]float64{125124, 125123}),
argN: 1,
want: NewPoly([]float64{125124}),
},
{
name: "quadratic",
argP: NewPoly([]float64{47346346, 734334, 2342366}),
argN: 1,
want: NewPoly([]float64{47346346 * 2, 734334}),
},
{
name: "negative n zero",
argP: NewPolyZero(),
argN: -2,
want: NewPolyZero(),
},
{
name: "negative n quadratic",
argP: NewPoly([]float64{47346346, 734334, 2342366}),
argN: -2,
want: NewPoly([]float64{47346346, 734334, 2342366}),
},
{
name: "n = deg + 1 quadratic",
argP: NewPoly([]float64{47346346, 734334, 2342366}),
argN: 3,
want: NewPolyZero(),
},
{
name: "n = deg quadratic",
argP: NewPoly([]float64{47346346, 734334, 2342366}),
argN: 2,
want: NewPolyConst(47346346 * 2),
},
{
name: "n = big quadratic",
argP: NewPoly([]float64{47346346, 734334, 2342366}),
argN: 100000000000000000,
want: NewPolyZero(),
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
got := tc.argP.DerivativeN(tc.argN)
t.Log(got)
assert.Equal(t, tc.want, got)
})
}
}