-
Notifications
You must be signed in to change notification settings - Fork 0
/
examples_test.go
57 lines (46 loc) · 1.2 KB
/
examples_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
package gotest
import (
"testing"
)
type Calculator interface {
Add(int, int) int
Subtract(int, int) int
IsGreaterThan(int, int) bool
}
type calculator struct{}
func (sut *calculator) Add(lhs int, rhs int) int {
return lhs + rhs
}
func (sut *calculator) Subtract(lhs int, rhs int) int {
return lhs - rhs
}
func (sut *calculator) IsGreaterThan(lhs int, rhs int) bool {
return lhs > rhs
}
func CreateCalculator() Calculator {
return &calculator{}
}
func Test_ShouldAddTwoNumbers(t *testing.T) {
calc := CreateCalculator()
I := Expec(t)
I.Expect(calc.Add(1, 1)).ToBe(2)
I.Expect(calc.Add(1, 2)).ToBe(3)
I.Expect(calc.Add(2, 2)).ToBe(4)
I.Expect(calc.Add(-1, -1)).ToBe(-2)
I.Expect(calc.Add(-1, 1)).ToBe(0)
}
func Test_ShouldCompareTwoNumbers(t *testing.T) {
calc := CreateCalculator()
I := Expec(t)
I.Expect(calc.IsGreaterThan(2, 1)).As("2 > 1").ToBe(true)
I.Expect(calc.IsGreaterThan(1, 2)).As("1 > 2").ToBe(false)
}
func Test_ShouldSubtractTwoNumbers(t *testing.T) {
sut := CreateCalculator()
I := Expec(t)
I.Expect(sut.Subtract(1, 2)).ToBe(-1).
Expect(sut.Subtract(1, 2)).ToBe(-1).
Expect(sut.Subtract(2, 2)).ToBe(0).
Expect(sut.Subtract(1, 0)).ToBe(1).
Expect(sut.Subtract(0, 1)).ToBe(-1)
}