Skip to content

Commit

Permalink
Merge pull request #3382 from serlo/staging
Browse files Browse the repository at this point in the history
Deployment
  • Loading branch information
Entkenntnis authored Feb 15, 2024
2 parents 2e1fc69 + 40ba1fd commit 51c2cbd
Show file tree
Hide file tree
Showing 37 changed files with 1,052 additions and 370 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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)
})
})
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('.')
})
})
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')
})
})
4 changes: 4 additions & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,13 @@
"postcss": "^8.4.31",
"qrcode.react": "^3.1.0",
"ramda": "^0.29.1",
"rdndmb-html5-to-touch": "^8.0.3",
"react": "^18.2.0",
"react-diff-viewer": "^3.1.1",
"react-dnd": "^16.0.1",
"react-dnd-html5-backend": "^16.0.1",
"react-dnd-multi-backend": "^8.0.3",
"react-dnd-touch-backend": "^16.0.1",
"react-dom": "^18.2.0",
"react-hotkeys-hook": "^4.4.1",
"react-lazyload": "^3.2.0",
Expand Down Expand Up @@ -126,6 +129,7 @@
"@types/ramda": "^0.29.6",
"@types/react": "^18.0.25",
"@types/react-beautiful-dnd": "^13.1.5",
"@types/react-dnd-multi-backend": "^6.0.6",
"@types/react-dom": "^18.0.8",
"@types/react-lazyload": "^3.2.1",
"@types/react-modal": "^3.16.1",
Expand Down
Loading

0 comments on commit 51c2cbd

Please sign in to comment.