func add(x, y int) int { return x + y } func TestAdd(t *testing.T) { result := add(2, 3) if result != 5 { t.Fail() } }
func concat(s1, s2 string) string { return s1 + s2 } func TestConcat(t *testing.T) { result := concat("hello", "world") if result != "helloworld" { t.Fail() } }This code defines a "concat" function that takes two strings as its input and returns their concatenation. It then defines a test function that calls the "concat" function with the inputs "hello" and "world" and checks whether the result is equal to "helloworld". If the result is not equal to "helloworld", the test function calls "T Fail" to signal that the test has failed. Both of these examples use the "testing" package's "T" type, which represents a testing function's "testing.T" object. "T Fail" is a method on this object that signals that the current test has failed.