func TestAddition(t *testing.T) { result := add(2, 3) expected := 5 if result != expected { t.Fatalf("Expected %d but got %d", expected, result) } }
func TestDivision(t *testing.T) { divisor := 0 _, err := divide(10, divisor) if err == nil { t.Fatalf("Expected to get an error") } }This code tests a "divide" function by passing it two numbers and checking for an error if the divisor is 0. If there is no error, TB Fatalf will log an error message and stop the test. In both examples, the package library is "testing," which is part of the Go standard library.