Golang test

package main

import "testing"

func calcTriangle(a, b int32) int32 {
    return a + b
}

func TestTriangle(t *testing.T) {
    tests := []struct {
        a, b, c int32
    }{
        {3, 4, 7},
        {3, 4, 10},
        {11, 4, 11},
    }

    for _, tt := range tests {
        if actual := calcTriangle(tt.a, tt.b); actual != tt.c {
            t.Errorf("calc Triangle(%d,%d,%d)", tt.a, tt.b, tt.c)
        }
    }
}

添加新评论