underscore/sum_test.go
Andy Long 3066810f92 Adding some new funky functions which I find useful
Created a Tuple struct as some of the new functions require you to return a new slice with two fields which is the result of the new functions

Created the Join, JoinProjection, Range, SumMap, Zip functions, ecah fuction is documented with how it works and had a unit test or maybe more
2022-09-02 00:12:39 +01:00

33 lines
578 B
Go

package underscore_test
import (
"testing"
u "github.com/rjNemo/underscore"
"github.com/stretchr/testify/assert"
)
func TestSum(t *testing.T) {
nums := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
want := 45
assert.Equal(t, want, u.Sum(nums))
}
func TestSumMap(t *testing.T) {
nums := []u.Tuple[string, int]{
{"zero", 0},
{"one", 1},
{"two", 2},
{"three", 3},
{"four", 4},
{"five", 5},
{"six", 6},
{"seven", 7},
{"eight", 8},
{"nine", 9},
}
want := 45
assert.Equal(t, want, u.SumMap(nums, func(item u.Tuple[string, int]) int { return item.Right }))
}