From cee96522bf745746e8190d80bd829989a15c45a4 Mon Sep 17 00:00:00 2001 From: Piotr Idzik Date: Mon, 29 Jan 2024 15:48:17 +0000 Subject: [PATCH 1/2] tests: add tests for `SHA1` --- Hashes/tests/SHA1.test.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Hashes/tests/SHA1.test.js diff --git a/Hashes/tests/SHA1.test.js b/Hashes/tests/SHA1.test.js new file mode 100644 index 0000000000..c17dc9dccf --- /dev/null +++ b/Hashes/tests/SHA1.test.js @@ -0,0 +1,38 @@ +import { describe, test } from 'vitest' +import { SHA1 } from '../SHA1' + +describe('Testing SHA1 function', () => { + const TEST_CASES = [ + { args: [''], expected: 'da39a3ee5e6b4b0d3255bfef95601890afd80709' }, + { + args: ['The quick brown fox jumps over the lazy dog'], + expected: '2fd4e1c67a2d28fced849ee1bb76e7391b93eb12' + }, + { + args: ['The quick brown fox jumps over the lazy cog'], + expected: 'de9f2c7fd25e1b3afad3e85a0bd17d9b100db4b3' + }, + { args: ['a'], expected: '86f7e437faa5a7fce15d1ddcb9eaeaea377667b8' }, + { + args: ['Today is 29.01.2024!'], + expected: 'ae829b60d11fb5ab527d5db2501e06da3402718d' + }, + { + args: ['Have a nice day.'], + expected: 'ed51dd3909281c25db5e1d8b1ce6fc701fda20ab' + }, + { + args: [ + '12345678901234567890123456789012345678901234567890123456789012345678901234567890' + ], + expected: '50abf5706a150990a08b2c5ea40fa0e585554732' + } + ] + + TEST_CASES.forEach((testCase) => { + it(`check with ${JSON.stringify(testCase.args)}`, () => { + const result = SHA1.apply(this, testCase.args) + expect(testCase.expected).toEqual(result) + }) + }) +}) From 9c5e0e4faa8d16abfbb58f6789bee927cbcb32d7 Mon Sep 17 00:00:00 2001 From: vil02 Date: Mon, 29 Jan 2024 20:58:32 +0100 Subject: [PATCH 2/2] style: use `it.each` --------- Co-authored-by: appgurueu <34514239+appgurueu@users.noreply.github.com> --- Hashes/tests/SHA1.test.js | 51 +++++++++++++++------------------------ 1 file changed, 19 insertions(+), 32 deletions(-) diff --git a/Hashes/tests/SHA1.test.js b/Hashes/tests/SHA1.test.js index c17dc9dccf..8032e29908 100644 --- a/Hashes/tests/SHA1.test.js +++ b/Hashes/tests/SHA1.test.js @@ -2,37 +2,24 @@ import { describe, test } from 'vitest' import { SHA1 } from '../SHA1' describe('Testing SHA1 function', () => { - const TEST_CASES = [ - { args: [''], expected: 'da39a3ee5e6b4b0d3255bfef95601890afd80709' }, - { - args: ['The quick brown fox jumps over the lazy dog'], - expected: '2fd4e1c67a2d28fced849ee1bb76e7391b93eb12' - }, - { - args: ['The quick brown fox jumps over the lazy cog'], - expected: 'de9f2c7fd25e1b3afad3e85a0bd17d9b100db4b3' - }, - { args: ['a'], expected: '86f7e437faa5a7fce15d1ddcb9eaeaea377667b8' }, - { - args: ['Today is 29.01.2024!'], - expected: 'ae829b60d11fb5ab527d5db2501e06da3402718d' - }, - { - args: ['Have a nice day.'], - expected: 'ed51dd3909281c25db5e1d8b1ce6fc701fda20ab' - }, - { - args: [ - '12345678901234567890123456789012345678901234567890123456789012345678901234567890' - ], - expected: '50abf5706a150990a08b2c5ea40fa0e585554732' - } - ] - - TEST_CASES.forEach((testCase) => { - it(`check with ${JSON.stringify(testCase.args)}`, () => { - const result = SHA1.apply(this, testCase.args) - expect(testCase.expected).toEqual(result) - }) + it.each([ + ['', 'da39a3ee5e6b4b0d3255bfef95601890afd80709'], + [ + 'The quick brown fox jumps over the lazy dog', + '2fd4e1c67a2d28fced849ee1bb76e7391b93eb12' + ], + [ + 'The quick brown fox jumps over the lazy cog', + 'de9f2c7fd25e1b3afad3e85a0bd17d9b100db4b3' + ], + ['a', '86f7e437faa5a7fce15d1ddcb9eaeaea377667b8'], + ['Today is 29.01.2024!', 'ae829b60d11fb5ab527d5db2501e06da3402718d'], + ['Have a nice day.', 'ed51dd3909281c25db5e1d8b1ce6fc701fda20ab'], + [ + '12345678901234567890123456789012345678901234567890123456789012345678901234567890', + '50abf5706a150990a08b2c5ea40fa0e585554732' + ] + ])('check with %j', (input, expected) => { + expect(SHA1(input)).toBe(expected) }) }) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy