From bc32e2b16786257398c2e8533a18216a177c81c9 Mon Sep 17 00:00:00 2001 From: Chris Sangwin Date: Thu, 16 Jan 2025 09:16:35 +0000 Subject: [PATCH] fix to issue #1359: add Dioptre as extra units. --- stack/cas/casstring.units.class.php | 1 + tests/fixtures/answertestfixtures.class.php | 1 + tests/input_units_test.php | 13 +++++++++++++ 3 files changed, 15 insertions(+) diff --git a/stack/cas/casstring.units.class.php b/stack/cas/casstring.units.class.php index 773915e37c..b56516bdb5 100644 --- a/stack/cas/casstring.units.class.php +++ b/stack/cas/casstring.units.class.php @@ -156,6 +156,7 @@ class stack_cas_casstring_units { ['yd', '36*in', 'yd', 'yard'], ['mi', '5280*12*in', 'mi', 'mile'], ['lb', '4.4482*N', 'lb', 'pound'], + ['dpt', '1/m', 'dpt', 'Dioptre'], ]; /** diff --git a/tests/fixtures/answertestfixtures.class.php b/tests/fixtures/answertestfixtures.class.php index 55621f4898..696bfb4319 100644 --- a/tests/fixtures/answertestfixtures.class.php +++ b/tests/fixtures/answertestfixtures.class.php @@ -2484,6 +2484,7 @@ class stack_answertest_test_data { ['Units', '1', '0.0*km/s', '0.0*m/s', 1, 'ATUnits_compatible_units m/s.', ''], ['Units', '1', '0.0*m', '0.0*m/s', 0, 'ATUnits_incompatible_units. ATUnits_correct_numerical.', ''], ['Units', '1', '0.0', '0.0*m/s', 0, 'ATUnits_SA_no_units.', ''], + ['Units', '3', '0.200*dpt', '0.200/m', 1, 'ATUnits_compatible_units 1/m.', ''], ['Units', '1', '7*in', '7*in', 1, 'ATUnits_units_match.', 'Imperial'], ['Units', '1', '6*in', '0.5*ft', 1, 'ATUnits_compatible_units in.', ''], ['Units', '4', '2640*ft', '0.5*mi', 1, 'ATNumSigFigs_WithinRange. ATUnits_compatible_units in.', ''], diff --git a/tests/input_units_test.php b/tests/input_units_test.php index 1f5924b12e..48febfc74b 100644 --- a/tests/input_units_test.php +++ b/tests/input_units_test.php @@ -1327,4 +1327,17 @@ public function test_validate_student_response_complex_1(): void { $state->contentsdisplayed); $this->assertEquals('', $state->errors); } + + public function test_validate_student_response_dpt(): void { + $options = new stack_options(); + $el = stack_input_factory::make('units', 'sans1', '0.520*dpt'); + $el->set_parameter('insertStars', 1); + $state = $el->validate_student_response(['sans1' => '0.520*dpt'], $options, '0.520*dpt', + new stack_cas_security(true)); + $this->assertEquals(stack_input::VALID, $state->status); + $this->assertEquals('', $state->note); + $this->assertEquals('0.520*dpt', $state->contentsmodified); + $this->assertEquals('\[ 0.520\, \mathrm{dpt} \]', $state->contentsdisplayed); + $this->assertEquals('', $state->errors); + } }