/
shape_test.go
69 lines (56 loc) · 1017 Bytes
/
shape_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
package main
import "testing"
type testpair struct {
x float64
y float64
r float64
perimeterC float64
}
var tests = []testpair{
{ -1,-1,-5,-1 },
{ 0, 0,0,0 },
{ 1, 1,1, 6.283185307179586 },
{ 6, 8 , 24, 150.79644737231007},
}
//for rectangle
type testpair1 struct {
x1 float64
y1 float64
x2 float64
y2 float64
perimeterR float64
}
var testsRectanglePerimeter = []testpair1{
{ -1,-2,-3,-4,8},
{ 0, 0,0,0,-1 },
{ 1, 2,1,9,-1 },
{ 2, 6,5,6,-1 },
{ 4, 6, 10,12,24 },
{ 24, 2, 4, 30, 96},
}
func TestPerimeter(t *testing.T) {
//Testing for circle
for _, pair := range tests {
c := Circle{pair.x,pair.y,pair.r}
v := c.perimeter()
if v != pair.perimeterC {
t.Error(
"For", pair.x, pair.y,pair.r,
"expected", pair.perimeterC,
"got", v,
)
}
}
//Testing for rectangle
for _, pair1 := range testsRectanglePerimeter {
r := Rectangle{pair1.x1,pair1.y1,pair1.x2,pair1.y2}
v := r.perimeter()
if v != pair1.perimeterR {
t.Error(
"For", pair1.x1,pair1.y1,pair1.x2,pair1.y2,
"expected", pair1.perimeterR,
"got", v,
)
}
}
}