Skip to content

Commit

Permalink
TestVersion7MonotonicityStrict
Browse files Browse the repository at this point in the history
  • Loading branch information
it512 committed Jan 13, 2024
1 parent 016b199 commit 74c320f
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions uuid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -896,3 +896,30 @@ func TestVersion7Monotonicity(t *testing.T) {
u1 = u2
}
}

type fakeRand struct{}

func (g fakeRand) Read(bs []byte) (int, error) {
for i, _ := range bs {
bs[i] = 0x88
}
return len(bs), nil
}

func TestVersion7MonotonicityStrict(t *testing.T) {
timeNow = func() time.Time {
return time.Date(2008, 8, 8, 8, 8, 8, 8, time.UTC)
}
SetRand(fakeRand{})

length := 100000 // > 3906
u1 := Must(NewV7()).String()
for i := 0; i < length; i++ {
u2 := Must(NewV7()).String()
if u2 <= u1 {
t.Errorf("monotonicity failed at #%d: %s(next) < %s(before)", i, u2, u1)
break
}
u1 = u2
}
}

0 comments on commit 74c320f

Please sign in to comment.