-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtriangle_test.go
69 lines (50 loc) · 1.4 KB
/
triangle_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
// +build unit
package main
import (
"testing"
)
func triangleTestValidation(sides []float64, expectedType string, t *testing.T) {
triangleType, err := CategorizeTriangle(sides)
if err != nil {
t.Error(err.Error())
}
if triangleType != expectedType {
t.Fatalf("Triangle Type != Expected Type (%s != %s)", triangleType, expectedType)
}
}
func TestNotTriangle(t *testing.T) {
sides := []float64{10, 15.5, 25.5}
if ValidateTriangle(sides) {
t.Fatalf("This is not a triangle: (sides: %+v)", sides)
}
}
func TestTriangle(t *testing.T) {
sides := []float64{10, 15.5, 24.5}
if !ValidateTriangle(sides) {
t.Fatalf("This is a triangle (sides: %+v)", sides)
}
}
func TestEquilateral(t *testing.T) {
sides := []float64{125.3, 125.3, 125.3}
expectedType := `equilateral`
triangleTestValidation(sides, expectedType, t)
}
func TestIsoscales(t *testing.T) {
sides := []float64{125.3, 125.3, 233.334345}
expectedType := `isosceles`
triangleTestValidation(sides, expectedType, t)
}
func TestScalene(t *testing.T) {
sides := []float64{115.7, 125.3, 233.334345}
expectedType := `scalene`
triangleTestValidation(sides, expectedType, t)
}
func TestErrorCategorization(t *testing.T) {
sides := []float64{115.7, 125.3, 233.334345, 233.334345}
_, err := CategorizeTriangle(sides)
if err != nil {
t.Log(err.Error())
} else {
t.Errorf("There should be an ERROR because it is not triangle (%+v)", sides)
}
}