diff options
Diffstat (limited to 'ms/ms_test.go')
| -rw-r--r-- | ms/ms_test.go | 117 |
1 files changed, 104 insertions, 13 deletions
diff --git a/ms/ms_test.go b/ms/ms_test.go index 988b647..d93102f 100644 --- a/ms/ms_test.go +++ b/ms/ms_test.go @@ -7,15 +7,106 @@ import ( "github.com/network-quality/goresponsiveness/utilities" ) -func Test_TooFewInstantsSequentialIncreasesLessThanAlwaysFalse(test *testing.T) { +func Test_InfiniteValues(test *testing.T) { + series := NewInfiniteMathematicalSeries[float64]() + shouldMatch := make([]float64, 0) + previous := float64(1.0) + for _ = range utilities.Iota(1, 80) { + previous *= 1.059 + series.AddElement(float64(previous)) + shouldMatch = append(shouldMatch, previous) + } + + if !reflect.DeepEqual(shouldMatch, series.Values()) { + test.Fatalf("Values() on infinite mathematical series does not work.") + } +} +func Test_InfiniteSequentialIncreasesAlwaysLessThan(test *testing.T) { + series := NewInfiniteMathematicalSeries[float64]() + previous := float64(1.0) + for _ = range utilities.Iota(1, 80) { + previous *= 1.059 + series.AddElement(float64(previous)) + } + if islt, maxSeqIncrease := series.AllSequentialIncreasesLessThan(6.0); !islt { + test.Fatalf("(infinite) Sequential increases are not always less than 6.0 (%f).", maxSeqIncrease) + } +} +func Test_CappedTooFewInstantsSequentialIncreasesLessThanAlwaysFalse(test *testing.T) { series := NewCappedMathematicalSeries[float64](500) series.AddElement(0.0) if islt, _ := series.AllSequentialIncreasesLessThan(6.0); islt { - test.Fatalf("Too few instants should always yield false when asking if sequential increases are less than a value.") + test.Fatalf("(infinite) 0 elements in a series should always yield false when asking if sequential increases are less than a value.") + } +} + +func Test_Infinite_degenerate_percentile_too_high(test *testing.T) { + series := NewInfiniteMathematicalSeries[int]() + if series.Percentile(101) != 0 { + test.Fatalf("(infinite) Series percentile of 101 failed.") + } +} +func Test_Infinite_degenerate_percentile_too_low(test *testing.T) { + series := NewInfiniteMathematicalSeries[int]() + if series.Percentile(-1) != 0 { + test.Fatalf("(infinite) Series percentile of -1 failed.") + } +} +func Test_Infinite90_percentile(test *testing.T) { + series := NewInfiniteMathematicalSeries[int]() + series.AddElement(10) + series.AddElement(9) + series.AddElement(8) + series.AddElement(7) + series.AddElement(6) + series.AddElement(5) + series.AddElement(4) + series.AddElement(3) + series.AddElement(2) + series.AddElement(1) + + if series.Percentile(90) != 10 { + test.Fatalf("(infinite) Series 90th percentile of 0 ... 10 failed: Expected 10 got %v.", series.Percentile(90)) + } +} + +func Test_Infinite90_percentile_reversed(test *testing.T) { + series := NewInfiniteMathematicalSeries[int64]() + series.AddElement(1) + series.AddElement(2) + series.AddElement(3) + series.AddElement(4) + series.AddElement(5) + series.AddElement(6) + series.AddElement(7) + series.AddElement(8) + series.AddElement(9) + series.AddElement(10) + + if series.Percentile(90) != 10 { + test.Fatalf("(infinite) Series 90th percentile of 0 ... 10 failed: Expected 10 got %v.", series.Percentile(90)) + } +} + +func Test_Infinite50_percentile_jumbled(test *testing.T) { + series := NewInfiniteMathematicalSeries[int64]() + series.AddElement(7) + series.AddElement(2) + series.AddElement(15) + series.AddElement(27) + series.AddElement(5) + series.AddElement(52) + series.AddElement(18) + series.AddElement(23) + series.AddElement(11) + series.AddElement(12) + + if series.Percentile(50) != 15 { + test.Fatalf("(infinite) Series 50 percentile of a jumble of numbers failed: Expected 15 got %v.", series.Percentile(50)) } } -func Test_SequentialIncreasesAlwaysLessThan(test *testing.T) { +func Test_CappedSequentialIncreasesAlwaysLessThan(test *testing.T) { series := NewCappedMathematicalSeries[float64](40) previous := float64(1.0) for _ = range utilities.Iota(1, 80) { @@ -27,7 +118,7 @@ func Test_SequentialIncreasesAlwaysLessThan(test *testing.T) { } } -func Test_SequentialIncreasesAlwaysLessThanWithWraparound(test *testing.T) { +func Test_CappedSequentialIncreasesAlwaysLessThanWithWraparound(test *testing.T) { series := NewCappedMathematicalSeries[float64](20) previous := float64(1.0) for range utilities.Iota(1, 20) { @@ -47,7 +138,7 @@ func Test_SequentialIncreasesAlwaysLessThanWithWraparound(test *testing.T) { } } -func Test_SequentialIncreasesAlwaysLessThanWithWraparoundInverse(test *testing.T) { +func Test_CappedSequentialIncreasesAlwaysLessThanWithWraparoundInverse(test *testing.T) { series := NewCappedMathematicalSeries[float64](20) previous := float64(1.0) for range utilities.Iota(1, 20) { @@ -67,7 +158,7 @@ func Test_SequentialIncreasesAlwaysLessThanWithWraparoundInverse(test *testing.T } } -func Test_StandardDeviationCalculation(test *testing.T) { +func Test_CappedStandardDeviationCalculation(test *testing.T) { series := NewCappedMathematicalSeries[float64](5) // 5.7, 1.0, 8.6, 7.4, 2.2 series.AddElement(5.7) @@ -83,7 +174,7 @@ func Test_StandardDeviationCalculation(test *testing.T) { } } -func Test_RotatingValues(test *testing.T) { +func Test_CappedRotatingValues(test *testing.T) { series := NewCappedMathematicalSeries[int](5) series.AddElement(1) @@ -99,7 +190,7 @@ func Test_RotatingValues(test *testing.T) { test.Fatalf("Adding values does not properly erase earlier values.") } } -func Test_Size(test *testing.T) { +func Test_CappedSize(test *testing.T) { series := NewCappedMathematicalSeries[int](5) series.AddElement(1) @@ -116,19 +207,19 @@ func Test_Size(test *testing.T) { } } -func Test_degenerate_percentile_too_high(test *testing.T) { +func Test_Capped_degenerate_percentile_too_high(test *testing.T) { series := NewCappedMathematicalSeries[int](21) if series.Percentile(101) != 0 { test.Fatalf("Series percentile of 101 failed.") } } -func Test_degenerate_percentile_too_low(test *testing.T) { +func Test_Capped_degenerate_percentile_too_low(test *testing.T) { series := NewCappedMathematicalSeries[int](21) if series.Percentile(-1) != 0 { test.Fatalf("Series percentile of -1 failed.") } } -func Test_90_percentile(test *testing.T) { +func Test_Capped90_percentile(test *testing.T) { series := NewCappedMathematicalSeries[int](10) series.AddElement(10) series.AddElement(9) @@ -146,7 +237,7 @@ func Test_90_percentile(test *testing.T) { } } -func Test_90_percentile_reversed(test *testing.T) { +func Test_Capped90_percentile_reversed(test *testing.T) { series := NewCappedMathematicalSeries[int64](10) series.AddElement(1) series.AddElement(2) @@ -164,7 +255,7 @@ func Test_90_percentile_reversed(test *testing.T) { } } -func Test_50_percentile_jumbled(test *testing.T) { +func Test_Capped50_percentile_jumbled(test *testing.T) { series := NewCappedMathematicalSeries[int64](10) series.AddElement(7) series.AddElement(2) |
