This repository has been archived by the owner on Aug 4, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
swego_test.go
132 lines (112 loc) · 2.82 KB
/
swego_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
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
124
125
126
127
128
129
130
131
132
package swego
import "testing"
func TestNewHSys(t *testing.T) {
cases := []struct {
in byte
want bool
}{
{'A', true}, // Equal
{'B', true}, // Alcabitius
{'C', true}, // Campanus
{'D', true}, // Equal houses, where cusp 10 = MC
{'E', true}, // Equal
{'F', true}, // Carter poli-equatorial
{'G', true}, // Gauquelin sectors
{'H', true}, // Azimuthal
{'I', true}, // Sunshine (Treindl)
{'i', true}, // Sunshine (Makransky)
{'K', true}, // Koch
{'L', true}, // Pullen SD (sinusoidal delta) = ex Neo-Porphyry
{'M', true}, // Morinus
{'N', true}, // Equal houses, where cusp 1 = 0 Aries
{'O', true}, // Porphyrius
{'P', true}, // Placidus
{'Q', true}, // Pullen SR (sinusoidal ratio)
{'R', true}, // Regiomontanus
{'S', true}, // Sripati
{'T', true}, // Polich-Page
{'U', true}, // Krusinski-Pisa-Goelzer
{'V', true}, // Vehlow equal
{'W', true}, // Whole sign
{'X', true}, // Axial rotation
{'Y', true}, // APC houses
{'_', false},
{'Z', false},
}
for _, c := range cases {
hsys, ok := NewHSys(c.in)
if ok && byte(hsys) != c.in {
t.Errorf("input %q is not returned", c.in)
}
if !ok && byte(hsys) != '\000' {
t.Errorf("invalid input does not return '\\000' as hsys")
}
if ok != c.want {
t.Errorf("%q is no valid house system", c.in)
}
}
}
func TestNewHSys_lowerToUpper(t *testing.T) {
got, ok := NewHSys('a')
if !ok {
t.Error("ok = false, want: true")
}
want := HSys('A')
if got != want {
t.Errorf("hsys = %c, want: %c", got, want)
}
}
func TestCalcFlags_Copy(t *testing.T) {
fl := new(CalcFlags)
fl.Flags = FlagSpeed
got := fl.Copy()
if got == fl {
t.Errorf("%p = %p, want copy", got, fl)
}
}
func TestCalcFlags_SetEphemeris(t *testing.T) {
fl := new(CalcFlags)
fl.SetEphemeris(JPL)
if fl.Flags != int32(JPL) {
t.Error("flags value does not contain ephemeris flag")
}
}
type testInterface struct{ Interface }
type testExclLocker struct{ Interface }
type testLockedIface struct{ Interface }
func (l *testLockedIface) ExclusiveUnlock() {}
func (el *testExclLocker) ExclusiveLock() LockedInterface {
return &testLockedIface{el}
}
func TestLocked(t *testing.T) {
t.Run("Interface", func(t *testing.T) {
called := make(chan struct{}, 1)
swe := new(testInterface)
Locked(swe, func(i Interface) {
if i != swe {
t.Error("passed Interface no equal to input Interface")
}
called <- struct{}{}
})
select {
case <-called:
default:
t.Error("callback not called")
}
})
t.Run("ExclusiveLocker", func(t *testing.T) {
called := make(chan struct{}, 1)
swe := (*testExclLocker)(nil)
Locked(swe, func(i Interface) {
if i.(*testLockedIface).Interface != swe {
t.Error("passed Interface no equal to input Interface")
}
called <- struct{}{}
})
select {
case <-called:
default:
t.Error("callback not called")
}
})
}