-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdirection_test.go
More file actions
123 lines (117 loc) · 2.39 KB
/
direction_test.go
File metadata and controls
123 lines (117 loc) · 2.39 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package main
import (
"fmt"
"testing"
)
func Test_Direction(t *testing.T) {
for i, tt := range []struct {
heading int
direction direction
}{
{0, N},
{11, N},
{12, NNE},
{33, NNE},
{34, NE},
{56, NE},
{57, ENE},
{78, ENE},
{79, E},
{101, E},
{102, ESE},
{123, ESE},
{124, SE},
{146, SE},
{147, SSE},
{168, SSE},
{169, S},
{191, S},
{192, SSW},
{213, SSW},
{214, SW},
{236, SW},
{237, WSW},
{258, WSW},
{259, W},
{281, W},
{282, WNW},
{303, WNW},
{304, NW},
{326, NW},
{327, NNW},
{348, NNW},
{349, N},
{359, N},
} {
t.Run(fmt.Sprintf("%d: %d %s", i, tt.heading, tt.direction.String()), func(t *testing.T) {
dir := Direction(tt.heading)
if dir != tt.direction {
t.Errorf("exp: %s got: %s", tt.direction.String(), dir.String())
}
})
}
}
func Test_PointOfSail(t *testing.T) {
for i, tt := range []struct {
wind direction
heading int
pos pointOfSail
}{
{N, 45, closePT},
{N, 90, beamPT},
{N, 135, broadPT},
{N, 180, run},
{N, 215, broadSB},
{N, 270, beamSB},
{N, 315, closeSB},
{NW, 90, broadPT},
{NW, 180, broadSB},
{S, 90, beamSB},
{S, 270, beamPT},
} {
t.Run(fmt.Sprintf("%d: %s %d", i, tt.wind.String(), tt.heading), func(t *testing.T) {
pos := tt.wind.pointOfSail(tt.heading)
if pos.pointOfSail != tt.pos {
t.Errorf("exp %s got %s", tt.pos.String(), pos.String())
}
})
}
}
func Test_TurnType(t *testing.T) {
for i, tt := range []struct {
from, to pointOfSail
turn turn
}{
{closePT, closeSB, tackPTSB},
{closeSB, closePT, tackSBPT},
{closeSB, broadSB, bearawaySB},
{closePT, broadPT, bearawayPT},
{broadPT, broadSB, gybePTSB},
{broadSB, broadPT, gybeSBPT},
{broadSB, closeSB, roundupSB},
{broadPT, closePT, roundupPT},
} {
t.Run(fmt.Sprintf("%d: %s-%s", i, tt.from, tt.to), func(t *testing.T) {
got := turnType(tt.from, tt.to)
if got != tt.turn {
t.Errorf("exp %s got %s", tt.turn, got)
}
})
}
}
func Test_WindDirectionTurnType(t *testing.T) {
for i, tt := range []struct {
wind direction
from, to int
turn string
}{
{N, 310, 40, "tack starboard to port N"},
} {
t.Run(fmt.Sprintf("%d: %d->%d@%s", i, tt.from, tt.to, tt.wind), func(t *testing.T) {
got := tt.wind.turnType(tt.wind.pointOfSail(tt.from), tt.wind.pointOfSail(tt.to))
if got.String() != tt.turn {
t.Errorf("exp %s got %s", tt.turn, got)
}
})
}
}