Skip to content
Snippets Groups Projects
Commit e476d19d authored by David Stainton's avatar David Stainton
Browse files

Add test TestMutateTimestampDeltaAverage

parent e6266d2e
No related branches found
No related tags found
5 merge requests!510Release,!419rewrote the health tracker to both consider if there are waiting rounds and...,!371[Channel RSAtoPrivate] Implement Reverse Asymmetric in Client/Broadcast,!354Channels impl,!340Project/channels
package channels package channels
import ( import (
"crypto/rand"
"testing"
"time" "time"
"gitlab.com/elixxir/crypto/channel"
) )
// withinMutationWindow is a utility test function to check if a mutated // withinMutationWindow is a utility test function to check if a mutated
...@@ -12,3 +16,30 @@ func withinMutationWindow(raw, mutated time.Time) bool { ...@@ -12,3 +16,30 @@ func withinMutationWindow(raw, mutated time.Time) bool {
return mutated.After(lowerBound) && mutated.Before(upperBound) return mutated.After(lowerBound) && mutated.Before(upperBound)
} }
func abs(n int64) int64 {
if n < 0 {
return -n
}
return n
}
func TestMutateTimestampDeltaAverage(t *testing.T) {
samples := 10000
t1 := time.Now()
sum := int64(0)
for i := 0; i < samples; i++ {
var msgID channel.MessageID
rand.Read(msgID[:])
t2 := mutateTimestamp(t1, msgID)
delta := t2.Sub(t1)
sum += abs(int64(delta))
}
avg := sum / int64(samples)
diff := abs(avg - 2502865)
if diff > 30000 {
t.Fatal()
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment