| 
 | 1 | +import {getStreaks} from './getStreaks.js';  | 
 | 2 | + | 
 | 3 | +describe('getStreaks', () => {  | 
 | 4 | +  const input = [10, 20, 30, 40, 32, 42, 50, 45, 44, 41, 59, 90, 100];  | 
 | 5 | + | 
 | 6 | +  describe('uptrends', () => {  | 
 | 7 | +    it('keeps track of upward streak lengths', () => {  | 
 | 8 | +      const actual = getStreaks(input, 'up');  | 
 | 9 | +      expect(actual.map(s => s.length)).toStrictEqual([3, 2, 3]);  | 
 | 10 | +    });  | 
 | 11 | + | 
 | 12 | +    it('keeps track of price increases during an upward streak', () => {  | 
 | 13 | +      const actual = getStreaks(input, 'up');  | 
 | 14 | +      expect(actual.map(s => s.percentage)).toStrictEqual([300, 56.25, 143.90243902439025]);  | 
 | 15 | +    });  | 
 | 16 | +  });  | 
 | 17 | + | 
 | 18 | +  describe('downtrends', () => {  | 
 | 19 | +    it('keeps track of downward streak lengths', () => {  | 
 | 20 | +      const actual = getStreaks(input, 'down');  | 
 | 21 | +      expect(actual.map(s => s.length)).toStrictEqual([1, 3]);  | 
 | 22 | +    });  | 
 | 23 | + | 
 | 24 | +    it('keeps track of price decreases during a downward streak', () => {  | 
 | 25 | +      const actual = getStreaks(input, 'down');  | 
 | 26 | +      expect(actual.map(s => s.percentage)).toStrictEqual([-20, -18]);  | 
 | 27 | +    });  | 
 | 28 | +  });  | 
 | 29 | + | 
 | 30 | +  describe('special cases', () => {  | 
 | 31 | +    it("doesn't record a streak of 1", () => {  | 
 | 32 | +      const actual = getStreaks([1], 'up');  | 
 | 33 | +      expect(actual.map(s => s.length)).toStrictEqual([]);  | 
 | 34 | +    });  | 
 | 35 | +  });  | 
 | 36 | +});  | 
0 commit comments