|
| 1 | +// some parts tested on src/data-structures/maps/map.spec.js |
| 2 | + |
| 3 | +const TreeMap = require('./tree-map'); |
| 4 | + |
| 5 | +describe('TreeMap: keep values sorted', () => { |
| 6 | + let map; |
| 7 | + |
| 8 | + beforeEach(() => { |
| 9 | + map = new TreeMap(); |
| 10 | + }); |
| 11 | + |
| 12 | + describe('when map is empty', () => { |
| 13 | + describe('.lastEntry and .firstEntry', () => { |
| 14 | + it('should get last/first entry', () => { |
| 15 | + expect(map.lastEntry()).toEqual([]); |
| 16 | + expect(map.firstEntry()).toEqual([]); |
| 17 | + }); |
| 18 | + }); |
| 19 | + }); |
| 20 | + |
| 21 | + describe('when map has entries', () => { |
| 22 | + beforeEach(() => { |
| 23 | + map.set(20, { title: '3sum', passed: true }); |
| 24 | + map.set(30, { title: '3sum', passed: false }); |
| 25 | + map.set(10, { title: '2sum', passed: true }); |
| 26 | + map.set(5, { title: '4sum', passed: false }); |
| 27 | + }); |
| 28 | + |
| 29 | + describe('.lastEntry and .firstEntry', () => { |
| 30 | + it('should get last/first entry', () => { |
| 31 | + expect(map.lastEntry()).toEqual([ |
| 32 | + 30, |
| 33 | + { title: '3sum', passed: false }, |
| 34 | + ]); |
| 35 | + |
| 36 | + expect(map.firstEntry()).toEqual([ |
| 37 | + 5, |
| 38 | + { title: '4sum', passed: false }, |
| 39 | + ]); |
| 40 | + }); |
| 41 | + }); |
| 42 | + }); |
| 43 | +}); |
0 commit comments