1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Add a few more tests (#1056)

* Add test for SumInts()

* Add a few more tests in utils

* Minor update for SumInts test
This commit is contained in:
David Bouchare 2021-03-01 17:33:42 +01:00 committed by GitHub
parent 7c12523139
commit cf3229e0cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 1 deletions

24
utils/sums_test.go Normal file
View File

@ -0,0 +1,24 @@
package utils
import (
"testing"
"github.com/stretchr/testify/assert"
)
func Test_SumInts(t *testing.T) {
expected := 6
result := SumInts([]int{1, 3, 2})
assert.Equal(t, expected, result)
expected = 46
result = SumInts([]int{4, 6, 7, 23, 6})
assert.Equal(t, expected, result)
expected = 4
result = SumInts([]int{4})
assert.Equal(t, expected, result)
}

View File

@ -204,7 +204,7 @@ func MaxInt(x, y int) int {
// //
// Examples: // Examples:
// //
// clamp(6, 3, 8) => 4 // clamp(6, 3, 8) => 6
// clamp(1, 3, 8) => 3 // clamp(1, 3, 8) => 3
// clamp(9, 3, 8) => 8 // clamp(9, 3, 8) => 8
// //

View File

@ -131,3 +131,32 @@ func Test_ReadFileBytes(t *testing.T) {
}) })
} }
} }
func Test_MaxInt(t *testing.T) {
expected := 3
result := MaxInt(3, 2)
assert.Equal(t, expected, result)
expected = 3
result = MaxInt(2, 3)
assert.Equal(t, expected, result)
}
func Test_Clamp(t *testing.T) {
expected := 6
result := Clamp(6, 3, 8)
assert.Equal(t, expected, result)
expected = 3
result = Clamp(1, 3, 8)
assert.Equal(t, expected, result)
expected = 8
result = Clamp(9, 3, 8)
assert.Equal(t, expected, result)
}