peckertest/internal/internal_test.go

52 lines
998 B
Go
Raw Normal View History

2022-01-10 12:02:45 +00:00
package internal_test
import (
"fmt"
"testing"
"git.t-juice.club/torjus/peckertest/internal"
)
func TestAdd(t *testing.T) {
var tc = []struct {
A int
B int
Expected int
}{
{A: 1, B: 0, Expected: 1},
{A: 1, B: 1, Expected: 2},
{A: 1, B: -1, Expected: 0},
}
for _, test := range tc {
name := fmt.Sprintf("%d+%d", test.A, test.B)
t.Run(name, func(t *testing.T) {
result := internal.Add(test.A, test.B)
if result != test.Expected {
t.Errorf("Got %d, expected %d", result, test.Expected)
}
})
}
}
2022-01-10 12:12:13 +00:00
func TestSub(t *testing.T) {
var tc = []struct {
A int
B int
Expected int
}{
{A: 1, B: 0, Expected: 1},
{A: 1, B: 1, Expected: 0},
{A: 0, B: -5, Expected: -5},
}
for _, test := range tc {
name := fmt.Sprintf("%d-%d", test.A, test.B)
t.Run(name, func(t *testing.T) {
result := internal.Sub(test.A, test.B)
if result != test.Expected {
t.Errorf("Got %d, expected %d", result, test.Expected)
}
})
}
}