Minor changes, added example classes test

This commit is contained in:
mrfry 2021-05-04 10:28:20 +02:00
parent 8801bb96cd
commit d8b0c28471
4 changed files with 35 additions and 10 deletions

25
src/utils/classes.test.ts Normal file
View file

@ -0,0 +1,25 @@
import { compareString } from './classes'
const testCases: Array<{ s1: string; s2: string; res: number }> = [
{ s1: 'hello', s2: 'hello', res: 100 },
{ s1: 'aaaaa', s2: 'bbbbb', res: 0 },
{
s1: 'Mely állítás nem igaz a tőzsdékre?',
s2: 'Mely állítás nem igaz a tőzsdékre?',
res: 100,
},
{
s1: 'Mely állítás nem igaz a tőzsdékre?',
s2: 'Ez egy teljesen más mondat',
res: 0,
},
{ s1: 'cHar caSe tESt', s2: 'ChaR cAse TEst', res: 0 },
]
testCases.forEach((currCase) => {
const { s1, s2, res } = currCase
test(`String compare tests: "${s1}" & "${s2}" should be: ${res}%`, () => {
expect(compareString(s1, s1.split(' '), s2, s2.split(' '))).toBe(res)
})
})

View file

@ -65,10 +65,7 @@ function getSubjNameWithoutYear(subjName: string): string {
// ---------------------------------------------------------------------------------------------------------
function simplifyString(toremove) {
return toremove
.replace(/\s/g, ' ')
.replace(/\s+/g, ' ')
.toLowerCase()
return toremove.replace(/\s/g, ' ').replace(/\s+/g, ' ').toLowerCase()
}
function removeStuff(
@ -92,7 +89,7 @@ function removeUnnecesarySpaces(toremove: string) {
return normalizeSpaces(toremove).replace(/\s+/g, ' ')
}
function compareString(
export function compareString(
s1: string,
s1a: Array<string>,
s2: string,