generated from cdelaorden/node-ts-service
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fc81760
commit b874f1f
Showing
3 changed files
with
90 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,56 @@ | ||
import { explode } from '@/lib/utils' | ||
import { calculateDifferences, expandWithDifferences } from '.' | ||
import { | ||
calculateDifferences, | ||
calculateNext, | ||
isAllZeros, | ||
makeHistory, | ||
parseInput, | ||
reduceHistories, | ||
} from '.' | ||
|
||
describe('calculateDifferences', () => { | ||
it('creates a new Array with differences', () => { | ||
const result = calculateDifferences([0, 3, 6, 9, 12, 15]) | ||
expect(result).toEqual([3, 3, 3, 3, 3]) | ||
const result2 = calculateDifferences(result) | ||
expect(result2).toEqual([0, 0, 0, 0]) | ||
describe('Day 9 Mirage maintenance', () => { | ||
describe('parseInput', () => { | ||
it('generates array of histories', () => { | ||
expect(parseInput('0 3 6 9 12 15\n1 2 3 4')).toEqual([ | ||
[0, 3, 6, 9, 12, 15], | ||
[1, 2, 3, 4], | ||
]) | ||
}) | ||
}) | ||
}) | ||
|
||
describe('expandWithDifferences', () => { | ||
it('creates an Array of dimishing differences from original row', () => { | ||
const result = expandWithDifferences([0, 3, 6, 9, 12, 15]) | ||
expect(result).toEqual([ | ||
[0, 3, 6, 9, 12, 15], | ||
[3, 3, 3, 3, 3], | ||
[0, 0, 0, 0], | ||
]) | ||
describe('isAllZeros', () => { | ||
it('returns true if array is composed of only 0s', () => { | ||
expect(isAllZeros([0])).toBe(true) | ||
expect(isAllZeros([])).toBe(true) | ||
expect(isAllZeros([1, 0])).toBe(false) | ||
}) | ||
}) | ||
describe('calculateDifferences', () => { | ||
it('creates a new Array with differences', () => { | ||
const result = calculateDifferences([0, 3, 6, 9, 12, 15]) | ||
expect(result).toEqual([3, 3, 3, 3, 3]) | ||
const result2 = calculateDifferences(result) | ||
expect(result2).toEqual([0, 0, 0, 0]) | ||
}) | ||
}) | ||
|
||
it('handles neg values', () => { | ||
const result = expandWithDifferences( | ||
explode( | ||
'-9 -13 -17 -21 -25 -29 -33 -37 -41 -45 -49 -53 -57 -61 -65 -69 -73 -77 -81 -85 -89', | ||
' ' | ||
).map(Number) | ||
) | ||
expect(result).toMatchSnapshot() | ||
describe('reduceHistories (recursive)', () => { | ||
it('generates prev histories', () => { | ||
const result = reduceHistories([0, 3, 6, 9, 12, 15]) | ||
expect(result).toMatchSnapshot() | ||
}) | ||
}) | ||
describe('calculateNext', () => { | ||
it('returns the next value in the history', () => { | ||
expect(calculateNext([0, 3, 6, 9, 12, 15])).toBe(18) | ||
expect(calculateNext([1, 3, 6, 10, 15, 21])).toBe(28) | ||
expect(calculateNext([10, 13, 16, 21, 30, 45])).toBe(68) | ||
expect( | ||
calculateNext( | ||
makeHistory('9 8 7 6 5 4 3 2 1 0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11') | ||
) | ||
).toBe(-12) | ||
expect(calculateNext(makeHistory('-9 -13 -17 -21 -25 -29 -33 -37'))).toBe( | ||
-41 | ||
) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters