feat: Test running overhaul, switch to Prettier & reformat everything (#1407)

* chore: Switch to Node 20 + Vitest

* chore: migrate to vitest mock functions

* chore: code style (switch to prettier)

* test: re-enable long-running test

Seems the switch to Node 20 and Vitest has vastly improved the code's and / or the test's runtime!

see #1193

* chore: code style

* chore: fix failing tests

* Updated Documentation in README.md

* Update contribution guidelines to state usage of Prettier

* fix: set prettier printWidth back to 80

* chore: apply updated code style automatically

* fix: set prettier line endings to lf again

* chore: apply updated code style automatically

---------

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Co-authored-by: Lars Müller <34514239+appgurueu@users.noreply.github.com>
This commit is contained in:
Roland Hummel
2023-10-03 23:08:19 +02:00
committed by GitHub
parent 0ca18c2b2c
commit 86d333ee94
392 changed files with 5849 additions and 16622 deletions

View File

@@ -1,22 +1,22 @@
import { AlternativeStringArrange } from '../AlternativeStringArrange'
test('AlternativeStringArrange(Agrtm, loih) -> Algorithm', () => {
const str1 = 'Agrtm'
const str2 = 'loih'
const res = AlternativeStringArrange(str1, str2)
expect(res).toEqual('Algorithm')
})
test('AlternativeStringArrange(JvSrp, aacit) -> JavaScript', () => {
const str1 = 'JvSrp'
const str2 = 'aacit'
const res = AlternativeStringArrange(str1, str2)
expect(res).toEqual('JavaScript')
})
test('AlternativeStringArrange(abc, def) -> adbecf', () => {
const str1 = 'abc'
const str2 = 'def'
const res = AlternativeStringArrange(str1, str2)
expect(res).toEqual('adbecf')
})
import { AlternativeStringArrange } from '../AlternativeStringArrange'
test('AlternativeStringArrange(Agrtm, loih) -> Algorithm', () => {
const str1 = 'Agrtm'
const str2 = 'loih'
const res = AlternativeStringArrange(str1, str2)
expect(res).toEqual('Algorithm')
})
test('AlternativeStringArrange(JvSrp, aacit) -> JavaScript', () => {
const str1 = 'JvSrp'
const str2 = 'aacit'
const res = AlternativeStringArrange(str1, str2)
expect(res).toEqual('JavaScript')
})
test('AlternativeStringArrange(abc, def) -> adbecf', () => {
const str1 = 'abc'
const str2 = 'def'
const res = AlternativeStringArrange(str1, str2)
expect(res).toEqual('adbecf')
})

View File

@@ -12,9 +12,7 @@ describe('Testing checkAnagramRegex', () => {
`(
'expects to throw the type Error given values $inputOne and $inputTwo',
({ inputOne, inputTwo }) => {
expect(
() => checkAnagramRegex(inputOne, inputTwo)
).toThrowError()
expect(() => checkAnagramRegex(inputOne, inputTwo)).toThrowError()
}
)
@@ -102,9 +100,7 @@ describe('Testing checkAnagramMap', () => {
`(
'expects to throw the type Error given values $inputOne and $inputTwo',
({ inputOne, inputTwo }) => {
expect(
() => checkAnagramMap(inputOne, inputTwo)
).toThrowError()
expect(() => checkAnagramMap(inputOne, inputTwo)).toThrowError()
}
)

View File

@@ -2,7 +2,9 @@ import { checkExceeding } from '../CheckExceeding'
describe('Testing CheckExceeding function', () => {
it('Testing the invalid types', () => {
expect(() => checkExceeding(Math.random())).toThrow('Argument is not a string')
expect(() => checkExceeding(Math.random())).toThrow(
'Argument is not a string'
)
expect(() => checkExceeding(null)).toThrow('Argument is not a string')
expect(() => checkExceeding(false)).toThrow('Argument is not a string')
expect(() => checkExceeding(false)).toThrow('Argument is not a string')

View File

@@ -1,13 +1,13 @@
import { CheckKebabCase } from '../CheckKebabCase'
test('CheckKebabCase(The-Algorithms) -> true', () => {
const word = 'The-Algorithms'
const res = CheckKebabCase(word)
expect(res).toBeTruthy()
})
test('CheckKebabCase(The Algorithms) -> false', () => {
const word = 'The Algorithms'
const res = CheckKebabCase(word)
expect(res).toBeFalsy()
})
import { CheckKebabCase } from '../CheckKebabCase'
test('CheckKebabCase(The-Algorithms) -> true', () => {
const word = 'The-Algorithms'
const res = CheckKebabCase(word)
expect(res).toBeTruthy()
})
test('CheckKebabCase(The Algorithms) -> false', () => {
const word = 'The Algorithms'
const res = CheckKebabCase(word)
expect(res).toBeFalsy()
})

View File

@@ -8,7 +8,9 @@ describe('Testing checkPangramRegex function', () => {
})
it('"Waltz, bad nymph, for quick jigs vex." is a pangram', () => {
expect(checkPangramRegex('Waltz, bad nymph, for quick jigs vex.')).toBe(true)
expect(checkPangramRegex('Waltz, bad nymph, for quick jigs vex.')).toBe(
true
)
})
it('"Jived fox nymph grabs quick waltz." is a pangram', () => {
@@ -34,9 +36,9 @@ describe('Testing checkPangramRegex function', () => {
describe('Testing checkPangramSet function', () => {
it('"The quick brown fox jumps over the lazy dog" is a pangram', () => {
expect(
checkPangramSet('The quick brown fox jumps over the lazy dog')
).toBe(true)
expect(checkPangramSet('The quick brown fox jumps over the lazy dog')).toBe(
true
)
})
it('"Waltz, bad nymph, for quick jigs vex." is a pangram', () => {
@@ -52,9 +54,9 @@ describe('Testing checkPangramSet function', () => {
})
it('"The quick brown fox jumps over the la_y dog" is NOT a pangram', () => {
expect(
checkPangramSet('The quick brown fox jumps over the la_y dog')
).toBe(false)
expect(checkPangramSet('The quick brown fox jumps over the la_y dog')).toBe(
false
)
})
it('Throws an error if given param is not a string', () => {

View File

@@ -1,19 +1,19 @@
import { CheckPascalCase } from '../CheckPascalCase'
test('CheckPascalCase(TheAlgorithms) -> true', () => {
const word = 'TheAlgorithms'
const res = CheckPascalCase(word)
expect(res).toBeTruthy()
})
test('CheckPascalCase(theAlgorithms) -> false', () => {
const word = 'theAlgorithms'
const res = CheckPascalCase(word)
expect(res).toBeFalsy()
})
test('CheckPascalCase(The Algorithms) -> false', () => {
const word = 'The Algorithms'
const res = CheckPascalCase(word)
expect(res).toBeFalsy()
})
import { CheckPascalCase } from '../CheckPascalCase'
test('CheckPascalCase(TheAlgorithms) -> true', () => {
const word = 'TheAlgorithms'
const res = CheckPascalCase(word)
expect(res).toBeTruthy()
})
test('CheckPascalCase(theAlgorithms) -> false', () => {
const word = 'theAlgorithms'
const res = CheckPascalCase(word)
expect(res).toBeFalsy()
})
test('CheckPascalCase(The Algorithms) -> false', () => {
const word = 'The Algorithms'
const res = CheckPascalCase(word)
expect(res).toBeFalsy()
})

View File

@@ -1,25 +1,25 @@
import { palindromeRearranging } from '../CheckRearrangePalindrome'
test('palindromeRearranging(apple) -> false', () => {
const word = 'apple'
const res = palindromeRearranging(word)
expect(res).toBeFalsy()
})
test('palindromeRearranging(aapplle) -> true', () => {
const word = 'aapplle'
const res = palindromeRearranging(word)
expect(res).toBeTruthy()
})
test('palindromeRearranging(value) -> false', () => {
const word = 'value'
const res = palindromeRearranging(word)
expect(res).toBeFalsy()
})
test('palindromeRearranging(aaeccrr) -> true', () => {
const word = 'aaeccrr'
const res = palindromeRearranging(word)
expect(res).toBeTruthy()
})
import { palindromeRearranging } from '../CheckRearrangePalindrome'
test('palindromeRearranging(apple) -> false', () => {
const word = 'apple'
const res = palindromeRearranging(word)
expect(res).toBeFalsy()
})
test('palindromeRearranging(aapplle) -> true', () => {
const word = 'aapplle'
const res = palindromeRearranging(word)
expect(res).toBeTruthy()
})
test('palindromeRearranging(value) -> false', () => {
const word = 'value'
const res = palindromeRearranging(word)
expect(res).toBeFalsy()
})
test('palindromeRearranging(aaeccrr) -> true', () => {
const word = 'aaeccrr'
const res = palindromeRearranging(word)
expect(res).toBeTruthy()
})

View File

@@ -15,14 +15,33 @@ describe('Testing checkWordOccurrence', () => {
it('check occurrence with case sensitive', () => {
const stringToTest = 'The quick brown fox jumps over the lazy dog'
const expectResult = { The: 1, quick: 1, brown: 1, fox: 1, jumps: 1, over: 1, the: 1, lazy: 1, dog: 1 }
const expectResult = {
The: 1,
quick: 1,
brown: 1,
fox: 1,
jumps: 1,
over: 1,
the: 1,
lazy: 1,
dog: 1
}
expect(checkWordOccurrence(stringToTest)).toEqual(expectResult)
})
it('check occurrence with case insensitive', () => {
const stringToTest = 'The quick brown fox jumps over the lazy dog'
const expectResult = { the: 2, quick: 1, brown: 1, fox: 1, jumps: 1, over: 1, lazy: 1, dog: 1 }
const expectResult = {
the: 2,
quick: 1,
brown: 1,
fox: 1,
jumps: 1,
over: 1,
lazy: 1,
dog: 1
}
expect(checkWordOccurrence(stringToTest, true)).toEqual(expectResult)
})

View File

@@ -3,7 +3,9 @@ import formatPhoneNumber from '../FormatPhoneNumber'
describe('Testing the formatPhoneNumber functions', () => {
it('expects to throw a type error', () => {
expect(() => formatPhoneNumber('1234567')).toThrow('Invalid phone number!')
expect(() => formatPhoneNumber('123456text')).toThrow('Invalid phone number!')
expect(() => formatPhoneNumber('123456text')).toThrow(
'Invalid phone number!'
)
expect(() => formatPhoneNumber(12345)).toThrow('Invalid phone number!')
})

View File

@@ -12,7 +12,7 @@ describe('LengthOfLongestSubstring', () => {
expect(lengthOfLongestSubstring('bbbbb')).toBe(1)
expect(lengthOfLongestSubstring('pwwkew')).toBe(3)
expect(lengthOfLongestSubstring(' ')).toBe(1)
expect(lengthOfLongestSubstring('abcdefghijklmnaaaaa')).toBe(13)
expect(lengthOfLongestSubstring('abcdefghijklmnaaaaa')).toBe(14)
})
it('should give zero for empty strings', () => {
@@ -20,7 +20,7 @@ describe('LengthOfLongestSubstring', () => {
})
it('should be case-sensitive', () => {
expect(lengthOfLongestSubstring('AaBbCc')).toBe(3)
expect(lengthOfLongestSubstring('AaBbCc')).toBe(6)
expect(lengthOfLongestSubstring('AbCdEf')).toBe(6)
})
})

View File

@@ -7,7 +7,7 @@ describe('Testing the maxCharacter function', () => {
})
it('Check the max character in string', () => {
const theString = 'I can\'t do that'
const theString = "I can't do that"
const maxCharInAllCount = maxCharacter(theString)
const maxChar = maxCharacter(theString, /\s/)

View File

@@ -2,7 +2,9 @@ import { permutate } from '../PermutateString'
describe('Permutate a string', () => {
it('expects to throw an Error with an empty string', () => {
expect(() => { permutate() }).toThrow('The arg must be a valid, non empty string')
expect(() => {
permutate()
}).toThrow('The arg must be a valid, non empty string')
})
it('expects to permute "no" into [no, on]', () => {
expect(['no', 'on']).toEqual(permutate('no'))
@@ -11,7 +13,19 @@ describe('Permutate a string', () => {
expect(['esy', 'eys', 'sey', 'sye', 'yes', 'yse']).toEqual(permutate('yes'))
})
it('expects to permute "good" into [dgoo dogo doog gdoo godo good odgo odog ogdo ogod oodg oogd ]', () => {
expect(['dgoo', 'dogo', 'doog', 'gdoo', 'godo', 'good', 'odgo', 'odog', 'ogdo', 'ogod', 'oodg', 'oogd'])
.toEqual(permutate('good'))
expect([
'dgoo',
'dogo',
'doog',
'gdoo',
'godo',
'good',
'odgo',
'odog',
'ogdo',
'ogod',
'oodg',
'oogd'
]).toEqual(permutate('good'))
})
})

View File

@@ -1,11 +1,16 @@
import { ReverseStringIterative, ReverseStringIterativeInplace } from '../ReverseString'
import {
ReverseStringIterative,
ReverseStringIterativeInplace
} from '../ReverseString'
describe('ReverseStringIterative', () => {
it('expects to reverse a simple string', () => {
expect(ReverseStringIterative('reverse')).toEqual('esrever')
expect(ReverseStringIterative('some')).toEqual('emos')
expect(ReverseStringIterative('string')).toEqual('gnirts')
expect(ReverseStringIterative('The Algorithms Javascript')).toEqual('tpircsavaJ smhtiroglA ehT')
expect(ReverseStringIterative('The Algorithms Javascript')).toEqual(
'tpircsavaJ smhtiroglA ehT'
)
})
it('expects to reverse a string with spaces in between', () => {
@@ -25,7 +30,9 @@ describe('ReverseStringIterative', () => {
`(
'expects to throw a type error given a value that is $input',
({ input }) => {
expect(() => ReverseStringIterative(input)).toThrow('The given value is not a string')
expect(() => ReverseStringIterative(input)).toThrow(
'The given value is not a string'
)
}
)

View File

@@ -19,6 +19,8 @@ describe('Testing the reverseWords function', () => {
it('expects to reverse words to return a joined word', () => {
expect(reverseWords('I Love JS')).toBe('JS Love I')
expect(reverseWords('Hello World')).toBe('World Hello')
expect(reverseWords('The Algorithms Javascript')).toBe('Javascript Algorithms The')
expect(reverseWords('The Algorithms Javascript')).toBe(
'Javascript Algorithms The'
)
})
})

View File

@@ -14,26 +14,48 @@ describe('Validate credit card number', () => {
})
it('should throw an error on non-numeric character in given credit card number', () => {
const nonNumericCCNumbers = ['123ABCDEF', 'ABCDKDKD', 'ADS232']
nonNumericCCNumbers.forEach(nonNumericCC => expect(() => validateCreditCard(nonNumericCC)).toThrow(
`${nonNumericCC} is an invalid credit card number because ` + 'it has nonnumerical characters.'
))
nonNumericCCNumbers.forEach((nonNumericCC) =>
expect(() => validateCreditCard(nonNumericCC)).toThrow(
`${nonNumericCC} is an invalid credit card number because ` +
'it has nonnumerical characters.'
)
)
})
it('should throw an error on credit card with invalid length', () => {
const ccWithInvalidLength = ['41111', '4111111111111111111111']
ccWithInvalidLength.forEach(invalidCC => expect(() => validateCreditCard(invalidCC)).toThrow(
`${invalidCC} is an invalid credit card number because ` + 'of its length.'
))
ccWithInvalidLength.forEach((invalidCC) =>
expect(() => validateCreditCard(invalidCC)).toThrow(
`${invalidCC} is an invalid credit card number because ` +
'of its length.'
)
)
})
it('should throw an error on credit card with invalid start substring', () => {
const ccWithInvalidStartSubstring = ['12345678912345', '23456789123456', '789123456789123', '891234567891234', '912345678912345', '31345678912345', '32345678912345', '33345678912345', '38345678912345']
ccWithInvalidStartSubstring.forEach(invalidCC => expect(() => validateCreditCard(invalidCC)).toThrow(
`${invalidCC} is an invalid credit card number because ` + 'of its first two digits.'
))
const ccWithInvalidStartSubstring = [
'12345678912345',
'23456789123456',
'789123456789123',
'891234567891234',
'912345678912345',
'31345678912345',
'32345678912345',
'33345678912345',
'38345678912345'
]
ccWithInvalidStartSubstring.forEach((invalidCC) =>
expect(() => validateCreditCard(invalidCC)).toThrow(
`${invalidCC} is an invalid credit card number because ` +
'of its first two digits.'
)
)
})
it('should throw an error on credit card with luhn check fail', () => {
const invalidCCs = ['411111111111111', '371211111111111', '49999999999999']
invalidCCs.forEach(invalidCC => expect(() => validateCreditCard(invalidCC)).toThrow(
`${invalidCC} is an invalid credit card number because ` + 'it fails the Luhn check.'
))
invalidCCs.forEach((invalidCC) =>
expect(() => validateCreditCard(invalidCC)).toThrow(
`${invalidCC} is an invalid credit card number because ` +
'it fails the Luhn check.'
)
)
})
})

View File

@@ -18,7 +18,11 @@ describe('Validation of an Email Address', () => {
})
it('expects to throw a type error', () => {
expect(() => { validateEmail('') }).toThrow('Email Address String Null or Empty.')
expect(() => { validateEmail(null) }).toThrow('Email Address String Null or Empty.')
expect(() => {
validateEmail('')
}).toThrow('Email Address String Null or Empty.')
expect(() => {
validateEmail(null)
}).toThrow('Email Address String Null or Empty.')
})
})