Skip to main content
Module

x/rambda/source/groupWith.spec.js

Faster and smaller alternative to Ramda
Go to Latest
File
import {equals} from './equals'import {groupWith} from './groupWith'
test('issue is fixed', () => { const result = groupWith(equals, [1, 2, 2, 3]) const expected = [[1], [2, 2], [3]] expect(result).toEqual(expected)})
test('long list', () => { const result = groupWith( equals, [0, 1, 1, 2, 3, 5, 8, 13, 21, 21, 21, 1, 2] )
const expected = [ [0], [1, 1], [2], [3], [5], [8], [13], [21, 21, 21], [1], [2], ] expect(result).toEqual(expected)})
test('readme example', () => { const list = [4, 3, 6, 2, 2, 1]
const result = groupWith((a, b) => a - b === 1, list) const expected = [[4, 3], [6], [2], [2, 1]] expect(result).toEqual(expected)})
test('throw with string as input', () => { expect(() => groupWith(equals, 'Mississippi')).toThrowWithMessage( TypeError, 'list.reduce is not a function' )})
const isConsecutive = function (a, b) { return a + 1 === b}
test('fix coverage', () => { expect(groupWith(isConsecutive, [1, 2, 3, 0])).toEqual([[1, 2, 3], [0]])})
test('from ramda 0', () => { expect(groupWith(equals, [])).toEqual([]) expect(groupWith(isConsecutive, [])).toEqual([])})
test('from ramda 1', () => { expect(groupWith(isConsecutive, [4, 3, 2, 1])).toEqual([ [4], [3], [2], [1], ])})
test('from ramda 2', () => { expect(groupWith(isConsecutive, [1, 2, 3, 4])).toEqual([[1, 2, 3, 4]])})
test('from ramda 3', () => { expect(groupWith(isConsecutive, [1, 2, 2, 3])).toEqual([ [1, 2], [2, 3], ]) expect(groupWith(isConsecutive, [1, 2, 9, 3, 4])).toEqual([ [1, 2], [9], [3, 4], ])})
test('list with single item', () => { const result = groupWith(equals, [0])
const expected = [[0]] expect(result).toEqual(expected)})