-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: covert the default statement with a no default type like uint
- Loading branch information
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |