| 1 | package build |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | func TestUnion(t *testing.T) { |
| 9 | res := Empty(0).Union(Empty(0)) |
| 10 | exp := "0 []" |
| 11 | if mess, diff := diff(res.String(), exp); diff { |
| 12 | t.Errorf("Union %s", mess) |
| 13 | } |
| 14 | Consistent("Union", t, res) |
| 15 | |
| 16 | res = Empty(0).AddCost(4).Union(Grid(1, 2).AddCost(5)) |
| 17 | exp = "2 [{0 1}]" |
| 18 | if mess, diff := diff(res.String(), exp); diff { |
| 19 | t.Errorf("Union %s", mess) |
| 20 | } |
| 21 | Consistent("Union", t, res) |
| 22 | |
| 23 | res = Grid(1, 2).AddCost(4).Union(Grid(1, 2).AddCost(5)) |
| 24 | exp = "2 [{0 1}]" |
| 25 | if mess, diff := diff(res.String(), exp); diff { |
| 26 | t.Errorf("Union %s", mess) |
| 27 | } |
| 28 | Consistent("Union", t, res) |
| 29 | |
| 30 | res = Grid(2, 2).Union(Kn(3).AddCost(8)) |
| 31 | exp = "4 [{0 1} {0 2} {1 2} {1 3} {2 3}]" |
| 32 | if mess, diff := diff(res.String(), exp); diff { |
| 33 | t.Errorf("Union %s", mess) |
| 34 | } |
| 35 | Consistent("Union", t, res) |
| 36 | |
| 37 | res = Kn(3).Union(Grid(2, 2)) |
| 38 | exp = "4 [{0 1} {0 2} {1 2} {1 3} {2 3}]" |
| 39 | if mess, diff := diff(res.String(), exp); diff { |
| 40 | t.Errorf("Union %s", mess) |
| 41 | } |
| 42 | Consistent("Union", t, res) |
| 43 | |
| 44 | for m := 0; m < 5; m++ { |
| 45 | for n := 0; n < 5; n++ { |
| 46 | res = Kn(m).Union(Kn(n)) |
| 47 | mess := fmt.Sprintf("Kn(%d).Union(Kn(%d))", m, n) |
| 48 | Consistent(mess, t, res) |
| 49 | |
| 50 | res = Grid(m, n).Union(Kn(n)) |
| 51 | mess = fmt.Sprintf("Grid(%d,%d).Union(Kn(%d))", m, n, n) |
| 52 | Consistent(mess, t, res) |
| 53 | res = Kn(n).Union(Grid(m, n)) |
| 54 | mess = fmt.Sprintf("Kn(%d).Union(Grid(%d,%d))", n, m, n) |
| 55 | Consistent(mess, t, res) |
| 56 | |
| 57 | km := Kn(m).Keep(func(v, w int) bool { |
| 58 | return v != m-1 && w != m-1 |
| 59 | }) |
| 60 | res = km.Union(Kn(n)) |
| 61 | mess = fmt.Sprintf("Kn(%d)-{m-1}.Union(Kn(%d))", m, n) |
| 62 | Consistent(mess, t, res) |
| 63 | } |
| 64 | } |
| 65 | } |