mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
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:
parent
b9b70fb6b0
commit
43742e0277
1 changed files with 36 additions and 0 deletions
|
@ -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) {
|
||||
for i, this := range []struct {
|
||||
a interface{}
|
||||
|
|
Loading…
Reference in a new issue