Add some basic tests for doArithmetic

We might have to take precision into account for floating point nubers ... at some point.
This commit is contained in:
bep 2015-03-11 01:29:18 +01:00
parent b9b70fb6b0
commit 43742e0277

View file

@ -107,6 +107,42 @@ func doTestCompare(t *testing.T, tp tstCompareType, funcUnderTest func(a, b inte
} }
} }
func TestArethmic(t *testing.T) {
for i, this := range []struct {
a interface{}
b interface{}
op rune
expect interface{}
}{
{1, 2, '+', int64(3)},
{1, 2, '-', int64(-1)},
{2, 2, '*', int64(4)},
{4, 2, '/', int64(2)},
{uint8(1), uint8(3), '+', uint64(4)},
{uint8(3), uint8(2), '-', uint64(1)},
{uint8(2), uint8(2), '*', uint64(4)},
{uint16(4), uint8(2), '/', uint64(2)},
{4, 2, '¤', false},
} {
// TODO(bep): Take precision into account.
result, err := doArithmetic(this.a, this.b, this.op)
if b, ok := this.expect.(bool); ok && !b {
if err == nil {
t.Errorf("[%d] doArethmic didn't return an expected error", i)
}
} else {
if err != nil {
t.Errorf("[%d] failed: %s", i, err)
continue
}
if !reflect.DeepEqual(result, this.expect) {
t.Errorf("[%d] doArethmic got %v (%T) but expected %v (%T)", i, result, result, this.expect, this.expect)
}
}
}
}
func TestMod(t *testing.T) { func TestMod(t *testing.T) {
for i, this := range []struct { for i, this := range []struct {
a interface{} a interface{}