Skip to content

Commit

Permalink
test: covert the default statement with a no default type like uint
Browse files Browse the repository at this point in the history
  • Loading branch information
42atomys committed Aug 17, 2024
1 parent fe63cae commit bdcf95f
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions registry/numeric/helpers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package numeric

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestOperateNumeric(t *testing.T) {
var tests = []struct {
values []any
op numericOperation
initial any
expected any
}{
{[]any{1, 2}, func(a, b float64) float64 { return a + b }, 0, 3},
{[]any{1.5, 2.5}, func(a, b float64) float64 { return a - b }, 0, -1.0},
{[]any{1.5, 2.5}, func(a, b float64) float64 { return a * b }, 1, 3.75},
{[]any{1.5, 2.5}, func(a, b float64) float64 { return a / b }, 1, 0.6},
{[]any{uint(1), uint(2)}, func(a, b float64) float64 { return a + b }, uint(0), uint(3)},
}

for _, test := range tests {
result := operateNumeric(test.values, test.op, test.initial)
assert.Equal(t, test.expected, result, "operateNumeric(%v, %v, %v) returned %v, expected %v", test.values, test.op, test.initial, result, test.expected)
}
}

0 comments on commit bdcf95f

Please sign in to comment.