summaryrefslogtreecommitdiff
path: root/utilities/utilities_test.go
diff options
context:
space:
mode:
authorWill Hawkins <[email protected]>2023-07-10 13:45:50 -0400
committerWill Hawkins <[email protected]>2023-07-10 13:45:50 -0400
commit78d574a74665c8bc062c26755c80a8b524bce347 (patch)
tree7ad65f0052defaea63acb2f3445be00ef97e24d6 /utilities/utilities_test.go
parentfe17152a507bbf94a11cca7f49a51cbae9c0d67b (diff)
[Feature] Major update: Track measurements that may be delayed
Among other major feature additions, this version of the client tracks any measurements that may be long delayed and considers their presence or absence as part of a stability measurement. This version of the client also more closely tracks the spec. In particular, it performs a sinle-sided trimmed mean rather than a double-sided trimmed mean. Signed-off-by: Will Hawkins <[email protected]>
Diffstat (limited to 'utilities/utilities_test.go')
-rw-r--r--utilities/utilities_test.go62
1 files changed, 62 insertions, 0 deletions
diff --git a/utilities/utilities_test.go b/utilities/utilities_test.go
index 9cd4ef0..7f3d83a 100644
--- a/utilities/utilities_test.go
+++ b/utilities/utilities_test.go
@@ -126,3 +126,65 @@ func TestPerSecondToInterval(t *testing.T) {
t.Fatalf("Something that happens twice per second should happen every 5000ns.")
}
}
+
+func TestTrim(t *testing.T) {
+ elements := Iota(1, 101)
+
+ trimmedElements := TrimBy(elements, 75)
+
+ trimmedLength := len(trimmedElements)
+ trimmedLast := trimmedElements[trimmedLength-1]
+
+ if trimmedLength != 75 || trimmedLast != 75 {
+ t.Fatalf("When trimming, the length should be 75 but it is %d and/or the last element should be 75 but it is %d", trimmedLength, trimmedLast)
+ }
+}
+
+func TestTrim2(t *testing.T) {
+ elements := Iota(1, 11)
+
+ trimmedElements := TrimBy(elements, 75)
+
+ trimmedLength := len(trimmedElements)
+ trimmedLast := trimmedElements[trimmedLength-1]
+
+ if trimmedLength != 7 || trimmedLast != 7 {
+ t.Fatalf("When trimming, the length should be 7 but it is %d and/or the last element should be 7 but it is %d", trimmedLength, trimmedLast)
+ }
+}
+
+func TestTrim3(t *testing.T) {
+ elements := Iota(1, 6)
+
+ trimmedElements := TrimBy(elements, 101)
+
+ trimmedLength := len(trimmedElements)
+ trimmedLast := trimmedElements[trimmedLength-1]
+
+ if trimmedLength != 5 || trimmedLast != 5 {
+ t.Fatalf("When trimming, the length should be 5 but it is %d and/or the last element should be 5 but it is %d", trimmedLength, trimmedLast)
+ }
+}
+
+func TestTrim4(t *testing.T) {
+ elements := Iota(1, 11)
+
+ trimmedElements := TrimBy(elements, 81)
+
+ trimmedLength := len(trimmedElements)
+ trimmedLast := trimmedElements[trimmedLength-1]
+
+ if trimmedLength != 8 || trimmedLast != 8 {
+ t.Fatalf("When trimming, the length should be 8 but it is %d and/or the last element should be 8 but it is %d", trimmedLength, trimmedLast)
+ }
+}
+
+func TestTrimmedMean(t *testing.T) {
+ expected := 2.5
+ elements := []int{5, 4, 3, 2, 1}
+
+ result, elements := TrimmedMean(elements, 80)
+ if result != expected || len(elements) != 4 || elements[len(elements)-1] != 4 {
+ t.Fatalf("The trimmed mean result %v does not match the expected value %v", result, expected)
+ }
+}