Debian Codegraph @

mathutils_test.go

raw
1 package tensor
2
3 import (
4 "testing"
5
6 "github.com/stretchr/testify/assert"
7 )
8
9 func TestDivmod(t *testing.T) {
10 as := []int{0, 1, 2, 3, 4, 5}
11 bs := []int{1, 2, 3, 3, 2, 3}
12 qs := []int{0, 0, 0, 1, 2, 1}
13 rs := []int{0, 1, 2, 0, 0, 2}
14
15 for i, a := range as {
16 b := bs[i]
17 eq := qs[i]
18 er := rs[i]
19
20 q, r := divmod(a, b)
21 if q != eq {
22 t.Errorf("Expected %d / %d to equal %d. Got %d instead", a, b, eq, q)
23 }
24 if r != er {
25 t.Errorf("Expected %d %% %d to equal %d. Got %d instead", a, b, er, r)
26 }
27 }
28
29 assert := assert.New(t)
30 fail := func() {
31 divmod(1, 0)
32 }
33 assert.Panics(fail)
34 }