Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add SampleBy and SamplesBy #516

Merged
merged 21 commits into from
Jan 26, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Better test
Bram Van de Walle committed Aug 16, 2024
commit 9be284c05028171162b89dd8ef72c3a7bf2d150d
10 changes: 7 additions & 3 deletions find_test.go
Original file line number Diff line number Diff line change
@@ -555,7 +555,9 @@ func TestSampleBy(t *testing.T) {
t.Parallel()
is := assert.New(t)

result1 := SampleBy([]string{"a", "b", "c"}, rand.Intn)
r := rand.New(rand.NewSource(42))

result1 := SampleBy([]string{"a", "b", "c"}, r.Intn)
result2 := SampleBy([]string{}, rand.Intn)

is.True(Contains([]string{"a", "b", "c"}, result1))
@@ -586,8 +588,10 @@ func TestSamplesBy(t *testing.T) {
t.Parallel()
is := assert.New(t)

result1 := SamplesBy([]string{"a", "b", "c"}, 3, rand.Intn)
result2 := SamplesBy([]string{}, 3, rand.Intn)
r := rand.New(rand.NewSource(42))

result1 := SamplesBy([]string{"a", "b", "c"}, 3, r.Intn)
result2 := SamplesBy([]string{}, 3, r.Intn)

sort.Strings(result1)