File: cartesian_test.go

package info (click to toggle)
golang-github-yourbasic-graph 1.0.5-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 400 kB
  • sloc: makefile: 2
file content (48 lines) | stat: -rw-r--r-- 1,310 bytes parent folder | download | duplicates (2)
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package build

import "testing"

func TestCartesian(t *testing.T) {
	res := Empty(2).Cartesian(Grid(1, 2))
	exp := "4 [{0 1} {2 3}]"
	if mess, diff := diff(res.String(), exp); diff {
		t.Errorf("Cartesian %s", mess)
	}
	Consistent("Cartesian1", t, res)

	res = Kn(1).Cartesian(Grid(1, 2))
	exp = "2 [{0 1}]"
	if mess, diff := diff(res.String(), exp); diff {
		t.Errorf("Cartesian %s", mess)
	}
	Consistent("Cartesian2", t, res)

	res = Grid(1, 2).Cartesian(Grid(1, 2))
	exp = "4 [{0 1} {0 2} {1 3} {2 3}]"
	if mess, diff := diff(res.String(), exp); diff {
		t.Errorf("Cartesian %s", mess)
	}
	Consistent("Cartesian3", t, res)

	res = Grid(1, 3).Cartesian(Grid(1, 3))
	exp = "9 [{0 1} {0 3} {1 2} {1 4} {2 5} {3 4} {3 6} {4 5} {4 7} {5 8} {6 7} {7 8}]"
	if mess, diff := diff(res.String(), exp); diff {
		t.Errorf("Cartesian %s", mess)
	}
	Consistent("Cartesian4", t, res)

	res = Kn(2).Cartesian(Grid(1, 2))
	exp = "4 [{0 1} {0 2} {1 3} {2 3}]"
	if mess, diff := diff(res.String(), exp); diff {
		t.Errorf("Cartesian %s", mess)
	}
	Consistent("Cartesian5", t, res)

	for m := 0; m < 4; m++ {
		for n := 0; n < 4; n++ {
			Consistent("Cartesian6", t, Kn(m).Cartesian(Cycle(n)))
			Consistent("Cartesian7", t, Kn(m).Cartesian(Grid(m, m+n)))
			Consistent("Cartesian8", t, Grid(m, m+n).Cartesian(Kn(m)))
		}
	}
}