2025-11-10 12:27:02 +07:00

42 lines
759 B
Go

package operator
import "testing"
func TestAdd(t *testing.T) {
got := Add(2, 3)
if got != 5 {
t.Fatalf("Add(2,3) = %d; want 5", got)
}
}
func TestSub(t *testing.T) {
got := Sub(5, 3)
if got != 2 {
t.Fatalf("Sub(5,3) = %d; want 2", got)
}
}
func TestMul(t *testing.T) {
got := Mul(4, 3)
if got != 12 {
t.Fatalf("Mul(4,3) = %d; want 12", got)
}
}
func TestDiv(t *testing.T) {
got, err := Div(7, 2)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if got != 3.5 {
t.Fatalf("Div(7,2) = %v; want 3.5", got)
}
}
func TestDivByZero(t *testing.T) {
_, err := Div(1, 0)
if err == nil {
t.Fatalf("expected error when dividing by zero")
}
}