mirror of
https://github.com/rjNemo/underscore
synced 2026-06-06 02:26:42 +00:00
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
33 lines
578 B
Go
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 }))
|
|
}
|