|
| 1 | +package math_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/stretchr/testify/assert" |
| 7 | + "github.com/yitsushi/go-aoc/math" |
| 8 | +) |
| 9 | + |
| 10 | +func TestVector2DInt_Rotate(t *testing.T) { |
| 11 | + tests := []struct { |
| 12 | + name string |
| 13 | + initial math.Vector2DInt |
| 14 | + degree float64 |
| 15 | + expected math.Vector2DInt |
| 16 | + }{ |
| 17 | + { |
| 18 | + name: "Rotate 90", |
| 19 | + initial: math.Vector2DInt{X: 1, Y: 0}, |
| 20 | + degree: 90, |
| 21 | + expected: math.Vector2DInt{X: 0, Y: 1}, |
| 22 | + }, |
| 23 | + { |
| 24 | + name: "Rotate -90", |
| 25 | + initial: math.Vector2DInt{X: 1, Y: 0}, |
| 26 | + degree: -90, |
| 27 | + expected: math.Vector2DInt{X: 0, Y: -1}, |
| 28 | + }, |
| 29 | + { |
| 30 | + name: "Rotate 180", |
| 31 | + initial: math.Vector2DInt{X: 1, Y: 0}, |
| 32 | + degree: 180, |
| 33 | + expected: math.Vector2DInt{X: -1, Y: 0}, |
| 34 | + }, |
| 35 | + { |
| 36 | + name: "Rotate -180", |
| 37 | + initial: math.Vector2DInt{X: 1, Y: 0}, |
| 38 | + degree: -180, |
| 39 | + expected: math.Vector2DInt{X: -1, Y: 0}, |
| 40 | + }, |
| 41 | + } |
| 42 | + for _, tt := range tests { |
| 43 | + t.Run(tt.name, func(t *testing.T) { |
| 44 | + v := &math.Vector2DInt{ |
| 45 | + X: tt.initial.X, |
| 46 | + Y: tt.initial.Y, |
| 47 | + } |
| 48 | + |
| 49 | + v.Rotate(tt.degree) |
| 50 | + |
| 51 | + assert.Equal(t, tt.expected.X, v.X) |
| 52 | + assert.Equal(t, tt.expected.Y, v.Y) |
| 53 | + }) |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +func TestVector2DInt_Manhattan(t *testing.T) { |
| 58 | + v := math.Vector2DInt{15, 33} |
| 59 | + |
| 60 | + assert.Equal(t, int(48), v.Manhattan()) |
| 61 | +} |
| 62 | + |
| 63 | +func TestVector2DInt_Hash(t *testing.T) { |
| 64 | + v := math.Vector2DInt{15, 33} |
| 65 | + |
| 66 | + assert.Equal(t, math.Vector2DInt{X: 15, Y: 33}, v.Hash()) |
| 67 | +} |
| 68 | + |
| 69 | +func TestVector2DInt_Neighbours(t *testing.T) { |
| 70 | + v := math.Vector2DInt{15, 33} |
| 71 | + |
| 72 | + neighbors := v.Neighbours() |
| 73 | + |
| 74 | + assert.Len(t, neighbors, 8) |
| 75 | +} |
| 76 | + |
| 77 | +func TestVector2DInt_Values(t *testing.T) { |
| 78 | + v := math.Vector2DInt{15, 33} |
| 79 | + |
| 80 | + assert.Equal(t, []int{15, 33}, v.Values()) |
| 81 | +} |
| 82 | + |
| 83 | +func TestVector2DInt_Add(t *testing.T) { |
| 84 | + v := math.Vector2DInt{15, 33} |
| 85 | + |
| 86 | + assert.Equal(t, math.Vector2DInt{26, 36}, v.Add(math.Vector2DInt{11, 3})) |
| 87 | +} |
0 commit comments