Skip to content

Commit

Permalink
Tests to prove GoVector's: pushfixed-handles-exception branch changes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Ropes committed Oct 30, 2015
1 parent 4600a11 commit 7a58565
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions anomalyze_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,33 @@ func TestAnomalyzerPushFixed(t *testing.T) {
assert.Equal(t, len(anomalyzer.Data), 6, "Array size did not stay at original size")
}

func TestAnomalyzerPushMixed(t *testing.T) {
conf := &AnomalyzerConf{
Sensitivity: 0.1,
UpperBound: 5,
LowerBound: 0,
ActiveSize: 1,
NSeasons: 4,
Methods: []string{"cdf", "fence", "highrank", "lowrank", "magnitude"},
}

// initialize with empty data or an actual slice of floats
data := []float64{0.1, 2.05, 1.5, 2.5, 2.6, 2.55}

anomalyzer, err := NewAnomalyzer(conf, data)
assert.Equal(t, nil, err, "Error initializing new anomalyzer")

prob, err := anomalyzer.PushFixed(8.0)
prob = anomalyzer.Push(10.0)
prob, err = anomalyzer.PushFixed(8.0)
prob = anomalyzer.Push(9.0)
assert.Equal(t, err, nil, "There was an error with mixing array extension")
assert.Tf(t, prob > 0.5, "Anomalyzer returned a probability that was too small")
assert.Equal(t, len(anomalyzer.Data), 8, "Array size Push* functions failed to grow Data to expected size")
assert.Equal(t, anomalyzer.Data[7], 9.0)
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.")
}

func Example() {
conf := &AnomalyzerConf{
Sensitivity: 0.1,
Expand Down

0 comments on commit 7a58565

Please sign in to comment.