github.com/lazyledger/lazyledger-core@v0.35.0-dev.0.20210613111200-4c651f053571/p2p/ipld/sample_test.go (about) 1 package ipld 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func TestSampleSquare(t *testing.T) { 10 tests := []struct { 11 width uint32 12 samples int 13 }{ 14 {width: 10, samples: 5}, 15 {width: 500, samples: 90}, 16 } 17 18 for _, tt := range tests { 19 ss := SampleSquare(tt.width, tt.samples) 20 assert.Len(t, ss, tt.samples) 21 // check points are within width 22 for _, s := range ss { 23 assert.Less(t, s.Row, tt.width) 24 assert.Less(t, s.Col, tt.width) 25 } 26 // checks samples are not equal 27 for i, s1 := range ss { 28 for j, s2 := range ss { 29 if i != j { 30 assert.False(t, s1.Equals(s2)) 31 } 32 } 33 } 34 } 35 }