learndrone/main_test.go
2025-05-30 01:09:08 +02:00

40 lines
610 B
Go

package main
import (
"testing"
)
func Test_sum(t *testing.T) {
tests := []struct {
a, b int
want int
}{
{1, 2, 3},
{-1, 1, 0},
{0, 0, 0},
}
for _, test := range tests {
if got := sum(test.a, test.b); got != test.want {
t.Errorf("sum(%d, %d) = %d, want %d", test.a, test.b, got, test.want)
}
}
}
func Test_sub(t *testing.T) {
tests := []struct {
a, b int
want int
}{
{1, 2, -1},
{-1, 1, -2},
{0, 0, 0},
}
for _, test := range tests {
if got := sub(test.a, test.b); got != test.want {
t.Errorf("sub(%d, %d) = %d, want %d", test.a, test.b, got, test.want)
}
}
}