UNPKG

@coorpacademy/progression-engine

Version:

181 lines (180 loc) 13.1 kB
"use strict"; var _ava = _interopRequireDefault(require("ava")); var _config = require("../config"); var _assertCheckAnswerCorrectness = require("./helpers/assert-check-answer-correctness"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } const config = (0, _config.getConfig)({ ref: 'microlearning', version: 'latest' }); const configWithTypos = { ...config, maxTypos: 3 }; function createQuestion(answers, maxTypos) { return { type: 'basic', content: { maxTypos, answers } }; } (0, _ava.default)('should return true when the accepted answer contain empty string', t => { const question = createQuestion([['viral'], ['']]); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, [' ']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['viral']); }); (0, _ava.default)('should return true when the given answer is in the accepted answers', t => { const question = createQuestion([['guillaume tell'], ['tell'], ['guillaume'], ['tel']]); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['guillaume tell']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['tell']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['guillaume']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['tel']); }); (0, _ava.default)('should return true even when the given answer does not have the same case as the accepted answers', t => { const question = createQuestion([['answer2']]); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['ANSWER2']); }); (0, _ava.default)('should return false when the given answer is not in the accepted answers', t => { const question = createQuestion([['guillaume tell'], ['tell'], ['guillaume'], ['tel']]); (0, _assertCheckAnswerCorrectness.assertIncorrect)(t, config, question, ['foo'], [false]); (0, _assertCheckAnswerCorrectness.assertIncorrect)(t, config, question, ['bar'], [false]); (0, _assertCheckAnswerCorrectness.assertIncorrect)(t, config, question, ['gui'], [false]); }); (0, _ava.default)('should return true when the given answer closely resembles an accepted answer', t => { const question = createQuestion([['guillaume tell'], ['tell'], ['guillaume'], ['tel']]); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['tel']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['Tel']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['téll']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['Guillaume Telle']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['GUILLAUME TELLE']); }); (0, _ava.default)('should allow typos by default', t => { const question = createQuestion([['foooooooooooo']]); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['foooooooooooo']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['foooooooooooa']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['fooooooooooaa']); (0, _assertCheckAnswerCorrectness.assertIncorrect)(t, config, question, ['foooooooooaaa'], [false]); }); (0, _ava.default)('should trim the given answer before comparing', t => { const question = createQuestion([['foo']], 0); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, configWithTypos, question, ['foo ']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, configWithTypos, question, [' foo']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, configWithTypos, question, [' foo ']); (0, _assertCheckAnswerCorrectness.assertIncorrect)(t, configWithTypos, question, [' fooo'], [false]); (0, _assertCheckAnswerCorrectness.assertIncorrect)(t, configWithTypos, question, ['A foo'], [false]); }); (0, _ava.default)('should trim the accepted answers before comparing', t => { const question = createQuestion([[' foo ']], 0); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, configWithTypos, question, ['foo ']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, configWithTypos, question, [' foo']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, configWithTypos, question, [' foo ']); (0, _assertCheckAnswerCorrectness.assertIncorrect)(t, configWithTypos, question, [' fooo'], [false]); (0, _assertCheckAnswerCorrectness.assertIncorrect)(t, configWithTypos, question, ['A foo'], [false]); }); (0, _ava.default)('should be able to define the number of typos in the question', t => { const question = createQuestion([['foooooooooooo']], 3); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['foooooooooooo']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['foooooooooooa']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['fooooooooooaa']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['foooooooooaaa']); (0, _assertCheckAnswerCorrectness.assertIncorrect)(t, config, question, ['fooooooooaaaa'], [false]); }); (0, _ava.default)('should consider the max number of typos from the slide before the one in the config', t => { const question = createQuestion([['foooooooooooo']], 1); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, configWithTypos, question, ['foooooooooooo']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, configWithTypos, question, ['foooooooooooa']); (0, _assertCheckAnswerCorrectness.assertIncorrect)(t, configWithTypos, question, ['fooooooooooaa'], [false]); }); (0, _ava.default)('should consider the max number of typos from the slide before the one in the config (with no typos)', t => { const question = createQuestion([['foooooooooooo']], 0); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, configWithTypos, question, ['foooooooooooo']); (0, _assertCheckAnswerCorrectness.assertIncorrect)(t, configWithTypos, question, ['foooooooooooa'], [false]); (0, _assertCheckAnswerCorrectness.assertIncorrect)(t, configWithTypos, question, ['fooooooooooaa'], [false]); }); (0, _ava.default)('should use the number of typos from the config if the one in question equals null', t => { const question = createQuestion([['foooooooooooo']], null); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, configWithTypos, question, ['foooooooooooo']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, configWithTypos, question, ['foooooooooooa']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, configWithTypos, question, ['fooooooooooaa']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, configWithTypos, question, ['foooooooooaaa']); (0, _assertCheckAnswerCorrectness.assertIncorrect)(t, configWithTypos, question, ['foooooooaaaaa'], [false]); }); (0, _ava.default)('should return true when the given answer contains an accepted answer', t => { const question = createQuestion([['Guillaume']]); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['Guillaume Bacon']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['We should tell guillaume something about QA']); }); (0, _ava.default)('should return true when the given answer includes an accepted answer that touches unrelated characters up to a certain limit', t => { const question = createQuestion([['Guillaume'], ['Tell']]); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['ZGuillaume']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['GuillaumeZ']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['ZGuillaumeZ']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['ZZGuillaumeZZ']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['ZZGuillaumeZZZ']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['ZZZGuillaumeZZ']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['ZZZZZGuillaume']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['GuillaumeZZZZZ']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['ZZZZZTellZZZZZ']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['We should tell ZZguillaume something about QA']); }); (0, _ava.default)('should return false when the given answer includes an accepted answer but touches too many unrelated characters', t => { const question = createQuestion([['Guillaume']]); (0, _assertCheckAnswerCorrectness.assertIncorrect)(t, config, question, ['GuillaumeZZZZZZ'], [false]); (0, _assertCheckAnswerCorrectness.assertIncorrect)(t, config, question, ['ZZZZZZGuillaume'], [false]); (0, _assertCheckAnswerCorrectness.assertIncorrect)(t, config, question, ['We should tell ZZZZZZguillaume something about QA'], [false]); }); (0, _ava.default)('should return false when the given answer includes an accepted answer but has a typo', t => { const question = createQuestion([['this exact phrase']]); (0, _assertCheckAnswerCorrectness.assertIncorrect)(t, config, question, ['ZZthis exactz phraseZZ'], [false]); }); (0, _ava.default)('should return false when the words are given in a different order', t => { const question = createQuestion([['this order']]); (0, _assertCheckAnswerCorrectness.assertIncorrect)(t, config, question, ['order this'], [false]); }); (0, _ava.default)('should return false when the given answer has typos and is in the midst of other words', t => { const question = createQuestion([['though question']]); (0, _assertCheckAnswerCorrectness.assertIncorrect)(t, config, question, ['XXXtouff questionXXX'], [false]); }); (0, _ava.default)('should return true when the given answer includes an accepted answer that touches unrelated characters up to a certain limit (simple word)', t => { const question = createQuestion([['Bob'], ['Guillaume']]); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['ZGuillaume']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['Zguillaume']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['GuillaumeZ']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['ZGuillaumeZ']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['ZZGuillaumeZZ']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['ZZGuillaumeZZZ']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['ZZZGuillaumeZZ']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['ZZZZZGuillaume']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['GuillaumeZZZZZ']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['We should tell ZZguillaume something about QA']); }); (0, _ava.default)('should return true when the given answer includes an accepted answer that touches unrelated characters up to a certain limit (multiple words)', t => { const question = createQuestion([['Guillaume Tell']]); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['ZGuillaume Tell']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['ZGuillaume tell']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['Guillaume TellZ']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['ZGuillaume TellZ']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['ZZGuillaume TellZZ']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['ZZGuillaume TellZZZ']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['ZZZGuillaume TellZZ']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['ZZZZZGuillaume Tell']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['Guillaume TellZZZZZ']); (0, _assertCheckAnswerCorrectness.assertCorrect)(t, config, question, ['We should tell ZZguillaume Tell something about QA']); }); (0, _ava.default)('should return false when the given answer is an empty string', t => { const question = createQuestion([['Guillaume Tell']]); (0, _assertCheckAnswerCorrectness.assertIncorrect)(t, config, question, [''], [false]); }); (0, _ava.default)("should return false when the given answer isn't defined", t => { const question = createQuestion([['Guillaume Tell']]); (0, _assertCheckAnswerCorrectness.assertIncorrect)(t, config, question, [], []); }); (0, _ava.default)('should return false when there are no correct answers', t => { const question = createQuestion([]); (0, _assertCheckAnswerCorrectness.assertIncorrectEmptyAnswer)(t, config, question, []); (0, _assertCheckAnswerCorrectness.assertIncorrectEmptyAnswer)(t, config, question, ['foo']); }); //# sourceMappingURL=check-answer-correctness.basic.js.map