You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
882 B
Go
39 lines
882 B
Go
11 months ago
|
package arrays
|
||
|
|
||
|
import "testing"
|
||
|
|
||
|
// go test -cover will show the test coverage for our package.
|
||
|
|
||
|
func TestSum(t *testing.T) {
|
||
|
|
||
|
t.Run("sum collection of 5 of integers", func(t *testing.T) {
|
||
|
numbers := []int{1, 2, 3, 4, 5}
|
||
|
|
||
|
got := Sum(numbers)
|
||
|
expected := 15
|
||
|
|
||
|
// https://pkg.go.dev/fmt
|
||
|
if got != expected {
|
||
|
t.Errorf("got %d expected %d given, %v", got, expected, numbers)
|
||
|
}
|
||
|
})
|
||
|
|
||
|
// go test -cover will show the test coverage for our package.
|
||
|
|
||
|
// You can see that commenting out this "duplicate" function still retains 100%
|
||
|
// test coverage, which is how we know it's redundant.
|
||
|
|
||
|
// t.Run("sum a collection of any size", func(t *testing.T) {
|
||
|
// numbers := []int{1, 2, 3}
|
||
|
|
||
|
// got := Sum(numbers)
|
||
|
// expected := 6
|
||
|
|
||
|
// // https://pkg.go.dev/fmt
|
||
|
// if got != expected {
|
||
|
// t.Errorf("got %d expected %d given, %v", got, expected, numbers)
|
||
|
// }
|
||
|
// })
|
||
|
|
||
|
}
|