Skip to content

Commit 7a58565

Browse files
committed
Tests to prove GoVector's: pushfixed-handles-exception branch changes
Changed the PushFixed array code to not break if the array was expanded by an external call to the standard Push function. The two functions can now be called in a mixed fashion, and PushFixed will still attempt to use as little memory as possible.
1 parent 4600a11 commit 7a58565

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

anomalyze_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,33 @@ func TestAnomalyzerPushFixed(t *testing.T) {
7070
assert.Equal(t, len(anomalyzer.Data), 6, "Array size did not stay at original size")
7171
}
7272

73+
func TestAnomalyzerPushMixed(t *testing.T) {
74+
conf := &AnomalyzerConf{
75+
Sensitivity: 0.1,
76+
UpperBound: 5,
77+
LowerBound: 0,
78+
ActiveSize: 1,
79+
NSeasons: 4,
80+
Methods: []string{"cdf", "fence", "highrank", "lowrank", "magnitude"},
81+
}
82+
83+
// initialize with empty data or an actual slice of floats
84+
data := []float64{0.1, 2.05, 1.5, 2.5, 2.6, 2.55}
85+
86+
anomalyzer, err := NewAnomalyzer(conf, data)
87+
assert.Equal(t, nil, err, "Error initializing new anomalyzer")
88+
89+
prob, err := anomalyzer.PushFixed(8.0)
90+
prob = anomalyzer.Push(10.0)
91+
prob, err = anomalyzer.PushFixed(8.0)
92+
prob = anomalyzer.Push(9.0)
93+
assert.Equal(t, err, nil, "There was an error with mixing array extension")
94+
assert.Tf(t, prob > 0.5, "Anomalyzer returned a probability that was too small")
95+
assert.Equal(t, len(anomalyzer.Data), 8, "Array size Push* functions failed to grow Data to expected size")
96+
assert.Equal(t, anomalyzer.Data[7], 9.0)
97+
assert.Equal(t, anomalyzer.Data[0], 1.5, "Two values were appended, two values were popped from the array. 3rd original element should be tail.")
98+
}
99+
73100
func Example() {
74101
conf := &AnomalyzerConf{
75102
Sensitivity: 0.1,

0 commit comments

Comments
 (0)