mirror of
https://github.com/rjNemo/underscore
synced 2026-06-06 10:36:43 +00:00
* 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 * Added in an OrderBy function * Documentation comment for OrderBy which I missed out * Adding a Unit test for JoinProject function Updated the comments on the Join & OrderBy functions so they make a little more sense. Covered an extra test case with the Join test, where the left set has more data than the right and so the Right handside array of the join is empty
31 lines
530 B
Go
31 lines
530 B
Go
package underscore_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
u "github.com/rjNemo/underscore"
|
|
)
|
|
|
|
func Test_OrderBy_Asc(t *testing.T) {
|
|
set := u.Range(5, 0)
|
|
want := u.Range(0, 5)
|
|
|
|
result := u.OrderBy(set, func(left int, right int) bool {
|
|
return left > right
|
|
})
|
|
|
|
assert.Equal(t, want, result)
|
|
}
|
|
|
|
func Test_OrderBy_Desc(t *testing.T) {
|
|
set := u.Range(0, 5)
|
|
want := u.Range(5, 0)
|
|
|
|
result := u.OrderBy(set, func(left int, right int) bool {
|
|
return left < right
|
|
})
|
|
|
|
assert.Equal(t, want, result)
|
|
}
|