mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-04 17:59:49 +08:00
An ambiguous key such as "12.500 €" was read in the convention the
answer proved, so "12.5" became a final "correct" for what is 12 500 in
German notation (likewise "12.5 TEUR" for "12.500 TEUR"). Only the key's
own notation now fixes how the key is read; the answer may still borrow
the key's convention. An unproven key must match under both readings,
otherwise the result is ambiguous.
Precision follows half-away-from-zero rounding with exact rationals:
"3.48" accepts [3.475, 3.485) instead of a closed interval plus an
epsilon, which also made "1.5e-99" equal to an integer key "0". A key
more precise than the answer's rounding ("3,48" for "3,4833") and a bare
value below 1 for a percent key ("0.5" for "0.5%") are ambiguous instead
of a final verdict.
The web port now uses BigInt rationals like Python's Fraction, and both
ports reject tokens over 30 digits, so the shared vectors cannot drift on
large values. The unused rel_tol/abs_tol parameters are removed.
Signed-off-by: Benjamin Schwing <63053132+BenjiAvH@users.noreply.github.com>
50 lines
1.4 KiB
TypeScript
50 lines
1.4 KiB
TypeScript
import { readFileSync } from 'node:fs'
|
|
import path from 'node:path'
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
import { numericEquivalent } from '@/lib/numeric-answer'
|
|
|
|
interface Vector {
|
|
user: string
|
|
expected: string
|
|
comparable: boolean
|
|
correct: boolean
|
|
ambiguous?: boolean
|
|
}
|
|
|
|
// Shared with deeptutor/learning/tests/test_grading.py so both ports agree.
|
|
const { vectors } = JSON.parse(
|
|
readFileSync(path.resolve(process.cwd(), '../tests/fixtures/numeric_answers.json'), 'utf8')
|
|
) as { vectors: Vector[] }
|
|
|
|
describe('numericEquivalent shared vectors', () => {
|
|
it.each(vectors)('$user ~ $expected', vector => {
|
|
const result = numericEquivalent(vector.user, vector.expected)
|
|
expect({
|
|
comparable: result.comparable,
|
|
correct: result.correct,
|
|
ambiguous: result.ambiguous,
|
|
}).toEqual({
|
|
comparable: vector.comparable,
|
|
correct: vector.correct,
|
|
ambiguous: vector.ambiguous ?? false,
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('numericEquivalent', () => {
|
|
it('reports each labelled part', () => {
|
|
const result = numericEquivalent('b) 3,6; a) 12', 'a) 12; b) 3,5')
|
|
expect(result.parts.map(p => [p.label, p.correct])).toEqual([
|
|
['a', true],
|
|
['b', false],
|
|
])
|
|
})
|
|
})
|
|
|
|
describe('numericEquivalent units', () => {
|
|
it('does not treat object prototype keys as currencies', () => {
|
|
expect(numericEquivalent('5 constructor', '5 units').comparable).toBe(false)
|
|
})
|
|
})
|