mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
prettier 4 tabwidth
This commit is contained in:
parent
00ec614f1d
commit
96b413a365
42 changed files with 7034 additions and 6905 deletions
|
@ -4,45 +4,45 @@ import { Subject, Question } from '../types/basicTypes'
|
|||
const question: Question = createQuestion('asd', 'asd', { type: 'simple' })
|
||||
|
||||
test('Adds questions to empty db', () => {
|
||||
const emptyDb: Subject[] = []
|
||||
addQuestion(emptyDb, 'test subject', question)
|
||||
expect(emptyDb.length).toBe(1)
|
||||
const emptyDb: Subject[] = []
|
||||
addQuestion(emptyDb, 'test subject', question)
|
||||
expect(emptyDb.length).toBe(1)
|
||||
})
|
||||
|
||||
test('Adds questions next to existing', () => {
|
||||
const db: Subject[] = [
|
||||
{
|
||||
Name: 'test subject',
|
||||
Questions: [question],
|
||||
},
|
||||
]
|
||||
addQuestion(db, 'another something', question)
|
||||
expect(db.length).toBe(2)
|
||||
const db: Subject[] = [
|
||||
{
|
||||
Name: 'test subject',
|
||||
Questions: [question],
|
||||
},
|
||||
]
|
||||
addQuestion(db, 'another something', question)
|
||||
expect(db.length).toBe(2)
|
||||
})
|
||||
|
||||
test('Does not add new subject, multiple new questions', () => {
|
||||
const db: Subject[] = [
|
||||
{
|
||||
Name: 'test subject',
|
||||
Questions: [question],
|
||||
},
|
||||
]
|
||||
addQuestion(db, 'test subject', question)
|
||||
addQuestion(db, 'test subject', question)
|
||||
addQuestion(db, 'test subject', question)
|
||||
addQuestion(db, 'test subject', question)
|
||||
expect(db.length).toBe(1)
|
||||
const db: Subject[] = [
|
||||
{
|
||||
Name: 'test subject',
|
||||
Questions: [question],
|
||||
},
|
||||
]
|
||||
addQuestion(db, 'test subject', question)
|
||||
addQuestion(db, 'test subject', question)
|
||||
addQuestion(db, 'test subject', question)
|
||||
addQuestion(db, 'test subject', question)
|
||||
expect(db.length).toBe(1)
|
||||
})
|
||||
|
||||
test('Adds new subjects, multiple new questions', () => {
|
||||
const db: Subject[] = [
|
||||
{
|
||||
Name: 'test subject',
|
||||
Questions: [question],
|
||||
},
|
||||
]
|
||||
addQuestion(db, 'gfjdkglfd', question)
|
||||
addQuestion(db, ' somrthing test ', question)
|
||||
addQuestion(db, 'aaaaaaaa', question)
|
||||
expect(db.length).toBe(4)
|
||||
const db: Subject[] = [
|
||||
{
|
||||
Name: 'test subject',
|
||||
Questions: [question],
|
||||
},
|
||||
]
|
||||
addQuestion(db, 'gfjdkglfd', question)
|
||||
addQuestion(db, ' somrthing test ', question)
|
||||
addQuestion(db, 'aaaaaaaa', question)
|
||||
expect(db.length).toBe(4)
|
||||
})
|
||||
|
|
|
@ -11,22 +11,22 @@
|
|||
// const expectedResults = ['Melyik híres zenekar tagja volt Joe Muranyi?']
|
||||
|
||||
test('Img text recognition works', async () => {
|
||||
// TODO: tesseract keeps workers even after terminate(), and jest --detectOpenHandles detects them
|
||||
expect(true).toBeTruthy()
|
||||
// await tesseractLoaded
|
||||
// for (let i = 0; i < imgs.length; i++) {
|
||||
// const expectedResult = expectedResults[i]
|
||||
// const img = imgs[i]
|
||||
//
|
||||
// const text = await recognizeTextFromBase64(img)
|
||||
// expect(text.trim() === expectedResult).toBeTruthy()
|
||||
// }
|
||||
//
|
||||
// await terminateWorker()
|
||||
//
|
||||
// return new Promise<void>((resolve) => {
|
||||
// setTimeout(() => {
|
||||
// resolve()
|
||||
// }, 1 * 1000)
|
||||
// })
|
||||
// TODO: tesseract keeps workers even after terminate(), and jest --detectOpenHandles detects them
|
||||
expect(true).toBeTruthy()
|
||||
// await tesseractLoaded
|
||||
// for (let i = 0; i < imgs.length; i++) {
|
||||
// const expectedResult = expectedResults[i]
|
||||
// const img = imgs[i]
|
||||
//
|
||||
// const text = await recognizeTextFromBase64(img)
|
||||
// expect(text.trim() === expectedResult).toBeTruthy()
|
||||
// }
|
||||
//
|
||||
// await terminateWorker()
|
||||
//
|
||||
// return new Promise<void>((resolve) => {
|
||||
// setTimeout(() => {
|
||||
// resolve()
|
||||
// }, 1 * 1000)
|
||||
// })
|
||||
})
|
||||
|
|
|
@ -6,192 +6,192 @@ import { QuestionDb, Subject, Question } from '../types/basicTypes'
|
|||
const date = (x?: number) => new Date().getTime() + (x || 0)
|
||||
|
||||
const q1 = createQuestion(
|
||||
'A kötvény és a részvény közös tulajdonsága, hogy TOREMOVE',
|
||||
'piaci áruk eltérhet a névértéktől.',
|
||||
{
|
||||
type: 'simple',
|
||||
date: date(-1000),
|
||||
}
|
||||
'A kötvény és a részvény közös tulajdonsága, hogy TOREMOVE',
|
||||
'piaci áruk eltérhet a névértéktől.',
|
||||
{
|
||||
type: 'simple',
|
||||
date: date(-1000),
|
||||
}
|
||||
)
|
||||
const q2 = createQuestion(
|
||||
'A kötvény és a részvény közös tulajdonsága, hogy TOREMOVE',
|
||||
'afjléa gféda gfdjs légf',
|
||||
{
|
||||
type: 'simple',
|
||||
date: date(-1000),
|
||||
}
|
||||
'A kötvény és a részvény közös tulajdonsága, hogy TOREMOVE',
|
||||
'afjléa gféda gfdjs légf',
|
||||
{
|
||||
type: 'simple',
|
||||
date: date(-1000),
|
||||
}
|
||||
)
|
||||
const q3 = createQuestion(
|
||||
'A kötvény és a részvény közös tulajdonsága, hogy TOREMOVE',
|
||||
'afjlsd gfds dgfs gf sdgf d',
|
||||
{
|
||||
type: 'simple',
|
||||
date: date(-1000),
|
||||
}
|
||||
'A kötvény és a részvény közös tulajdonsága, hogy TOREMOVE',
|
||||
'afjlsd gfds dgfs gf sdgf d',
|
||||
{
|
||||
type: 'simple',
|
||||
date: date(-1000),
|
||||
}
|
||||
)
|
||||
const q4 = createQuestion(
|
||||
'A kötvény névértéke',
|
||||
'A kötvényen feltüntetett meghatározott nagyságú összeg.',
|
||||
{
|
||||
type: 'simple',
|
||||
date: date(-1000),
|
||||
}
|
||||
'A kötvény névértéke',
|
||||
'A kötvényen feltüntetett meghatározott nagyságú összeg.',
|
||||
{
|
||||
type: 'simple',
|
||||
date: date(-1000),
|
||||
}
|
||||
)
|
||||
const q5 = createQuestion(
|
||||
'Mi az osztalék? asd asd',
|
||||
'A vállalati profit egy része..',
|
||||
{
|
||||
type: 'simple',
|
||||
date: date(1000),
|
||||
}
|
||||
'Mi az osztalék? asd asd',
|
||||
'A vállalati profit egy része..',
|
||||
{
|
||||
type: 'simple',
|
||||
date: date(1000),
|
||||
}
|
||||
)
|
||||
const q6 = createQuestion(
|
||||
'valaim nagyon értelmes kérdés asd asd',
|
||||
'A vállalati profit egy része..',
|
||||
{
|
||||
type: 'simple',
|
||||
date: date(1000),
|
||||
}
|
||||
'valaim nagyon értelmes kérdés asd asd',
|
||||
'A vállalati profit egy része..',
|
||||
{
|
||||
type: 'simple',
|
||||
date: date(1000),
|
||||
}
|
||||
)
|
||||
|
||||
function setupTest({
|
||||
newQuestions,
|
||||
data,
|
||||
subjToClean,
|
||||
newQuestions,
|
||||
data,
|
||||
subjToClean,
|
||||
}: {
|
||||
newQuestions: Question[]
|
||||
data: Subject[]
|
||||
subjToClean?: string
|
||||
newQuestions: Question[]
|
||||
data: Subject[]
|
||||
subjToClean?: string
|
||||
}) {
|
||||
const recievedQuestions: Question[] = newQuestions.map((x) => {
|
||||
const recievedQuestions: Question[] = newQuestions.map((x) => {
|
||||
return {
|
||||
...x,
|
||||
data: {
|
||||
...x.data,
|
||||
date: date(),
|
||||
},
|
||||
}
|
||||
})
|
||||
const subjName = subjToClean || 'subject'
|
||||
const overwriteFromDate = date(-100)
|
||||
const qdbIndex = 0
|
||||
const qdbs: QuestionDb[] = [
|
||||
{
|
||||
name: 'test',
|
||||
data: data,
|
||||
index: 0,
|
||||
path: '',
|
||||
shouldSearch: 'asd',
|
||||
shouldSave: {},
|
||||
},
|
||||
]
|
||||
const subjIndex = qdbs[qdbIndex].data.findIndex((x) => {
|
||||
return x.Name.toLowerCase().includes(subjName.toLowerCase())
|
||||
})
|
||||
|
||||
const questionIndexesToRemove = cleanDb(
|
||||
{
|
||||
questions: recievedQuestions,
|
||||
subjToClean: subjName,
|
||||
overwriteFromDate: overwriteFromDate,
|
||||
qdbIndex: qdbIndex,
|
||||
},
|
||||
qdbs
|
||||
)
|
||||
|
||||
const updatedQuestions = updateQuestionsInArray(
|
||||
questionIndexesToRemove,
|
||||
qdbs[qdbIndex].data[subjIndex].Questions,
|
||||
recievedQuestions
|
||||
)
|
||||
|
||||
return {
|
||||
...x,
|
||||
data: {
|
||||
...x.data,
|
||||
date: date(),
|
||||
},
|
||||
questionIndexesToRemove: questionIndexesToRemove,
|
||||
updatedQuestions: updatedQuestions,
|
||||
overwriteFromDate: overwriteFromDate,
|
||||
subjIndex: subjIndex,
|
||||
}
|
||||
})
|
||||
const subjName = subjToClean || 'subject'
|
||||
const overwriteFromDate = date(-100)
|
||||
const qdbIndex = 0
|
||||
const qdbs: QuestionDb[] = [
|
||||
{
|
||||
name: 'test',
|
||||
data: data,
|
||||
index: 0,
|
||||
path: '',
|
||||
shouldSearch: 'asd',
|
||||
shouldSave: {},
|
||||
},
|
||||
]
|
||||
const subjIndex = qdbs[qdbIndex].data.findIndex((x) => {
|
||||
return x.Name.toLowerCase().includes(subjName.toLowerCase())
|
||||
})
|
||||
|
||||
const questionIndexesToRemove = cleanDb(
|
||||
{
|
||||
questions: recievedQuestions,
|
||||
subjToClean: subjName,
|
||||
overwriteFromDate: overwriteFromDate,
|
||||
qdbIndex: qdbIndex,
|
||||
},
|
||||
qdbs
|
||||
)
|
||||
|
||||
const updatedQuestions = updateQuestionsInArray(
|
||||
questionIndexesToRemove,
|
||||
qdbs[qdbIndex].data[subjIndex].Questions,
|
||||
recievedQuestions
|
||||
)
|
||||
|
||||
return {
|
||||
questionIndexesToRemove: questionIndexesToRemove,
|
||||
updatedQuestions: updatedQuestions,
|
||||
overwriteFromDate: overwriteFromDate,
|
||||
subjIndex: subjIndex,
|
||||
}
|
||||
}
|
||||
|
||||
const s1: Subject = { Name: 'test subject', Questions: [q1, q2, q4, q5] }
|
||||
|
||||
test('Old and duplicate questions should be removed from the database', () => {
|
||||
const { questionIndexesToRemove, updatedQuestions, overwriteFromDate } =
|
||||
setupTest({ newQuestions: [q1, q4, q5], data: [s1] })
|
||||
const { questionIndexesToRemove, updatedQuestions, overwriteFromDate } =
|
||||
setupTest({ newQuestions: [q1, q4, q5], data: [s1] })
|
||||
|
||||
expect(questionIndexesToRemove.length).toBe(3)
|
||||
expect(questionIndexesToRemove[0].length).toBe(2)
|
||||
expect(questionIndexesToRemove.length).toBe(3)
|
||||
expect(questionIndexesToRemove[0].length).toBe(2)
|
||||
|
||||
expect(updatedQuestions.length).toBe(3)
|
||||
const toremoveCount = updatedQuestions.filter((question) => {
|
||||
return question.Q.includes('TOREMOVE')
|
||||
}).length
|
||||
expect(toremoveCount).toBe(1)
|
||||
const newQuestion = updatedQuestions.find((question) => {
|
||||
return question.Q.includes('TOREMOVE')
|
||||
})
|
||||
expect(newQuestion.data.date > overwriteFromDate).toBeTruthy()
|
||||
expect(updatedQuestions.length).toBe(3)
|
||||
const toremoveCount = updatedQuestions.filter((question) => {
|
||||
return question.Q.includes('TOREMOVE')
|
||||
}).length
|
||||
expect(toremoveCount).toBe(1)
|
||||
const newQuestion = updatedQuestions.find((question) => {
|
||||
return question.Q.includes('TOREMOVE')
|
||||
})
|
||||
expect(newQuestion.data.date > overwriteFromDate).toBeTruthy()
|
||||
})
|
||||
|
||||
const s2: Subject = {
|
||||
Name: 'test subject',
|
||||
Questions: [q1, q2, q3, q4, q5, q6],
|
||||
Name: 'test subject',
|
||||
Questions: [q1, q2, q3, q4, q5, q6],
|
||||
}
|
||||
|
||||
test('Old and duplicate questions should be removed from the database round 2', () => {
|
||||
const { questionIndexesToRemove, updatedQuestions, overwriteFromDate } =
|
||||
setupTest({ newQuestions: [q1, q4, q5], data: [s2] })
|
||||
const { questionIndexesToRemove, updatedQuestions, overwriteFromDate } =
|
||||
setupTest({ newQuestions: [q1, q4, q5], data: [s2] })
|
||||
|
||||
expect(questionIndexesToRemove.length).toBe(3)
|
||||
expect(questionIndexesToRemove[0].length).toBe(3)
|
||||
expect(questionIndexesToRemove.length).toBe(3)
|
||||
expect(questionIndexesToRemove[0].length).toBe(3)
|
||||
|
||||
expect(updatedQuestions.length).toBe(4)
|
||||
const toremoveCount = updatedQuestions.filter((question) => {
|
||||
return question.Q.includes('TOREMOVE')
|
||||
}).length
|
||||
expect(toremoveCount).toBe(1)
|
||||
const newQuestion = updatedQuestions.find((question) => {
|
||||
return question.Q.includes('TOREMOVE')
|
||||
})
|
||||
expect(newQuestion.data.date > overwriteFromDate).toBeTruthy()
|
||||
expect(updatedQuestions.length).toBe(4)
|
||||
const toremoveCount = updatedQuestions.filter((question) => {
|
||||
return question.Q.includes('TOREMOVE')
|
||||
}).length
|
||||
expect(toremoveCount).toBe(1)
|
||||
const newQuestion = updatedQuestions.find((question) => {
|
||||
return question.Q.includes('TOREMOVE')
|
||||
})
|
||||
expect(newQuestion.data.date > overwriteFromDate).toBeTruthy()
|
||||
})
|
||||
|
||||
const s3: Subject = {
|
||||
Name: 'test subject',
|
||||
Questions: [q5, q6].map((x) => ({
|
||||
...x,
|
||||
data: {
|
||||
...x.data,
|
||||
date: date(+50000),
|
||||
},
|
||||
})),
|
||||
Name: 'test subject',
|
||||
Questions: [q5, q6].map((x) => ({
|
||||
...x,
|
||||
data: {
|
||||
...x.data,
|
||||
date: date(+50000),
|
||||
},
|
||||
})),
|
||||
}
|
||||
|
||||
test('Old and duplicate questions should be removed from the database: questions should be left alone when they are newer', () => {
|
||||
const { questionIndexesToRemove, updatedQuestions } = setupTest({
|
||||
newQuestions: [q5, q6],
|
||||
data: [s3],
|
||||
})
|
||||
const { questionIndexesToRemove, updatedQuestions } = setupTest({
|
||||
newQuestions: [q5, q6],
|
||||
data: [s3],
|
||||
})
|
||||
|
||||
expect(questionIndexesToRemove.length).toBe(2)
|
||||
questionIndexesToRemove.forEach((x) => {
|
||||
expect(x.length).toBe(0)
|
||||
})
|
||||
expect(questionIndexesToRemove.length).toBe(2)
|
||||
questionIndexesToRemove.forEach((x) => {
|
||||
expect(x.length).toBe(0)
|
||||
})
|
||||
|
||||
expect(updatedQuestions.length).toBe(2)
|
||||
expect(updatedQuestions.length).toBe(2)
|
||||
})
|
||||
|
||||
const s4: Subject = {
|
||||
Name: 'something else',
|
||||
Questions: [q5, q6],
|
||||
Name: 'something else',
|
||||
Questions: [q5, q6],
|
||||
}
|
||||
|
||||
test('Old and duplicate questions should be removed from the database:other subjects should be left alone', () => {
|
||||
const { subjIndex } = setupTest({
|
||||
newQuestions: [q5, q6],
|
||||
data: [s2, s1, s4, s3],
|
||||
subjToClean: 'else',
|
||||
})
|
||||
const { subjIndex } = setupTest({
|
||||
newQuestions: [q5, q6],
|
||||
data: [s2, s1, s4, s3],
|
||||
subjToClean: 'else',
|
||||
})
|
||||
|
||||
expect(subjIndex).toBe(2)
|
||||
expect(subjIndex).toBe(2)
|
||||
})
|
||||
|
|
|
@ -1,308 +1,308 @@
|
|||
import {
|
||||
setNoPossibleAnswersPenalties,
|
||||
SearchResultQuestion,
|
||||
noPossibleAnswerMatchPenalty,
|
||||
setNoPossibleAnswersPenalties,
|
||||
SearchResultQuestion,
|
||||
noPossibleAnswerMatchPenalty,
|
||||
} from '../utils/classes'
|
||||
import { Question } from '../types/basicTypes'
|
||||
|
||||
const matchPercent = 100
|
||||
|
||||
const questionWithNormalPossibleAnswers: Question = {
|
||||
Q: 'asd',
|
||||
A: 'asd',
|
||||
data: {
|
||||
type: 'simple',
|
||||
possibleAnswers: [
|
||||
{ type: 'txt', val: 'rubber duck' },
|
||||
{ type: 'txt', val: 'super laptop' },
|
||||
{ type: 'txt', val: 'nothing in particular' },
|
||||
{ type: 'txt', val: 'something giberish' },
|
||||
],
|
||||
},
|
||||
Q: 'asd',
|
||||
A: 'asd',
|
||||
data: {
|
||||
type: 'simple',
|
||||
possibleAnswers: [
|
||||
{ type: 'txt', val: 'rubber duck' },
|
||||
{ type: 'txt', val: 'super laptop' },
|
||||
{ type: 'txt', val: 'nothing in particular' },
|
||||
{ type: 'txt', val: 'something giberish' },
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
const questionWithNormalPossibleAnswersWithLabels: Question = {
|
||||
Q: 'asd',
|
||||
A: 'asd',
|
||||
data: {
|
||||
type: 'simple',
|
||||
possibleAnswers: [
|
||||
{ type: 'txt', val: 'a) nothing in particular' },
|
||||
{ type: 'txt', val: 'b) super laptop' },
|
||||
{ type: 'txt', val: 'c) something giberish' },
|
||||
{ type: 'txt', val: 'd) rubber duck' },
|
||||
],
|
||||
},
|
||||
Q: 'asd',
|
||||
A: 'asd',
|
||||
data: {
|
||||
type: 'simple',
|
||||
possibleAnswers: [
|
||||
{ type: 'txt', val: 'a) nothing in particular' },
|
||||
{ type: 'txt', val: 'b) super laptop' },
|
||||
{ type: 'txt', val: 'c) something giberish' },
|
||||
{ type: 'txt', val: 'd) rubber duck' },
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
const questionWithNormalPossibleAnswers2: Question = {
|
||||
Q: 'asd',
|
||||
A: 'asd',
|
||||
data: {
|
||||
type: 'simple',
|
||||
possibleAnswers: [
|
||||
{ type: 'txt', val: 'rubber duck' },
|
||||
{ type: 'txt', val: 'cat' },
|
||||
{ type: 'txt', val: 'nothing in particular' },
|
||||
{ type: 'txt', val: 'dog' },
|
||||
],
|
||||
},
|
||||
Q: 'asd',
|
||||
A: 'asd',
|
||||
data: {
|
||||
type: 'simple',
|
||||
possibleAnswers: [
|
||||
{ type: 'txt', val: 'rubber duck' },
|
||||
{ type: 'txt', val: 'cat' },
|
||||
{ type: 'txt', val: 'nothing in particular' },
|
||||
{ type: 'txt', val: 'dog' },
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
const questionWithNormalPossibleAnswers3: Question = {
|
||||
Q: 'asd',
|
||||
A: 'asd',
|
||||
data: {
|
||||
type: 'simple',
|
||||
possibleAnswers: [
|
||||
{ type: 'txt', val: 'rubber duck 2' },
|
||||
{ type: 'txt', val: 'whale' },
|
||||
{ type: 'txt', val: 'nothing in particular 2' },
|
||||
{ type: 'txt', val: 'sea lion' },
|
||||
],
|
||||
},
|
||||
Q: 'asd',
|
||||
A: 'asd',
|
||||
data: {
|
||||
type: 'simple',
|
||||
possibleAnswers: [
|
||||
{ type: 'txt', val: 'rubber duck 2' },
|
||||
{ type: 'txt', val: 'whale' },
|
||||
{ type: 'txt', val: 'nothing in particular 2' },
|
||||
{ type: 'txt', val: 'sea lion' },
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
const questionWithNormalPossibleAnswers4: Question = {
|
||||
Q: 'asd',
|
||||
A: 'asd',
|
||||
data: {
|
||||
type: 'simple',
|
||||
possibleAnswers: [
|
||||
{ type: 'txt', val: 'rubber duck' },
|
||||
{ type: 'txt', val: 'super laptop' },
|
||||
],
|
||||
},
|
||||
Q: 'asd',
|
||||
A: 'asd',
|
||||
data: {
|
||||
type: 'simple',
|
||||
possibleAnswers: [
|
||||
{ type: 'txt', val: 'rubber duck' },
|
||||
{ type: 'txt', val: 'super laptop' },
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
const questionWithSimilarPossibleAnswers: Question = {
|
||||
Q: 'asd',
|
||||
A: 'asd',
|
||||
data: {
|
||||
type: 'simple',
|
||||
possibleAnswers: [
|
||||
{ type: 'txt', val: 'asd' },
|
||||
{ type: 'txt', val: 'basd' },
|
||||
{ type: 'txt', val: 'aaa' },
|
||||
{ type: 'txt', val: 'bbb' },
|
||||
],
|
||||
},
|
||||
Q: 'asd',
|
||||
A: 'asd',
|
||||
data: {
|
||||
type: 'simple',
|
||||
possibleAnswers: [
|
||||
{ type: 'txt', val: 'asd' },
|
||||
{ type: 'txt', val: 'basd' },
|
||||
{ type: 'txt', val: 'aaa' },
|
||||
{ type: 'txt', val: 'bbb' },
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
const questionWithTrueFalsePossibleAnser: Question = {
|
||||
Q: 'asd',
|
||||
A: 'asd',
|
||||
data: {
|
||||
type: 'simple',
|
||||
possibleAnswers: [
|
||||
{ type: 'txt', val: 'true' },
|
||||
{ type: 'txt', val: 'false' },
|
||||
],
|
||||
},
|
||||
Q: 'asd',
|
||||
A: 'asd',
|
||||
data: {
|
||||
type: 'simple',
|
||||
possibleAnswers: [
|
||||
{ type: 'txt', val: 'true' },
|
||||
{ type: 'txt', val: 'false' },
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
const questionWithNoPossibleAnswer: Question = {
|
||||
Q: 'asd',
|
||||
A: 'asd',
|
||||
data: {
|
||||
type: 'simple',
|
||||
},
|
||||
Q: 'asd',
|
||||
A: 'asd',
|
||||
data: {
|
||||
type: 'simple',
|
||||
},
|
||||
}
|
||||
|
||||
const resNormal: SearchResultQuestion = {
|
||||
q: questionWithNormalPossibleAnswers,
|
||||
match: matchPercent,
|
||||
detailedMatch: {
|
||||
qMatch: matchPercent,
|
||||
aMatch: matchPercent,
|
||||
dMatch: matchPercent,
|
||||
matchedSubjName: 'testSubj',
|
||||
avg: matchPercent,
|
||||
},
|
||||
q: questionWithNormalPossibleAnswers,
|
||||
match: matchPercent,
|
||||
detailedMatch: {
|
||||
qMatch: matchPercent,
|
||||
aMatch: matchPercent,
|
||||
dMatch: matchPercent,
|
||||
matchedSubjName: 'testSubj',
|
||||
avg: matchPercent,
|
||||
},
|
||||
}
|
||||
|
||||
const resNormal2: SearchResultQuestion = {
|
||||
q: questionWithNormalPossibleAnswers2,
|
||||
match: matchPercent,
|
||||
detailedMatch: {
|
||||
qMatch: matchPercent,
|
||||
aMatch: matchPercent,
|
||||
dMatch: matchPercent,
|
||||
matchedSubjName: 'testSubj',
|
||||
avg: matchPercent,
|
||||
},
|
||||
q: questionWithNormalPossibleAnswers2,
|
||||
match: matchPercent,
|
||||
detailedMatch: {
|
||||
qMatch: matchPercent,
|
||||
aMatch: matchPercent,
|
||||
dMatch: matchPercent,
|
||||
matchedSubjName: 'testSubj',
|
||||
avg: matchPercent,
|
||||
},
|
||||
}
|
||||
|
||||
const resNormal3: SearchResultQuestion = {
|
||||
q: questionWithNormalPossibleAnswers3,
|
||||
match: matchPercent,
|
||||
detailedMatch: {
|
||||
qMatch: matchPercent,
|
||||
aMatch: matchPercent,
|
||||
dMatch: matchPercent,
|
||||
matchedSubjName: 'testSubj',
|
||||
avg: matchPercent,
|
||||
},
|
||||
q: questionWithNormalPossibleAnswers3,
|
||||
match: matchPercent,
|
||||
detailedMatch: {
|
||||
qMatch: matchPercent,
|
||||
aMatch: matchPercent,
|
||||
dMatch: matchPercent,
|
||||
matchedSubjName: 'testSubj',
|
||||
avg: matchPercent,
|
||||
},
|
||||
}
|
||||
|
||||
const resNormal4: SearchResultQuestion = {
|
||||
q: questionWithNormalPossibleAnswers4,
|
||||
match: matchPercent,
|
||||
detailedMatch: {
|
||||
qMatch: matchPercent,
|
||||
aMatch: matchPercent,
|
||||
dMatch: matchPercent,
|
||||
matchedSubjName: 'testSubj',
|
||||
avg: matchPercent,
|
||||
},
|
||||
q: questionWithNormalPossibleAnswers4,
|
||||
match: matchPercent,
|
||||
detailedMatch: {
|
||||
qMatch: matchPercent,
|
||||
aMatch: matchPercent,
|
||||
dMatch: matchPercent,
|
||||
matchedSubjName: 'testSubj',
|
||||
avg: matchPercent,
|
||||
},
|
||||
}
|
||||
|
||||
const resSimilar: SearchResultQuestion = {
|
||||
q: questionWithSimilarPossibleAnswers,
|
||||
match: matchPercent,
|
||||
detailedMatch: {
|
||||
qMatch: matchPercent,
|
||||
aMatch: matchPercent,
|
||||
dMatch: matchPercent,
|
||||
matchedSubjName: 'testSubj',
|
||||
avg: matchPercent,
|
||||
},
|
||||
q: questionWithSimilarPossibleAnswers,
|
||||
match: matchPercent,
|
||||
detailedMatch: {
|
||||
qMatch: matchPercent,
|
||||
aMatch: matchPercent,
|
||||
dMatch: matchPercent,
|
||||
matchedSubjName: 'testSubj',
|
||||
avg: matchPercent,
|
||||
},
|
||||
}
|
||||
|
||||
const resTrueFalse: SearchResultQuestion = {
|
||||
q: questionWithTrueFalsePossibleAnser,
|
||||
match: matchPercent,
|
||||
detailedMatch: {
|
||||
qMatch: matchPercent,
|
||||
aMatch: matchPercent,
|
||||
dMatch: matchPercent,
|
||||
matchedSubjName: 'testSubj',
|
||||
avg: matchPercent,
|
||||
},
|
||||
q: questionWithTrueFalsePossibleAnser,
|
||||
match: matchPercent,
|
||||
detailedMatch: {
|
||||
qMatch: matchPercent,
|
||||
aMatch: matchPercent,
|
||||
dMatch: matchPercent,
|
||||
matchedSubjName: 'testSubj',
|
||||
avg: matchPercent,
|
||||
},
|
||||
}
|
||||
|
||||
const resNoPossibleAnswer: SearchResultQuestion = {
|
||||
q: questionWithNoPossibleAnswer,
|
||||
match: matchPercent,
|
||||
detailedMatch: {
|
||||
qMatch: matchPercent,
|
||||
aMatch: matchPercent,
|
||||
dMatch: matchPercent,
|
||||
matchedSubjName: 'testSubj',
|
||||
avg: matchPercent,
|
||||
},
|
||||
q: questionWithNoPossibleAnswer,
|
||||
match: matchPercent,
|
||||
detailedMatch: {
|
||||
qMatch: matchPercent,
|
||||
aMatch: matchPercent,
|
||||
dMatch: matchPercent,
|
||||
matchedSubjName: 'testSubj',
|
||||
avg: matchPercent,
|
||||
},
|
||||
}
|
||||
|
||||
const testFunction = (
|
||||
question: Question,
|
||||
searchResult: SearchResultQuestion[],
|
||||
index: number
|
||||
question: Question,
|
||||
searchResult: SearchResultQuestion[],
|
||||
index: number
|
||||
) => {
|
||||
const updated = setNoPossibleAnswersPenalties(
|
||||
question.data.possibleAnswers,
|
||||
searchResult
|
||||
)
|
||||
const updated = setNoPossibleAnswersPenalties(
|
||||
question.data.possibleAnswers,
|
||||
searchResult
|
||||
)
|
||||
|
||||
updated.forEach((x, i) => {
|
||||
if (i !== index) {
|
||||
expect(x.match).toBe(matchPercent - noPossibleAnswerMatchPenalty)
|
||||
expect(x.detailedMatch.qMatch).toBe(
|
||||
matchPercent - noPossibleAnswerMatchPenalty
|
||||
)
|
||||
} else {
|
||||
expect(x.match).toBe(100)
|
||||
expect(x.detailedMatch.qMatch).toBe(100)
|
||||
}
|
||||
})
|
||||
updated.forEach((x, i) => {
|
||||
if (i !== index) {
|
||||
expect(x.match).toBe(matchPercent - noPossibleAnswerMatchPenalty)
|
||||
expect(x.detailedMatch.qMatch).toBe(
|
||||
matchPercent - noPossibleAnswerMatchPenalty
|
||||
)
|
||||
} else {
|
||||
expect(x.match).toBe(100)
|
||||
expect(x.detailedMatch.qMatch).toBe(100)
|
||||
}
|
||||
})
|
||||
|
||||
return updated
|
||||
return updated
|
||||
}
|
||||
|
||||
test('Possible answer penalty applies correctly (normal possible answers)', () => {
|
||||
testFunction(
|
||||
questionWithNormalPossibleAnswers,
|
||||
[
|
||||
resNormal,
|
||||
resNormal2,
|
||||
resNormal3,
|
||||
resNormal4,
|
||||
resSimilar,
|
||||
resTrueFalse,
|
||||
resNoPossibleAnswer,
|
||||
],
|
||||
0
|
||||
)
|
||||
testFunction(
|
||||
questionWithNormalPossibleAnswers,
|
||||
[
|
||||
resNormal,
|
||||
resNormal2,
|
||||
resNormal3,
|
||||
resNormal4,
|
||||
resSimilar,
|
||||
resTrueFalse,
|
||||
resNoPossibleAnswer,
|
||||
],
|
||||
0
|
||||
)
|
||||
})
|
||||
|
||||
test('Possible answer penalty applies correctly (normal possible answers, with labels)', () => {
|
||||
testFunction(
|
||||
questionWithNormalPossibleAnswersWithLabels,
|
||||
[
|
||||
resNormal,
|
||||
resNormal2,
|
||||
resNormal3,
|
||||
resNormal4,
|
||||
resSimilar,
|
||||
resTrueFalse,
|
||||
resNoPossibleAnswer,
|
||||
],
|
||||
0
|
||||
)
|
||||
testFunction(
|
||||
questionWithNormalPossibleAnswersWithLabels,
|
||||
[
|
||||
resNormal,
|
||||
resNormal2,
|
||||
resNormal3,
|
||||
resNormal4,
|
||||
resSimilar,
|
||||
resTrueFalse,
|
||||
resNoPossibleAnswer,
|
||||
],
|
||||
0
|
||||
)
|
||||
})
|
||||
|
||||
test('Possible answer penalty applies correctly (similar possible answers)', () => {
|
||||
testFunction(
|
||||
questionWithSimilarPossibleAnswers,
|
||||
[
|
||||
resNormal,
|
||||
resNormal2,
|
||||
resNormal3,
|
||||
resNormal4,
|
||||
resSimilar,
|
||||
resTrueFalse,
|
||||
resNoPossibleAnswer,
|
||||
],
|
||||
4
|
||||
)
|
||||
testFunction(
|
||||
questionWithSimilarPossibleAnswers,
|
||||
[
|
||||
resNormal,
|
||||
resNormal2,
|
||||
resNormal3,
|
||||
resNormal4,
|
||||
resSimilar,
|
||||
resTrueFalse,
|
||||
resNoPossibleAnswer,
|
||||
],
|
||||
4
|
||||
)
|
||||
})
|
||||
|
||||
test('Possible answer penalty applies correctly (true false possible answers)', () => {
|
||||
testFunction(
|
||||
questionWithTrueFalsePossibleAnser,
|
||||
[
|
||||
resNormal,
|
||||
resNormal2,
|
||||
resNormal3,
|
||||
resNormal4,
|
||||
resSimilar,
|
||||
resTrueFalse,
|
||||
resNoPossibleAnswer,
|
||||
],
|
||||
5
|
||||
)
|
||||
testFunction(
|
||||
questionWithTrueFalsePossibleAnser,
|
||||
[
|
||||
resNormal,
|
||||
resNormal2,
|
||||
resNormal3,
|
||||
resNormal4,
|
||||
resSimilar,
|
||||
resTrueFalse,
|
||||
resNoPossibleAnswer,
|
||||
],
|
||||
5
|
||||
)
|
||||
})
|
||||
|
||||
test('Possible answer penalty applies correctly (no possible answers)', () => {
|
||||
const updated = setNoPossibleAnswersPenalties(
|
||||
questionWithNoPossibleAnswer.data.possibleAnswers,
|
||||
[
|
||||
resNormal,
|
||||
resNormal2,
|
||||
resNormal3,
|
||||
resNormal4,
|
||||
resSimilar,
|
||||
resTrueFalse,
|
||||
resNoPossibleAnswer,
|
||||
]
|
||||
)
|
||||
const updated = setNoPossibleAnswersPenalties(
|
||||
questionWithNoPossibleAnswer.data.possibleAnswers,
|
||||
[
|
||||
resNormal,
|
||||
resNormal2,
|
||||
resNormal3,
|
||||
resNormal4,
|
||||
resSimilar,
|
||||
resTrueFalse,
|
||||
resNoPossibleAnswer,
|
||||
]
|
||||
)
|
||||
|
||||
updated.forEach((x) => {
|
||||
expect(x.match).toBe(100)
|
||||
expect(x.detailedMatch.qMatch).toBe(100)
|
||||
})
|
||||
updated.forEach((x) => {
|
||||
expect(x.match).toBe(100)
|
||||
expect(x.detailedMatch.qMatch).toBe(100)
|
||||
})
|
||||
})
|
||||
|
||||
test('Possible answer penalty applies correctly (empty searchResult)', () => {
|
||||
const updated = testFunction(questionWithTrueFalsePossibleAnser, [], 0)
|
||||
expect(updated.length).toBe(0)
|
||||
const updated = testFunction(questionWithTrueFalsePossibleAnser, [], 0)
|
||||
expect(updated.length).toBe(0)
|
||||
})
|
||||
|
|
|
@ -6,10 +6,10 @@ const truthy = [1, 2, '10', '40']
|
|||
const falsey = [5, '55', 47832, 'fhs']
|
||||
|
||||
test('ShouldLog works', () => {
|
||||
truthy.forEach((x) => {
|
||||
expect(shouldLog(x, noLogIds)).toBeTruthy()
|
||||
})
|
||||
falsey.forEach((x) => {
|
||||
expect(shouldLog(x, noLogIds)).toBeFalsy()
|
||||
})
|
||||
truthy.forEach((x) => {
|
||||
expect(shouldLog(x, noLogIds)).toBeTruthy()
|
||||
})
|
||||
falsey.forEach((x) => {
|
||||
expect(shouldLog(x, noLogIds)).toBeFalsy()
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue