File: mathutils_test.go

package info (click to toggle)
golang-github-gorgonia-tensor 0.9.24-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,696 kB
  • sloc: sh: 18; asm: 18; makefile: 8
file content (34 lines) | stat: -rw-r--r-- 597 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package tensor

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestDivmod(t *testing.T) {
	as := []int{0, 1, 2, 3, 4, 5}
	bs := []int{1, 2, 3, 3, 2, 3}
	qs := []int{0, 0, 0, 1, 2, 1}
	rs := []int{0, 1, 2, 0, 0, 2}

	for i, a := range as {
		b := bs[i]
		eq := qs[i]
		er := rs[i]

		q, r := divmod(a, b)
		if q != eq {
			t.Errorf("Expected %d / %d to equal %d. Got %d instead", a, b, eq, q)
		}
		if r != er {
			t.Errorf("Expected %d %% %d to equal %d. Got %d instead", a, b, er, r)
		}
	}

	assert := assert.New(t)
	fail := func() {
		divmod(1, 0)
	}
	assert.Panics(fail)
}