diff --git a/Hashes/tests/SHA256.test.js b/Hashes/tests/SHA256.test.js new file mode 100644 index 0000000000..1ffb236cea --- /dev/null +++ b/Hashes/tests/SHA256.test.js @@ -0,0 +1,27 @@ +import { describe, test } from 'vitest' +import { SHA256 } from '../SHA256' + +describe('Testing SHA256 function', () => { + it.each([ + ['', 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'], + [ + 'The quick brown fox jumps over the lazy dog', + 'd7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592' + ], + [ + 'The quick brown fox jumps over the lazy cog', + 'e4c4d8f3bf76b692de791a173e05321150f7a345b46484fe427f6acc7ecc81be' + ], + [ + 'This was added by vil02 on 01.02.2024. Have a nice day!', + '476025d91db754ab6ac0c124367afd7c108d041b2f497006a214d5035769ed5d' + ], + [ + '012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789', + '14582b3f153941891dca966b036a5b1de65fa3b7a2540095a31614da1de0feaf' + ], + ['a', 'ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb'] + ])('check with %j', (input, expected) => { + expect(SHA256(input)).toBe(expected) + }) +}) diff --git a/Maths/PascalTriangle.js b/Maths/PascalTriangle.js index 868e36fcac..71d782cd61 100644 --- a/Maths/PascalTriangle.js +++ b/Maths/PascalTriangle.js @@ -17,8 +17,6 @@ const generate = (numRows) => { return [] } else if (numRows === 1) { return [[1]] - } else if (numRows === 2) { - return [[1], [1, 1]] } else { for (let i = 2; i < numRows; i++) { addRow(triangle) diff --git a/Maths/test/PascalTriangle.test.js b/Maths/test/PascalTriangle.test.js index 314d0f3211..65c736f14f 100644 --- a/Maths/test/PascalTriangle.test.js +++ b/Maths/test/PascalTriangle.test.js @@ -1,20 +1,20 @@ +import { expect } from 'vitest' import { generate } from '../PascalTriangle' describe('Pascals Triangle', () => { - it('should have the the same length as the number', () => { - const pascalsTriangle = generate(5) - expect(pascalsTriangle.length).toEqual(5) - }) - it('should have same length as its index in the array', () => { - const pascalsTriangle = generate(5) + it.each([ + [0, []], + [1, [[1]]], + [2, [[1], [1, 1]]], + [3, [[1], [1, 1], [1, 2, 1]]], + [4, [[1], [1, 1], [1, 2, 1], [1, 3, 3, 1]]], + [5, [[1], [1, 1], [1, 2, 1], [1, 3, 3, 1]], [1, 4, 6, 4, 1]] + ])('check with %j', (input, expected) => { + const pascalsTriangle = generate(input) + expect(pascalsTriangle.length).toEqual(input) pascalsTriangle.forEach((arr, index) => { expect(arr.length).toEqual(index + 1) }) - }) - it('should return an array of arrays', () => { - const pascalsTriangle = generate(3) - expect(pascalsTriangle).toEqual( - expect.arrayContaining([[1], [1, 1], [1, 2, 1]]) - ) + expect(pascalsTriangle).toEqual(expect.arrayContaining(expected)) }) }) diff --git a/Maths/test/SumOfGeometricProgression.test.js b/Maths/test/SumOfGeometricProgression.test.js index f459835232..0edf2b9f8e 100644 --- a/Maths/test/SumOfGeometricProgression.test.js +++ b/Maths/test/SumOfGeometricProgression.test.js @@ -8,4 +8,8 @@ describe('Sum Of Geometric Progression', () => { it('should return the sum of an infinite GP', () => { expect(sumOfGeometricProgression(2, 0.5, Infinity)).toBe(4) }) + + it('should throw when series diverges', () => { + expect(() => sumOfGeometricProgression(1, 1, Infinity)).toThrowError() + }) })