-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3382 from serlo/staging
Deployment
- Loading branch information
Showing
37 changed files
with
1,052 additions
and
370 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+13 KB
.yarn/cache/@react-dnd-shallowequal-npm-2.0.0-2a10dca275-b5bbdc795d.zip
Binary file not shown.
Binary file added
BIN
+5.56 KB
.yarn/cache/@types-react-dnd-multi-backend-npm-6.0.6-67a4778133-5774db8644.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+3.52 KB
.yarn/cache/rdndmb-html5-to-touch-npm-8.0.3-1586002902-b245145cc3.zip
Binary file not shown.
Binary file added
BIN
+11.1 KB
.yarn/cache/react-dnd-multi-backend-npm-8.0.3-6fb78e4cb8-75a78c4a42.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+61.3 KB
.yarn/cache/react-dnd-touch-backend-npm-10.0.2-49c235fe26-62f8ad6637.zip
Binary file not shown.
Binary file added
BIN
+37.5 KB
.yarn/cache/react-dnd-touch-backend-npm-16.0.1-2b96ba84be-5362c5f426.zip
Binary file not shown.
139 changes: 139 additions & 0 deletions
139
apps/web/__tests__/editor/input-exercise-plugin/expression-equal-evaluation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
import { getMatchingAnswer } from '@editor/plugins/input-exercise/helper/get-matching-answer' | ||
import { InputExerciseType } from '@editor/plugins/input-exercise/input-exercise-type' | ||
import { evaluate } from 'mathjs' | ||
|
||
const answers = [ | ||
{ | ||
value: '1', | ||
isCorrect: true, | ||
feedback: null, | ||
}, | ||
{ | ||
value: '2', | ||
isCorrect: false, | ||
feedback: null, | ||
}, | ||
{ | ||
value: '4.0', | ||
isCorrect: true, | ||
feedback: null, | ||
}, | ||
{ | ||
value: '4,1', | ||
isCorrect: true, | ||
feedback: null, | ||
}, | ||
{ | ||
value: '123', | ||
isCorrect: true, | ||
feedback: null, | ||
}, | ||
{ | ||
value: 'answer', | ||
isCorrect: true, | ||
feedback: null, | ||
}, | ||
{ | ||
value: '.', | ||
isCorrect: true, | ||
feedback: null, | ||
}, | ||
] | ||
|
||
function getExpressionEqualAnswer(value: string) { | ||
return getMatchingAnswer( | ||
answers, | ||
value, | ||
InputExerciseType.ExpressionEqual, | ||
evaluate | ||
) | ||
} | ||
|
||
describe('input-exercise-plugin: getMatchingAnswer (ExpressionEqual)', () => { | ||
test('correct value matching answer', () => { | ||
const answer = getExpressionEqualAnswer('1') | ||
expect(!!answer).toBe(true) | ||
expect(answer?.value).toBe('1') | ||
}) | ||
|
||
test('value matching incorrect but existing answer', () => { | ||
const answer = getExpressionEqualAnswer('2') | ||
expect(!!answer).toBe(true) | ||
expect(answer?.value).toBe('2') | ||
}) | ||
|
||
test('incorrect value not matching existing answer', () => { | ||
const answer = getExpressionEqualAnswer('333') | ||
expect(answer).toBe(undefined) | ||
}) | ||
|
||
test('correct value matching answer with dot', () => { | ||
const answer = getExpressionEqualAnswer('4.0') | ||
expect(!!answer).toBe(true) | ||
expect(answer?.value).toBe('4.0') | ||
}) | ||
|
||
test('correct value with comma still matches answer with dot', () => { | ||
const answer = getExpressionEqualAnswer('4,0') | ||
expect(!!answer).toBe(true) | ||
expect(answer?.value).toBe('4.0') | ||
}) | ||
|
||
test('correct value without decimal place does not match answer with decimal place', () => { | ||
const answer = getExpressionEqualAnswer('4') | ||
expect(!!answer).toBe(true) | ||
expect(answer?.value).toBe('4.0') | ||
}) | ||
|
||
test('correct value matching answer with comma', () => { | ||
const answer = getExpressionEqualAnswer('4,1') | ||
expect(!!answer).toBe(true) | ||
expect(answer?.value).toBe('4,1') | ||
}) | ||
|
||
test('correct value with dot still matches answer with comma', () => { | ||
const answer = getExpressionEqualAnswer('4.1') | ||
expect(!!answer).toBe(true) | ||
expect(answer?.value).toBe('4,1') | ||
}) | ||
|
||
test('formulas get parsed to match correct answer', () => { | ||
const answer = getExpressionEqualAnswer('10 / 10') | ||
expect(!!answer).toBe(true) | ||
expect(answer?.value).toBe('1') | ||
}) | ||
|
||
test('formulas get parsed to match correct answer', () => { | ||
const answer = getExpressionEqualAnswer('10/10') | ||
expect(!!answer).toBe(true) | ||
expect(answer?.value).toBe('1') | ||
}) | ||
|
||
test('formulas get parsed to match correct answer', () => { | ||
const answer = getExpressionEqualAnswer('10 - 9') | ||
expect(!!answer).toBe(true) | ||
expect(answer?.value).toBe('1') | ||
}) | ||
|
||
test('formulas get parsed to match correct answer', () => { | ||
const answer = getExpressionEqualAnswer('0.5*2') | ||
expect(!!answer).toBe(true) | ||
expect(answer?.value).toBe('1') | ||
}) | ||
|
||
test('formulas get parsed to match correct answer', () => { | ||
const answer = getExpressionEqualAnswer('0,5*2') | ||
expect(!!answer).toBe(true) | ||
expect(answer?.value).toBe('1') | ||
}) | ||
|
||
// … just curious | ||
test('value with string', () => { | ||
const answer = getExpressionEqualAnswer('answer') | ||
expect(answer).toBe(undefined) | ||
}) | ||
test('dot as value', () => { | ||
const answer = getExpressionEqualAnswer('.') | ||
expect(answer).toBe(undefined) | ||
}) | ||
}) |
110 changes: 110 additions & 0 deletions
110
apps/web/__tests__/editor/input-exercise-plugin/number-exact-evaluation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import { getMatchingAnswer } from '@editor/plugins/input-exercise/helper/get-matching-answer' | ||
import { InputExerciseType } from '@editor/plugins/input-exercise/input-exercise-type' | ||
import { evaluate } from 'mathjs' | ||
|
||
const answers = [ | ||
{ | ||
value: '1', | ||
isCorrect: true, | ||
feedback: null, | ||
}, | ||
{ | ||
value: '2', | ||
isCorrect: false, | ||
feedback: null, | ||
}, | ||
{ | ||
value: '4.0', | ||
isCorrect: true, | ||
feedback: null, | ||
}, | ||
{ | ||
value: '4,1', | ||
isCorrect: true, | ||
feedback: null, | ||
}, | ||
{ | ||
value: '123', | ||
isCorrect: true, | ||
feedback: null, | ||
}, | ||
{ | ||
value: 'answer', | ||
isCorrect: true, | ||
feedback: null, | ||
}, | ||
{ | ||
value: '.', | ||
isCorrect: true, | ||
feedback: null, | ||
}, | ||
] | ||
|
||
function getNumberExactAnswer(value: string) { | ||
return getMatchingAnswer( | ||
answers, | ||
value, | ||
InputExerciseType.NumberExact, | ||
evaluate | ||
) | ||
} | ||
|
||
describe('input-exercise-plugin: getMatchingAnswer (NumberExact)', () => { | ||
test('correct value matching answer', () => { | ||
const answer = getNumberExactAnswer('1') | ||
expect(!!answer).toBe(true) | ||
expect(answer?.value).toBe('1') | ||
}) | ||
|
||
test('value matching incorrect but existing answer', () => { | ||
const answer = getNumberExactAnswer('2') | ||
expect(!!answer).toBe(true) | ||
expect(answer?.value).toBe('2') | ||
}) | ||
|
||
test('incorrect value not matching existing answer', () => { | ||
const answer = getNumberExactAnswer('333') | ||
expect(answer).toBe(undefined) | ||
}) | ||
|
||
test('correct value matching answer with dot', () => { | ||
const answer = getNumberExactAnswer('4.0') | ||
expect(!!answer).toBe(true) | ||
expect(answer?.value).toBe('4.0') | ||
}) | ||
|
||
test('correct value with comma still matches answer with dot', () => { | ||
const answer = getNumberExactAnswer('4,0') | ||
expect(!!answer).toBe(true) | ||
expect(answer?.value).toBe('4.0') | ||
}) | ||
|
||
test('correct value without decimal place does not match answer with decimal place', () => { | ||
const answer = getNumberExactAnswer('4') | ||
expect(answer).toBe(undefined) | ||
}) | ||
|
||
test('correct value matching answer with comma', () => { | ||
const answer = getNumberExactAnswer('4,1') | ||
expect(!!answer).toBe(true) | ||
expect(answer?.value).toBe('4,1') | ||
}) | ||
|
||
test('correct value with dot still matches answer with comma', () => { | ||
const answer = getNumberExactAnswer('4.1') | ||
expect(!!answer).toBe(true) | ||
expect(answer?.value).toBe('4,1') | ||
}) | ||
|
||
// … curious but probably okay | ||
test('value with string', () => { | ||
const answer = getNumberExactAnswer('answer') | ||
expect(!!answer).toBe(true) | ||
expect(answer?.value).toBe('answer') | ||
}) | ||
test('dot as value', () => { | ||
const answer = getNumberExactAnswer('.') | ||
expect(!!answer).toBe(true) | ||
expect(answer?.value).toBe('.') | ||
}) | ||
}) |
88 changes: 88 additions & 0 deletions
88
apps/web/__tests__/editor/input-exercise-plugin/string-match-evaluation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { getMatchingAnswer } from '@editor/plugins/input-exercise/helper/get-matching-answer' | ||
import { InputExerciseType } from '@editor/plugins/input-exercise/input-exercise-type' | ||
import { evaluate } from 'mathjs' | ||
|
||
const answers = [ | ||
{ | ||
value: 'answeralso', | ||
isCorrect: false, | ||
feedback: null, | ||
}, | ||
{ | ||
value: 'answer', | ||
isCorrect: true, | ||
feedback: null, | ||
}, | ||
{ | ||
value: 'wrong', | ||
isCorrect: false, | ||
feedback: null, | ||
}, | ||
{ | ||
value: 'UPPERCASE', | ||
isCorrect: true, | ||
feedback: null, | ||
}, | ||
{ | ||
value: '123', | ||
isCorrect: true, | ||
feedback: null, | ||
}, | ||
{ | ||
value: '€$%&/(()=?``', | ||
isCorrect: true, | ||
feedback: null, | ||
}, | ||
] | ||
|
||
function getStringNormalizedAnswer(value: string) { | ||
return getMatchingAnswer( | ||
answers, | ||
value, | ||
InputExerciseType.StringNormalized, | ||
evaluate | ||
) | ||
} | ||
|
||
describe('input-exercise-plugin: getMatchingAnswer (StringMatch)', () => { | ||
test('correct value matching answer', () => { | ||
const answer = getStringNormalizedAnswer('answer') | ||
expect(!!answer).toBe(true) | ||
expect(answer?.value).toBe('answer') | ||
}) | ||
|
||
test('value matching incorrect but existing answer', () => { | ||
const answer = getStringNormalizedAnswer('wrong') | ||
expect(answer?.isCorrect).toBe(false) | ||
expect(answer?.value).toBe('wrong') | ||
}) | ||
|
||
test('incorrect value not matching existing answer', () => { | ||
const answer = getStringNormalizedAnswer('somewrongstring') | ||
expect(answer).toBe(undefined) | ||
}) | ||
|
||
test('correct value matching answer with uppercase', () => { | ||
const answer = getStringNormalizedAnswer('UPPERCASE') | ||
expect(!!answer).toBe(true) | ||
expect(answer?.value).toBe('UPPERCASE') | ||
}) | ||
|
||
test('value with differing case still matches answer', () => { | ||
const answer = getStringNormalizedAnswer('uppercase') | ||
expect(!!answer).toBe(true) | ||
expect(answer?.value).toBe('UPPERCASE') | ||
}) | ||
|
||
test('value with special characters', () => { | ||
const answer = getStringNormalizedAnswer('€$%&/(()=?``') | ||
expect(!!answer).toBe(true) | ||
expect(answer?.value).toBe('€$%&/(()=?``') | ||
}) | ||
|
||
test('value does not match other string that starts with the same characters', () => { | ||
const answer = getStringNormalizedAnswer('answeralso') | ||
expect(answer?.isCorrect).toBe(false) | ||
expect(answer?.value).toBe('answeralso') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.