-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrid_test.go
50 lines (46 loc) · 1.64 KB
/
grid_test.go
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
49
50
// Copyright 2021 Frederik Zipp. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package pps
import "testing"
func TestGridCellAdd(t *testing.T) {
tests := []struct {
c gridCell
x, y int
want gridCell
}{
{c: gridCell{x: 3, y: 4}, x: 0, y: 0, want: gridCell{x: 3, y: 4}},
{c: gridCell{x: 3, y: 4}, x: 1, y: 1, want: gridCell{x: 4, y: 5}},
{c: gridCell{x: 3, y: 4}, x: -1, y: 0, want: gridCell{x: 2, y: 4}},
{c: gridCell{x: 3, y: 4}, x: -1, y: -1, want: gridCell{x: 2, y: 3}},
{c: gridCell{x: 6, y: 5}, x: 1, y: -1, want: gridCell{x: 7, y: 4}},
}
for _, tt := range tests {
got := tt.c.add(tt.x, tt.y)
if got != tt.want {
t.Errorf("%v.add(x: %d, y: %d) = %v, want %v",
tt.c, tt.x, tt.y, got, tt.want)
}
}
}
func TestIsLeft(t *testing.T) {
tests := []struct {
a, b, p Vec2
want bool
}{
{p: Vec2{X: 5, Y: -1}, a: Vec2{X: 0, Y: 0}, b: Vec2{X: 10, Y: 0}, want: true},
{p: Vec2{X: 5, Y: 0}, a: Vec2{X: 0, Y: 0}, b: Vec2{X: 10, Y: 0}, want: false},
{p: Vec2{X: 5, Y: 1}, a: Vec2{X: 0, Y: 0}, b: Vec2{X: 10, Y: 0}, want: false},
{p: Vec2{X: 11, Y: 15}, a: Vec2{X: 10, Y: 20}, b: Vec2{X: 15, Y: 10}, want: true},
{p: Vec2{X: 17, Y: 12}, a: Vec2{X: 10, Y: 20}, b: Vec2{X: 15, Y: 10}, want: false},
{p: Vec2{X: 5, Y: 1}, a: Vec2{X: 0, Y: 0}, b: Vec2{X: -10, Y: 0}, want: true},
{p: Vec2{X: 5, Y: -1}, a: Vec2{X: 0, Y: 0}, b: Vec2{X: -10, Y: 0}, want: false},
}
for _, tt := range tests {
got := isLeft(tt.p, tt.a, tt.b)
if got != tt.want {
t.Errorf("isLeft(p: %v, a: %v, b: %v) = %v, want %v",
tt.p, tt.a, tt.b, got, tt.want)
}
}
}