Skip to content

Commit

Permalink
refactor: merge FuzzUtilLimit into FuzzUtilLimitSet
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvinJWendt committed Feb 3, 2023
1 parent 28e36e1 commit df96e2e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 239 deletions.
23 changes: 3 additions & 20 deletions fuzz-utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func FuzzUtilModifySet[setType any](inputSet []setType, modifier func(index int,
return
}

// FuzzUtilLimitSet limits a test set in size.
// FuzzUtilLimitSet returns a random sample of a test set with a maximal size.
//
// Example:
//
Expand All @@ -83,6 +83,8 @@ func FuzzUtilLimitSet[setType any](testSet []setType, max int) []setType {
return []setType{}
}

rand.Shuffle(len(testSet), func(i, j int) { testSet[i], testSet[j] = testSet[j], testSet[i] })

return testSet[:max]
}

Expand All @@ -105,22 +107,3 @@ func FuzzUtilDistinctSet[setType comparable](testSet []setType) []setType {

return result
}

// FuzzUtilLimit returns a random piece of input set.
//
// Example:
//
// limited := testza.FuzzUtilLimit(testza.FuzzStringFull(), 10)
func FuzzUtilLimit[setType any](testSet []setType, limit int) []setType {
if len(testSet) <= limit {
return testSet
}

if limit <= 0 {
return []setType{}
}

rand.Shuffle(len(testSet), func(i, j int) { testSet[i], testSet[j] = testSet[j], testSet[i] })

return testSet[:limit]
}
20 changes: 0 additions & 20 deletions fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,26 +81,6 @@ func TestFuzzUtilDistinctSet(t *testing.T) {
AssertEqual(t, FuzzUtilDistinctSet([]int{1, 2, 2, 1, 3}), []int{1, 2, 3})
}

func TestFuzzUtilLimit(t *testing.T) {
for i := 0; i < 10; i++ {
t.Run(fmt.Sprintf("String (Limit=%d)", i), func(t *testing.T) {
AssertLen(t, FuzzUtilLimit(FuzzStringFull(), i), i)
})

t.Run(fmt.Sprintf("Int (Limit=%d)", i), func(t *testing.T) {
AssertLen(t, FuzzUtilLimit(FuzzIntFull(), i), i)
})

t.Run(fmt.Sprintf("Float64 (Limit=%d)", i), func(t *testing.T) {
AssertLen(t, FuzzUtilLimit(FuzzFloat64Full(), i), i)
})
}

t.Run(fmt.Sprintf("Limit bigger than length (Limit=%d)", 10), func(t *testing.T) {
AssertLen(t, FuzzUtilLimit([]string{"a", "b", "c"}, 10), 3)
})
}

// endregion

// region FuzzString
Expand Down
199 changes: 0 additions & 199 deletions output/fail_assertions_test.go

This file was deleted.

0 comments on commit df96e2e

Please sign in to comment.