it('concats two object sequences', () => { var a = Seq({a:1,b:2,c:3}); var b = Seq({d:4,e:5,f:6}); expect(a.size).toBe(3); expect(a.concat(b).size).toBe(6); expect(a.concat(b).toObject()).toEqual({a:1,b:2,c:3,d:4,e:5,f:6}); })
it('some is true when predicate is true for any entry', () => { expect(Seq([]).some(() => true)).toBe(false); expect(Seq([1,2,3]).some(v => v > 0)).toBe(true); expect(Seq([1,2,3]).some(v => v < 3)).toBe(true); expect(Seq([1,2,3]).some(v => v > 1)).toBe(true); expect(Seq([1,2,3]).some(v => v < 0)).toBe(false); });
it('slices an unindexed sequence', () => { expect(Seq({a:1,b:2,c:3}).slice(1).toObject()).toEqual({b:2,c:3}); expect(Seq({a:1,b:2,c:3}).slice(1, 2).toObject()).toEqual({b:2}); expect(Seq({a:1,b:2,c:3}).slice(0, 2).toObject()).toEqual({a:1,b:2}); expect(Seq({a:1,b:2,c:3}).slice(-1).toObject()).toEqual({c:3}); expect(Seq({a:1,b:2,c:3}).slice(1, -1).toObject()).toEqual({b:2}); })
check.it('is not dependent on order', [genHeterogeneousishArray], vals => { expect( is( Seq(shuffle(vals.slice())).max(), Seq(vals).max() ) ).toEqual(true); });
it('cannot be mutated after calling toArray', () => { var seq = Seq(['A', 'B', 'C']); var firstReverse = Seq(seq.toArray().reverse()); var secondReverse = Seq(seq.toArray().reverse()); expect(firstReverse.get(0)).toEqual('C'); expect(secondReverse.get(0)).toEqual('C'); });
it('cannot be mutated after calling toObject', () => { var seq = Seq({ a: 1, b: 2, c: 3 }); var obj = seq.toObject(); obj['c'] = 10; var seq2 = Seq(obj); expect(seq.get('c')).toEqual(3); expect(seq2.get('c')).toEqual(10); });
it('compares sequences', () => { var arraySeq = Seq.of(1,2,3); var arraySeq2 = Seq([1,2,3]); expectIs(arraySeq, arraySeq); expectIs(arraySeq, Seq.of(1,2,3)); expectIs(arraySeq2, arraySeq2); expectIs(arraySeq2, Seq([1,2,3])); expectIsNot(arraySeq, [1,2,3]); expectIsNot(arraySeq2, [1,2,3]); expectIs(arraySeq, arraySeq2); expectIs(arraySeq, arraySeq.map(x => x)); expectIs(arraySeq2, arraySeq2.map(x => x)); });
it('returns non-empty item when concat does nothing', () => { var a = Seq.of(1,2,3); var b = Seq(); expect(a.concat(b)).toBe(a); expect(b.concat(a)).toBe(a); expect(b.concat(b, b, b, a, b, b)).toBe(a); })
it('groups keyed sequence', () => { var grouped = Seq({a:1,b:2,c:3,d:4}).groupBy(x => x % 2); expect(grouped.toJS()).toEqual({1:{a:1,c:3}, 0:{b:2,d:4}}); // Each group should be a keyed sequence, not an indexed sequence expect(grouped.get(1).toArray()).toEqual([1, 3]); })
it('is stable', () => { var i = new SimpleIterable(); var s = Seq(i); expect(s.take(5).toArray()).toEqual([ 0,1,2,3,4 ]); expect(s.take(5).toArray()).toEqual([ 0,1,2,3,4 ]); expect(s.take(5).toArray()).toEqual([ 0,1,2,3,4 ]); })