diff --git a/channels/mutateTimestamp_test.go b/channels/mutateTimestamp_test.go index 843757c3e0221907a0fbf884b47f2d52d26f0af9..ba58728c487a3b40338ab9cfad135f98d1d681e7 100644 --- a/channels/mutateTimestamp_test.go +++ b/channels/mutateTimestamp_test.go @@ -1,7 +1,11 @@ package channels import ( + "crypto/rand" + "testing" "time" + + "gitlab.com/elixxir/crypto/channel" ) // withinMutationWindow is a utility test function to check if a mutated @@ -12,3 +16,30 @@ func withinMutationWindow(raw, mutated time.Time) bool { 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() + } +}