We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
would you accept tests helpers on this repo ?
like parametrize ?
parametrize
func parametrize[V any, T any](fn T, allValues [][]V) { v := reflect.ValueOf(fn) for _, a := range allValues { vargs := make([]reflect.Value, len(a)) for i, b := range a { vargs[i] = reflect.ValueOf(b) } v.Call(vargs) } } func tutu(a int) int { return a + 1 } func Test_tutu(t *testing.T) { testsArgs := [][]any{ {t, 1, 2}, {t, 3, 4}, } test := func(t *testing.T, input int, expected int) { assert.Equal(t, tutu(input), expected) } parametrize(test, testsArgs) }
The text was updated successfully, but these errors were encountered:
Hi.
Yes, it looks like a good idea. Feel free to prepare a pull request
Sorry, something went wrong.
parametrize is just a specific Each
Each
that accepts a list of multiple parameters instead of a list of single parameter
so it could be
func EachMultiple[T any, V any](allValues [][]T, action V) { v := reflect.ValueOf(action) for _, a := range allValues { vargs := make([]reflect.Value, len(a)) for i, b := range a { vargs[i] = reflect.ValueOf(b) } v.Call(vargs) } }
I have no idea for a good name
But maybe the best would be to introduce a partial struct like in python
from functools import partial def f(a, b, c, x): return 1000*a + 100*b + 10*c + x g = partial(f, 3, 1, 4) print(g(5)) # give 3145
No branches or pull requests
would you accept tests helpers on this repo ?
like
parametrize
?The text was updated successfully, but these errors were encountered: