Skip to content

Commit

Permalink
Add a deterministic test
Browse files Browse the repository at this point in the history
  • Loading branch information
yuxincs committed Oct 29, 2023
1 parent fb4b62b commit dc0e5a7
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions inference/inferred_map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,27 @@ func TestEncoding_Size(t *testing.T) {
)
}

func TestEncoding_Deterministic(t *testing.T) {
t.Parallel()

m := newBigInferredMap()
var previous []byte

// Encode the inferred map 10 times and check that the result is always the same.
for i := 0; i < 10; i++ {
var buf bytes.Buffer
err := gob.NewEncoder(&buf).Encode(m)
require.NoError(t, err)
require.NotEmpty(t, buf.Bytes())

if len(previous) == 0 {
previous = buf.Bytes()
continue
}
require.Equal(t, previous, buf.Bytes())
}
}

func TestDecoding(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit dc0e5a7

Please sign in to comment.