go project - add a migration and rename the dockerfiles so that Go is the primary
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestAddUpload_AverageOfOne(t *testing.T) {
|
||||
s := New(nil)
|
||||
id := DeviceID("device-1")
|
||||
d := 197331667813 * time.Nanosecond // ~3m17.331667813s
|
||||
|
||||
s.AddUpload(id, d)
|
||||
|
||||
if got := s.AverageUploadTime(id); got != d {
|
||||
t.Fatalf("avg = %v, want %v", got, d)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddUpload_AverageOfMany(t *testing.T) {
|
||||
s := New(nil)
|
||||
id := DeviceID("device-1")
|
||||
|
||||
s.AddUpload(id, 100*time.Nanosecond)
|
||||
s.AddUpload(id, 200*time.Nanosecond)
|
||||
s.AddUpload(id, 300*time.Nanosecond)
|
||||
|
||||
// (100+200+300)/3 = 200
|
||||
if got := s.AverageUploadTime(id); got != 200*time.Nanosecond {
|
||||
t.Fatalf("avg = %v, want 200ns", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAverageUploadTime_UnknownDevice(t *testing.T) {
|
||||
s := New(nil)
|
||||
if got := s.AverageUploadTime(DeviceID("missing")); got != 0 {
|
||||
t.Fatalf("avg = %v, want 0", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAverageUploadTime_IsPerDevice(t *testing.T) {
|
||||
s := New(nil)
|
||||
a := DeviceID("device-1")
|
||||
b := DeviceID("device-2")
|
||||
|
||||
s.AddUpload(a, 100*time.Nanosecond)
|
||||
s.AddUpload(a, 300*time.Nanosecond)
|
||||
s.AddUpload(b, 50*time.Nanosecond)
|
||||
|
||||
if got := s.AverageUploadTime(a); got != 200*time.Nanosecond {
|
||||
t.Fatalf("device-1 avg = %v, want 200ns", got)
|
||||
}
|
||||
if got := s.AverageUploadTime(b); got != 50*time.Nanosecond {
|
||||
t.Fatalf("device-2 avg = %v, want 50ns", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAverageUploadTime_TruncatingDivision(t *testing.T) {
|
||||
s := New(nil)
|
||||
id := DeviceID("device-1")
|
||||
|
||||
// 10+11 = 21; 21/2 = 10 in integer division
|
||||
s.AddUpload(id, 10*time.Nanosecond)
|
||||
s.AddUpload(id, 11*time.Nanosecond)
|
||||
|
||||
if got := s.AverageUploadTime(id); got != 10*time.Nanosecond {
|
||||
t.Fatalf("avg = %v, want 10ns (truncating)", got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user