aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/stat/sample/sample_test.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2024-07-24 12:08:49 +0200
committerDmitry Vyukov <dvyukov@google.com>2024-07-24 14:39:45 +0000
commit49e6369fe732c0f81e5b03b36e345afbf3c79a15 (patch)
tree651e322e41a8084abd6f2c80e4f9b7ff50a1dfe9 /pkg/stat/sample/sample_test.go
parent1f032c27c8158e44723253179928104813d45cdc (diff)
pkg/stat: rename package name to singular form
Go package names should generally be singular form: https://go.dev/blog/package-names https://rakyll.org/style-packages https://groups.google.com/g/golang-nuts/c/buBwLar1gNw
Diffstat (limited to 'pkg/stat/sample/sample_test.go')
-rw-r--r--pkg/stat/sample/sample_test.go66
1 files changed, 66 insertions, 0 deletions
diff --git a/pkg/stat/sample/sample_test.go b/pkg/stat/sample/sample_test.go
new file mode 100644
index 000000000..ac7845ccf
--- /dev/null
+++ b/pkg/stat/sample/sample_test.go
@@ -0,0 +1,66 @@
+// Copyright 2021 syzkaller project authors. All rights reserved.
+// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
+
+package sample
+
+import (
+ "reflect"
+ "testing"
+)
+
+func TestMedian(t *testing.T) {
+ tests := []struct {
+ input []float64
+ minMedian float64
+ maxMedian float64
+ }{
+ {
+ input: []float64{1, 2, 3},
+ minMedian: 1.99, // we cannot do exact floating point equality comparison
+ maxMedian: 2.01,
+ },
+ {
+ input: []float64{0, 1, 2, 3},
+ minMedian: 1.0,
+ maxMedian: 2.0,
+ },
+ }
+ for _, test := range tests {
+ sample := Sample{Xs: test.input}
+ median := sample.Median()
+ if median < test.minMedian || median > test.maxMedian {
+ t.Errorf("sample %v, median got %v, median expected [%v;%v]",
+ test.input, median, test.minMedian, test.maxMedian)
+ }
+ }
+}
+
+func TestRemoveOutliers(t *testing.T) {
+ // Some tests just to check the overall sanity of the method.
+ tests := []struct {
+ input []float64
+ output []float64
+ }{
+ {
+ input: []float64{-20, 1, 2, 3, 4, 5},
+ output: []float64{1, 2, 3, 4, 5},
+ },
+ {
+ input: []float64{1, 2, 3, 4, 25},
+ output: []float64{1, 2, 3, 4},
+ },
+ {
+ input: []float64{-10, -5, 0, 5, 10, 15},
+ output: []float64{-10, -5, 0, 5, 10, 15},
+ },
+ }
+ for _, test := range tests {
+ sample := Sample{Xs: test.input}
+ result := sample.RemoveOutliers()
+ result.Sort()
+ if !reflect.DeepEqual(result.Xs, test.output) {
+ t.Errorf("input: %v, expected no outliers: %v, got: %v",
+ test.input, test.output, result.Xs)
+ }
+ }
+}