mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2026-03-13 15:21:15 +08:00
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:
@@ -1,4 +1,7 @@
|
||||
import { convertArbitraryBase, convertArbitraryBaseBigIntVersion } from '../ArbitraryBase'
|
||||
import {
|
||||
convertArbitraryBase,
|
||||
convertArbitraryBaseBigIntVersion
|
||||
} from '../ArbitraryBase'
|
||||
|
||||
test('Check the answer of convertArbitraryBase(98, 0123456789, 01234567) is 142', () => {
|
||||
const res = convertArbitraryBase('98', '0123456789', '01234567')
|
||||
|
||||
@@ -14,6 +14,8 @@ describe('BinaryToHex', () => {
|
||||
})
|
||||
|
||||
it('expects to return correct hexadecimal value, matching (num).toString(16)', () => {
|
||||
expect(binaryToHex('1111')).toBe(parseInt('1111', 2).toString(16).toUpperCase())
|
||||
expect(binaryToHex('1111')).toBe(
|
||||
parseInt('1111', 2).toString(16).toUpperCase()
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import { hexStringToRGB } from '../HexToRGB'
|
||||
|
||||
test('The RGB form of Hex String E1E1E1 is {r: 225, g: 225, b: 225}', () => {
|
||||
const res = hexStringToRGB('E1E1E1')
|
||||
expect(res).toEqual({ r: 225, g: 225, b: 225 })
|
||||
})
|
||||
|
||||
test('The RGB form of Hex String 000000 is {r: 0, g: 0, b: 0}', () => {
|
||||
const res = hexStringToRGB('000000')
|
||||
expect(res).toEqual({ r: 0, g: 0, b: 0 })
|
||||
})
|
||||
|
||||
test('The RGB form of Hex String 6CE1CD is {r: 108, g: 225, b: 205}', () => {
|
||||
const res = hexStringToRGB('6CE1CD')
|
||||
expect(res).toEqual({ r: 108, g: 225, b: 205 })
|
||||
})
|
||||
import { hexStringToRGB } from '../HexToRGB'
|
||||
|
||||
test('The RGB form of Hex String E1E1E1 is {r: 225, g: 225, b: 225}', () => {
|
||||
const res = hexStringToRGB('E1E1E1')
|
||||
expect(res).toEqual({ r: 225, g: 225, b: 225 })
|
||||
})
|
||||
|
||||
test('The RGB form of Hex String 000000 is {r: 0, g: 0, b: 0}', () => {
|
||||
const res = hexStringToRGB('000000')
|
||||
expect(res).toEqual({ r: 0, g: 0, b: 0 })
|
||||
})
|
||||
|
||||
test('The RGB form of Hex String 6CE1CD is {r: 108, g: 225, b: 205}', () => {
|
||||
const res = hexStringToRGB('6CE1CD')
|
||||
expect(res).toEqual({ r: 108, g: 225, b: 205 })
|
||||
})
|
||||
|
||||
@@ -2,11 +2,11 @@ import { lengthConversion } from '../LengthConversion.js'
|
||||
|
||||
describe('LengthConversion', () => {
|
||||
it.each`
|
||||
length | fromUnit | toUnit | expected
|
||||
${10} | ${'km'} | ${'m'} | ${10000}
|
||||
${100} | ${'m'} | ${'km'} | ${0.1}
|
||||
${5} | ${'cm'} | ${'mm'} | ${50}
|
||||
${12} | ${'ft'} | ${'inch'}| ${144.00000000000003}
|
||||
length | fromUnit | toUnit | expected
|
||||
${10} | ${'km'} | ${'m'} | ${10000}
|
||||
${100} | ${'m'} | ${'km'} | ${0.1}
|
||||
${5} | ${'cm'} | ${'mm'} | ${50}
|
||||
${12} | ${'ft'} | ${'inch'} | ${144.00000000000003}
|
||||
`(
|
||||
'converts $length $fromUnit to $toUnit',
|
||||
({ length, fromUnit, toUnit, expected }) => {
|
||||
@@ -20,10 +20,10 @@ describe('LengthConversion', () => {
|
||||
)
|
||||
|
||||
it.each`
|
||||
length | fromUnit | toUnit | expected
|
||||
${10} | ${'m'} | ${'km'} | ${0.01}
|
||||
${1000}| ${'mm'} | ${'cm'} | ${100}
|
||||
${1} | ${'inch'}| ${'ft'} | ${0.08333333333}
|
||||
length | fromUnit | toUnit | expected
|
||||
${10} | ${'m'} | ${'km'} | ${0.01}
|
||||
${1000} | ${'mm'} | ${'cm'} | ${100}
|
||||
${1} | ${'inch'} | ${'ft'} | ${0.08333333333}
|
||||
`(
|
||||
'converts $length $fromUnit to $toUnit (vice versa)',
|
||||
({ length, fromUnit, toUnit, expected }) => {
|
||||
@@ -37,9 +37,9 @@ describe('LengthConversion', () => {
|
||||
)
|
||||
|
||||
it.each`
|
||||
length | fromUnit | toUnit | expectedError
|
||||
${10} | ${'km'} | ${'invalid'} | ${'Invalid units'}
|
||||
${5} | ${'invalid'} | ${'m'} | ${'Invalid units'}
|
||||
length | fromUnit | toUnit | expectedError
|
||||
${10} | ${'km'} | ${'invalid'} | ${'Invalid units'}
|
||||
${5} | ${'invalid'} | ${'m'} | ${'Invalid units'}
|
||||
`(
|
||||
'returns error message for invalid units: $fromUnit to $toUnit',
|
||||
({ length, fromUnit, toUnit, expectedError }) => {
|
||||
|
||||
@@ -20,14 +20,30 @@ describe('rgbToHsv', () => {
|
||||
// "approximatelyEqualHsv" needed because of small deviations due to rounding for the RGB-values
|
||||
it('should calculate the correct HSV values', () => {
|
||||
expect(approximatelyEqualHsv(rgbToHsv(0, 0, 0), [0, 0, 0])).toEqual(true)
|
||||
expect(approximatelyEqualHsv(rgbToHsv(255, 255, 255), [0, 0, 1])).toEqual(true)
|
||||
expect(approximatelyEqualHsv(rgbToHsv(255, 255, 255), [0, 0, 1])).toEqual(
|
||||
true
|
||||
)
|
||||
expect(approximatelyEqualHsv(rgbToHsv(255, 0, 0), [0, 1, 1])).toEqual(true)
|
||||
expect(approximatelyEqualHsv(rgbToHsv(255, 255, 0), [60, 1, 1])).toEqual(true)
|
||||
expect(approximatelyEqualHsv(rgbToHsv(0, 255, 0), [120, 1, 1])).toEqual(true)
|
||||
expect(approximatelyEqualHsv(rgbToHsv(0, 0, 255), [240, 1, 1])).toEqual(true)
|
||||
expect(approximatelyEqualHsv(rgbToHsv(255, 0, 255), [300, 1, 1])).toEqual(true)
|
||||
expect(approximatelyEqualHsv(rgbToHsv(64, 128, 128), [180, 0.5, 0.5])).toEqual(true)
|
||||
expect(approximatelyEqualHsv(rgbToHsv(193, 196, 224), [234, 0.14, 0.88])).toEqual(true)
|
||||
expect(approximatelyEqualHsv(rgbToHsv(128, 32, 80), [330, 0.75, 0.5])).toEqual(true)
|
||||
expect(approximatelyEqualHsv(rgbToHsv(255, 255, 0), [60, 1, 1])).toEqual(
|
||||
true
|
||||
)
|
||||
expect(approximatelyEqualHsv(rgbToHsv(0, 255, 0), [120, 1, 1])).toEqual(
|
||||
true
|
||||
)
|
||||
expect(approximatelyEqualHsv(rgbToHsv(0, 0, 255), [240, 1, 1])).toEqual(
|
||||
true
|
||||
)
|
||||
expect(approximatelyEqualHsv(rgbToHsv(255, 0, 255), [300, 1, 1])).toEqual(
|
||||
true
|
||||
)
|
||||
expect(
|
||||
approximatelyEqualHsv(rgbToHsv(64, 128, 128), [180, 0.5, 0.5])
|
||||
).toEqual(true)
|
||||
expect(
|
||||
approximatelyEqualHsv(rgbToHsv(193, 196, 224), [234, 0.14, 0.88])
|
||||
).toEqual(true)
|
||||
expect(
|
||||
approximatelyEqualHsv(rgbToHsv(128, 32, 80), [330, 0.75, 0.5])
|
||||
).toEqual(true)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,106 +1,106 @@
|
||||
import * as tc from '../TemperatureConversion.js'
|
||||
|
||||
describe('Testing Conversion of Celsius to fahrenheit', () => {
|
||||
it('with celsius value', () => {
|
||||
const test1 = tc.celsiusToFahrenheit(10)
|
||||
expect(test1).toBe(50)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Testing Conversion of Celsius to kelvin', () => {
|
||||
it('with celsius value', () => {
|
||||
const test1 = tc.celsiusToKelvin(15)
|
||||
expect(test1).toBe(288)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Testing Conversion of Celsius to Rankine', () => {
|
||||
it('with celsius value', () => {
|
||||
const test1 = tc.celsiusToRankine(28)
|
||||
expect(test1).toBe(542)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Testing Conversion of Fahrenheit to Celsius', () => {
|
||||
it('with Fahrenheit value', () => {
|
||||
const test1 = tc.fahrenheitToCelsius(134)
|
||||
expect(test1).toBe(57)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Testing Conversion of Fahrenheit to Kelvin', () => {
|
||||
it('with Fahrenheit value', () => {
|
||||
const test1 = tc.fahrenheitToKelvin(125)
|
||||
expect(test1).toBe(325)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Testing Conversion of Fahrenheit to Rankine', () => {
|
||||
it('with Fahrenheit value', () => {
|
||||
const test1 = tc.fahrenheitToRankine(10)
|
||||
expect(test1).toBe(470)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Testing Conversion of Kelvin to Celsius', () => {
|
||||
it('with Kelvin value', () => {
|
||||
const test1 = tc.kelvinToCelsius(100)
|
||||
expect(test1).toBe(-173)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Testing Conversion of Kelvin to Fahrenheit', () => {
|
||||
it('with Kelvin value', () => {
|
||||
const test1 = tc.kelvinToFahrenheit(20)
|
||||
expect(test1).toBe(-424)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Testing Conversion of Kelvin to Rankine', () => {
|
||||
it('with kelvin value', () => {
|
||||
const test1 = tc.kelvinToRankine(69)
|
||||
expect(test1).toBe(124)
|
||||
})
|
||||
})
|
||||
describe('Testing Conversion of Rankine to Celsius', () => {
|
||||
it('with Rankine value', () => {
|
||||
const test1 = tc.rankineToCelsius(234)
|
||||
expect(test1).toBe(-143)
|
||||
})
|
||||
})
|
||||
describe('Testing Conversion of Rankine to Fahrenheit', () => {
|
||||
it('with Rankine value', () => {
|
||||
const test1 = tc.rankineToFahrenheit(98)
|
||||
expect(test1).toBe(-362)
|
||||
})
|
||||
})
|
||||
describe('Testing Conversion of Rankine to Kelvin', () => {
|
||||
it('with Rankine value', () => {
|
||||
const test1 = tc.rankineToKelvin(10)
|
||||
expect(test1).toBe(6)
|
||||
})
|
||||
})
|
||||
describe('Testing Conversion of Reaumur to Celsius', () => {
|
||||
it('with Reaumur value', () => {
|
||||
const test1 = tc.reaumurToCelsius(100)
|
||||
expect(test1).toBe(125)
|
||||
})
|
||||
})
|
||||
describe('Testing Conversion of Reaumur to Fahrenheit', () => {
|
||||
it('with Reaumur value', () => {
|
||||
const test1 = tc.reaumurToFahrenheit(100)
|
||||
expect(test1).toBe(257)
|
||||
})
|
||||
})
|
||||
describe('Testing Conversion of Reaumur to Kelvin', () => {
|
||||
it('with Reamur value', () => {
|
||||
const test1 = tc.reaumurToKelvin(100)
|
||||
expect(test1).toBe(398)
|
||||
})
|
||||
})
|
||||
describe('Testing Conversion of Reamur to Rankine', () => {
|
||||
it('with Reamur value', () => {
|
||||
const test1 = tc.reaumurToRankine(100)
|
||||
expect(test1).toBe(717)
|
||||
})
|
||||
})
|
||||
import * as tc from '../TemperatureConversion.js'
|
||||
|
||||
describe('Testing Conversion of Celsius to fahrenheit', () => {
|
||||
it('with celsius value', () => {
|
||||
const test1 = tc.celsiusToFahrenheit(10)
|
||||
expect(test1).toBe(50)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Testing Conversion of Celsius to kelvin', () => {
|
||||
it('with celsius value', () => {
|
||||
const test1 = tc.celsiusToKelvin(15)
|
||||
expect(test1).toBe(288)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Testing Conversion of Celsius to Rankine', () => {
|
||||
it('with celsius value', () => {
|
||||
const test1 = tc.celsiusToRankine(28)
|
||||
expect(test1).toBe(542)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Testing Conversion of Fahrenheit to Celsius', () => {
|
||||
it('with Fahrenheit value', () => {
|
||||
const test1 = tc.fahrenheitToCelsius(134)
|
||||
expect(test1).toBe(57)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Testing Conversion of Fahrenheit to Kelvin', () => {
|
||||
it('with Fahrenheit value', () => {
|
||||
const test1 = tc.fahrenheitToKelvin(125)
|
||||
expect(test1).toBe(325)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Testing Conversion of Fahrenheit to Rankine', () => {
|
||||
it('with Fahrenheit value', () => {
|
||||
const test1 = tc.fahrenheitToRankine(10)
|
||||
expect(test1).toBe(470)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Testing Conversion of Kelvin to Celsius', () => {
|
||||
it('with Kelvin value', () => {
|
||||
const test1 = tc.kelvinToCelsius(100)
|
||||
expect(test1).toBe(-173)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Testing Conversion of Kelvin to Fahrenheit', () => {
|
||||
it('with Kelvin value', () => {
|
||||
const test1 = tc.kelvinToFahrenheit(20)
|
||||
expect(test1).toBe(-424)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Testing Conversion of Kelvin to Rankine', () => {
|
||||
it('with kelvin value', () => {
|
||||
const test1 = tc.kelvinToRankine(69)
|
||||
expect(test1).toBe(124)
|
||||
})
|
||||
})
|
||||
describe('Testing Conversion of Rankine to Celsius', () => {
|
||||
it('with Rankine value', () => {
|
||||
const test1 = tc.rankineToCelsius(234)
|
||||
expect(test1).toBe(-143)
|
||||
})
|
||||
})
|
||||
describe('Testing Conversion of Rankine to Fahrenheit', () => {
|
||||
it('with Rankine value', () => {
|
||||
const test1 = tc.rankineToFahrenheit(98)
|
||||
expect(test1).toBe(-362)
|
||||
})
|
||||
})
|
||||
describe('Testing Conversion of Rankine to Kelvin', () => {
|
||||
it('with Rankine value', () => {
|
||||
const test1 = tc.rankineToKelvin(10)
|
||||
expect(test1).toBe(6)
|
||||
})
|
||||
})
|
||||
describe('Testing Conversion of Reaumur to Celsius', () => {
|
||||
it('with Reaumur value', () => {
|
||||
const test1 = tc.reaumurToCelsius(100)
|
||||
expect(test1).toBe(125)
|
||||
})
|
||||
})
|
||||
describe('Testing Conversion of Reaumur to Fahrenheit', () => {
|
||||
it('with Reaumur value', () => {
|
||||
const test1 = tc.reaumurToFahrenheit(100)
|
||||
expect(test1).toBe(257)
|
||||
})
|
||||
})
|
||||
describe('Testing Conversion of Reaumur to Kelvin', () => {
|
||||
it('with Reamur value', () => {
|
||||
const test1 = tc.reaumurToKelvin(100)
|
||||
expect(test1).toBe(398)
|
||||
})
|
||||
})
|
||||
describe('Testing Conversion of Reamur to Rankine', () => {
|
||||
it('with Reamur value', () => {
|
||||
const test1 = tc.reaumurToRankine(100)
|
||||
expect(test1).toBe(717)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
import { titleCaseConversion } from '../TitleCaseConversion'
|
||||
|
||||
describe(('Tests for the titleCaseConversion function'), () => {
|
||||
describe('Tests for the titleCaseConversion function', () => {
|
||||
it('should return an empty string when the input is an empty string', () => {
|
||||
expect(titleCaseConversion('')).toEqual('')
|
||||
})
|
||||
|
||||
it('should return the input string when the input string is a title case string', () => {
|
||||
expect(titleCaseConversion('A Proper Title Case String')).toEqual('A Proper Title Case String')
|
||||
expect(titleCaseConversion('A Proper Title Case String')).toEqual(
|
||||
'A Proper Title Case String'
|
||||
)
|
||||
})
|
||||
|
||||
it('should return a title case string when input is an all-uppercase string', () => {
|
||||
@@ -34,7 +36,9 @@ describe(('Tests for the titleCaseConversion function'), () => {
|
||||
})
|
||||
|
||||
it('should return a title case string when input is an all-lowercase string with punctuation', () => {
|
||||
expect(titleCaseConversion('lower, case, input.')).toEqual('Lower, Case, Input.')
|
||||
expect(titleCaseConversion('lower, case, input.')).toEqual(
|
||||
'Lower, Case, Input.'
|
||||
)
|
||||
})
|
||||
|
||||
it('should return a title case string when input is an mixed-case string', () => {
|
||||
@@ -46,6 +50,8 @@ describe(('Tests for the titleCaseConversion function'), () => {
|
||||
})
|
||||
|
||||
it('should return a title case string when input is an mixed-case string with punctuation', () => {
|
||||
expect(titleCaseConversion('mixeD, CaSe, INPuT!')).toEqual('Mixed, Case, Input!')
|
||||
expect(titleCaseConversion('mixeD, CaSe, INPuT!')).toEqual(
|
||||
'Mixed, Case, Input!'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { upperCaseConversion } from '../UpperCaseConversion'
|
||||
|
||||
describe(('Test the upperCaseConversion function'), () => {
|
||||
describe('Test the upperCaseConversion function', () => {
|
||||
it('should return an empty string when the input is an empty string', () => {
|
||||
expect(upperCaseConversion('')).toEqual('')
|
||||
})
|
||||
@@ -26,7 +26,9 @@ describe(('Test the upperCaseConversion function'), () => {
|
||||
})
|
||||
|
||||
it('should return an all-uppercase string when input is an all-lowercase string with punctuation', () => {
|
||||
expect(upperCaseConversion('lower-case, input.')).toEqual('LOWER-CASE, INPUT.')
|
||||
expect(upperCaseConversion('lower-case, input.')).toEqual(
|
||||
'LOWER-CASE, INPUT.'
|
||||
)
|
||||
})
|
||||
|
||||
it('should return an all-uppercase string when input is an mixed-case string', () => {
|
||||
@@ -38,6 +40,8 @@ describe(('Test the upperCaseConversion function'), () => {
|
||||
})
|
||||
|
||||
it('should return an all-uppercase string when input is an mixed-case string with punctuation', () => {
|
||||
expect(upperCaseConversion('mixeD-CaSe INPuT!')).toEqual('MIXED-CASE INPUT!')
|
||||
expect(upperCaseConversion('mixeD-CaSe INPuT!')).toEqual(
|
||||
'MIXED-CASE INPUT!'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user