Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
57 lines (47 sloc) 915 Bytes
package main
import (
"fmt"
"testing"
)
type test struct {
data []int
answer int
}
var calc_tests = []test{
{[]int{21, 31}, 52},
{[]int{-1, 0}, -1},
{[]int{3, 5}, 8},
}
func TestCalc_sum(t *testing.T) {
for _, v := range calc_tests {
x := calc_sum(v.data[0], v.data[1])
if x != v.answer {
t.Errorf("sum was incorrect. expected %v, got %v", v.answer, x)
}
}
}
func TestCalc_product(t *testing.T) {
total := calc_product(99, 99)
if total != 9801 {
t.Errorf("product calculation was incorrect. expected 9801, got %v", total)
}
}
func ExampleCalc_sum() {
fmt.Println(calc_sum(2, 3))
// Output:
// 5
}
func ExampleCalc_product() {
fmt.Println(calc_product(10, 10))
//Output: 100
}
func BenchmarkCalc_sum(b *testing.B) {
for i := 0; i < b.N; i++ {
calc_sum(50000, 100000)
}
}
func BenchmarkCalc_product(b *testing.B) {
for i := 0; i < b.N; i++ {
calc_product(1000, 999)
}
}