From aa05e5cc74dfca2d6804de35f63ebd0bd53989b6 Mon Sep 17 00:00:00 2001 From: Boyd Duffee Date: Fri, 6 Jan 2023 13:12:40 +0000 Subject: [PATCH 1/6] Add aliases for Angstrom to Units.pm The SI symbol for the ampere is "A", which PG uses to mean Angstrom. To facilitate the migration of the Angstrom unit from "A" to "Angstrom" (or something else), this change adds in two aliases so that documentation and code can be updated before a breaking change is made. --- lib/Units.pm | 10 ++++++++++ t/units/length.t | 2 ++ 2 files changed, 12 insertions(+) diff --git a/lib/Units.pm b/lib/Units.pm index 6dd6dc52fa..99cb4b2ec0 100644 --- a/lib/Units.pm +++ b/lib/Units.pm @@ -224,6 +224,8 @@ our %known_units = ( # um -- micrometer # nm -- nanometer # A -- Angstrom + # Angstrom -- Angstrom + # angstrom -- Angstrom # pm -- picometer # fm -- femtometer # @@ -255,6 +257,14 @@ our %known_units = ( 'factor' => 1E-10, 'm' => 1 }, + 'Angstrom' => { + 'factor' => 1E-10, + 'm' => 1 + }, + 'angstrom' => { + 'factor' => 1E-10, + 'm' => 1 + }, 'pm' => { 'factor' => 1E-12, 'm' => 1 diff --git a/t/units/length.t b/t/units/length.t index 7b4333c899..989d03ec00 100644 --- a/t/units/length.t +++ b/t/units/length.t @@ -15,6 +15,7 @@ loadMacros('parserNumberWithUnits.pl'); my $micron = NumberWithUnits(1, 'um'); my $picometer = NumberWithUnits(1E6, 'pm'); my $femtometer = NumberWithUnits(1E9, 'fm'); +my $angstrom = NumberWithUnits(1E4, 'Angstrom'); subtest 'LaTeX output' => sub { is $picometer->TeX, '1\times 10^{6}\ {\rm pm}', 'LaTeX output for 1E6 picometers'; @@ -26,6 +27,7 @@ subtest 'LaTeX output' => sub { subtest 'Equivalent to micrometer' => sub { is check_score($picometer, $micron), 1, '1 micrometer in picometers'; is check_score($femtometer, $micron), 1, '1 micrometer in femtometers'; + is check_score($angstrom, $micron), 1, '1 micrometer in picometers'; }; done_testing(); From 6fbf9138da5524bd8e2241fb255ec624370b1494 Mon Sep 17 00:00:00 2001 From: Boyd Duffee Date: Mon, 30 Jan 2023 21:45:05 +0000 Subject: [PATCH 2/6] Change A from angstrom to ampere in Units.pm MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a breaking change for problems that use A as angstrom. Add in the unicode character Å \x{00C5} to Units.pm as an alias for angstrom. Add test for A as ampere and allow unit names to match a unicode character --- lib/Units.pm | 19 ++++++++++--------- t/units/basic_parser.t | 2 +- t/units/conversions.t | 2 +- t/units/electromagnetic.t | 8 +++++++- t/units/length.t | 2 +- 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/lib/Units.pm b/lib/Units.pm index 99cb4b2ec0..094dbefaf6 100644 --- a/lib/Units.pm +++ b/lib/Units.pm @@ -7,6 +7,7 @@ sub evaluate_units { # Methods for evaluating units in answers package Units; +use utf8; #require Exporter; #@ISA = qw(Exporter); @@ -223,9 +224,9 @@ our %known_units = ( # micron -- micrometer # um -- micrometer # nm -- nanometer - # A -- Angstrom - # Angstrom -- Angstrom - # angstrom -- Angstrom + # angstrom -- angstrom + # Angstrom -- angstrom + # Å -- angstrom # pm -- picometer # fm -- femtometer # @@ -253,7 +254,7 @@ our %known_units = ( 'factor' => 1E-9, 'm' => 1 }, - 'A' => { + 'angstrom' => { 'factor' => 1E-10, 'm' => 1 }, @@ -261,7 +262,7 @@ our %known_units = ( 'factor' => 1E-10, 'm' => 1 }, - 'angstrom' => { + 'Å' => { # unicode "\x{00C5}" 'factor' => 1E-10, 'm' => 1 }, @@ -722,8 +723,8 @@ our %known_units = ( # kohm -- kilo-ohm # Mohm -- mega-ohm # S -- siemens + # A -- ampere # mA -- milli-ampere - # mamp -- milli-ampere # 'C' => { 'factor' => 1, @@ -822,11 +823,11 @@ our %known_units = ( 'amp' => 2, 's' => 3, }, - 'mA' => { # milliampere - 'factor' => 0.001, + 'A' => { # ampere + 'factor' => 1, 'amp' => 1, }, - 'mamp' => { + 'mA' => { # milliampere 'factor' => 0.001, 'amp' => 1, }, diff --git a/t/units/basic_parser.t b/t/units/basic_parser.t index 06b3b80dc3..3a992741c8 100644 --- a/t/units/basic_parser.t +++ b/t/units/basic_parser.t @@ -115,7 +115,7 @@ subtest 'Check some known units' => sub { ok my @unit_names = (split /\|/, $joule->getUnitNames), 'Can getUnitNames'; is \@unit_names, bag { - all_items(match qr/^[-%\w]+$/); + all_items(match qr/^(?:[-%\w]+|\p{Lu})$/); item 'J'; item 'N'; item 'm'; diff --git a/t/units/conversions.t b/t/units/conversions.t index eca9d39af9..f744254ea6 100644 --- a/t/units/conversions.t +++ b/t/units/conversions.t @@ -29,7 +29,7 @@ subtest 'Check fundamental units' => sub { is \%Units::known_units, hash { field m => { factor => 1, m => 1 }; - all_keys match qr/^(?:[a-z02]+(?:-\w+)?|%)$/i; + all_keys match qr/^(?:[a-z02]+(?:-\w+)?|%|\p{Lu})$/i; all_vals hash { field factor => !number(0); diff --git a/t/units/electromagnetic.t b/t/units/electromagnetic.t index cd51d38fb0..1b85f161c1 100644 --- a/t/units/electromagnetic.t +++ b/t/units/electromagnetic.t @@ -17,7 +17,8 @@ my $milliwatt = NumberWithUnits(1E3, 'mW'); my $megawatt = NumberWithUnits(1E-6, 'MW'); my $amp = NumberWithUnits(1, 'amp'); -my $milliamp = NumberWithUnits(1, 'mamp'); +my $ampere = NumberWithUnits(1, 'A'); +my $milliamp = NumberWithUnits(1000, 'mA'); my $tesla = NumberWithUnits(1, 'T'); my $millitesla = NumberWithUnits(1000, 'mT'); @@ -41,6 +42,11 @@ subtest 'LaTeX output' => sub { is $microcoulomb->TeX, '1\times 10^{6}\ {\rm \mu C}', 'LaTeX output for micrometers'; }; +subtest 'Current' => sub { + is check_score($amp, $ampere), 1, '1 amp is 1 ampere'; + is check_score($milliamp, $ampere), 1, '1000 milliamps is 1 ampere'; +}; + subtest 'Charge' => sub { is check_score($millicoulomb, $coulomb), 1, '1000 millicoulombs is 1 coulomb'; is check_score($nanocoulomb, $coulomb), 1, '10^9 nanocoulombs is 1 coulomb'; diff --git a/t/units/length.t b/t/units/length.t index 989d03ec00..c4b47d593f 100644 --- a/t/units/length.t +++ b/t/units/length.t @@ -15,7 +15,7 @@ loadMacros('parserNumberWithUnits.pl'); my $micron = NumberWithUnits(1, 'um'); my $picometer = NumberWithUnits(1E6, 'pm'); my $femtometer = NumberWithUnits(1E9, 'fm'); -my $angstrom = NumberWithUnits(1E4, 'Angstrom'); +my $angstrom = NumberWithUnits(1E4, 'angstrom'); subtest 'LaTeX output' => sub { is $picometer->TeX, '1\times 10^{6}\ {\rm pm}', 'LaTeX output for 1E6 picometers'; From efbc16cb6c5ffa5365cfbbc568c674921a1c1383 Mon Sep 17 00:00:00 2001 From: Boyd Duffee Date: Tue, 31 Jan 2023 18:10:17 +0000 Subject: [PATCH 3/6] perltidy --- t/units/basic_parser.t | 1 + t/units/conversions.t | 15 ++++++++++----- t/units/electromagnetic.t | 4 ++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/t/units/basic_parser.t b/t/units/basic_parser.t index 3a992741c8..97fc349650 100644 --- a/t/units/basic_parser.t +++ b/t/units/basic_parser.t @@ -147,6 +147,7 @@ subtest 'Check display methods' => sub { }; subtest 'Check possible answer format branches' => sub { + # re-write without check_score so we can get the messages to students is check_score($joule, '1 J'), 1, 'one Joule plain'; diff --git a/t/units/conversions.t b/t/units/conversions.t index f744254ea6..10f3ea0d8e 100644 --- a/t/units/conversions.t +++ b/t/units/conversions.t @@ -49,9 +49,11 @@ subtest 'Check base units' => sub { is { evaluate_units('V') }, in_base_units(amp => -1, s => -3, kg => 1, m => 2, factor => 1), 'Volt'; is { evaluate_units('J*s') }, in_base_units(kg => 1, m => 2, s => -1, factor => 1), 'Joule-seconds'; - is { evaluate_units('V/m') }, in_base_units(kg => 1, m => 1, s => -3, amp => -1, factor => 1), + is { evaluate_units('V/m') }, + in_base_units(kg => 1, m => 1, s => -3, amp => -1, factor => 1), 'Volts per metre'; - is { evaluate_units('N/C') }, in_base_units(kg => 1, m => 1, s => -3, amp => -1, factor => 1), + is { evaluate_units('N/C') }, + in_base_units(kg => 1, m => 1, s => -3, amp => -1, factor => 1), 'Newtons per Coulomb'; }; @@ -98,13 +100,15 @@ subtest 'Check a collection of units' => sub { is multiply_by(1e9, evaluate_units('Pa')), { evaluate_units('GPa') }, 'gigapascal conversion'; is multiply_by(1000, evaluate_units('kPa')), { evaluate_units('MPa') }, 'kilopascal conversion'; - is multiply_by(2 * 1000 * $Units::PI, evaluate_units('rad/s')), { evaluate_units('kHz') }, + is multiply_by(2 * 1000 * $Units::PI, evaluate_units('rad/s')), + { evaluate_units('kHz') }, 'kilohertz conversion'; is multiply_by(0.01, %Units::fundamental_units), { evaluate_units('%') }, 'percent conversion'; my $todo = todo 'use within() to fudge factor in 9th decimal place'; - is multiply_by((180 / $Units::PI)**2, evaluate_units('deg^2')), { evaluate_units('sr') }, + is multiply_by((180 / $Units::PI)**2, evaluate_units('deg^2')), + { evaluate_units('sr') }, 'solid angle conversion'; }; @@ -115,7 +119,8 @@ subtest 'Check astronomical units' => sub { is { evaluate_units('c*yr') }, { evaluate_units('light-year') }, 'light year'; my $todo = todo 'use within() to fudge factor in 9th decimal place'; - is multiply_by(cos($second_arc) / sin($second_arc), evaluate_units('AU')), { evaluate_units('parsec') }, + is multiply_by(cos($second_arc) / sin($second_arc), evaluate_units('AU')), + { evaluate_units('parsec') }, 'parsec conversion'; }; diff --git a/t/units/electromagnetic.t b/t/units/electromagnetic.t index 1b85f161c1..2f1d1c0bd5 100644 --- a/t/units/electromagnetic.t +++ b/t/units/electromagnetic.t @@ -16,8 +16,8 @@ my $watt = NumberWithUnits(1, 'W'); my $milliwatt = NumberWithUnits(1E3, 'mW'); my $megawatt = NumberWithUnits(1E-6, 'MW'); -my $amp = NumberWithUnits(1, 'amp'); -my $ampere = NumberWithUnits(1, 'A'); +my $amp = NumberWithUnits(1, 'amp'); +my $ampere = NumberWithUnits(1, 'A'); my $milliamp = NumberWithUnits(1000, 'mA'); my $tesla = NumberWithUnits(1, 'T'); From acd93a08fa37fca904d874228562b09a2db1c23d Mon Sep 17 00:00:00 2001 From: Boyd Duffee Date: Tue, 31 Jan 2023 18:26:02 +0000 Subject: [PATCH 4/6] Update AnswerFormatHelp.pl Make the help file consistent with the code change A is amp not angstrom --- macros/answers/AnswerFormatHelp.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/macros/answers/AnswerFormatHelp.pl b/macros/answers/AnswerFormatHelp.pl index 504b8f6ce9..12d7defc5a 100644 --- a/macros/answers/AnswerFormatHelp.pl +++ b/macros/answers/AnswerFormatHelp.pl @@ -750,7 +750,7 @@ sub AnswerFormatHelp { OpenWindow.document.write("Abbreviations for Units") OpenWindow.document.write("") OpenWindow.document.write("

Abbreviations for Units

") -OpenWindow.document.write("
  • Some WeBWorK problems ask for answers with units. Below is a list of basic units and how they need to be abbreviated in WeBWorK answers. In some problems, youmay need to combine units (e.g, velocity might be in ft/s for feet per second).


UnitAbbreviation
Time
Seconds s
Minutes min
Hours hr
Days day
Years year
Milliseconds ms
Distance
Feet ft
Inches in
Miles mi
Meters m
Centimeters cm
Millimeters mm
Kilometers km
Angstroms A
Light years light-year
Mass
Grams g
Kilograms kg
Slugs slug
Volume
Liters L
Cubic Centimeters cc
Milliliters ml
Force
Newtons N
Dynes dyne
Pounds lb
Tons ton
Work/Energy
Joules J
kilo Joule kJ
ergs erg
foot pounds lbf
calories cal
kilo calories kcal
electron volts eV
kilo Watt hours kWh
Misc
Amperes amp
Moles mol
Degrees Centrigrade degC
Degrees Fahrenheit degF
Degrees Kelvin degK
Angle degrees deg
Angle radians rad


") +OpenWindow.document.write("
  • Some WeBWorK problems ask for answers with units. Below is a list of basic units and how they need to be abbreviated in WeBWorK answers. In some problems, youmay need to combine units (e.g, velocity might be in ft/s for feet per second).


UnitAbbreviation
Time
Seconds s
Minutes min
Hours hr
Days day
Years year
Milliseconds ms
Distance
Feet ft
Inches in
Miles mi
Meters m
Centimeters cm
Millimeters mm
Kilometers km
Angstroms angstrom
Light years light-year
Mass
Grams g
Kilograms kg
Slugs slug
Volume
Liters L
Cubic Centimeters cc
Milliliters ml
Force
Newtons N
Dynes dyne
Pounds lb
Tons ton
Work/Energy
Joules J
kilo Joule kJ
ergs erg
foot pounds lbf
calories cal
kilo calories kcal
electron volts eV
kilo Watt hours kWh
Misc
Amperes A
Moles mol
Degrees Centrigrade degC
Degrees Fahrenheit degF
Degrees Kelvin degK
Angle degrees deg
Angle radians rad


") OpenWindow.document.write("") OpenWindow.document.write("") OpenWindow.document.close() From bd97de594c696e022dc82545c6cae0c238a5eb9e Mon Sep 17 00:00:00 2001 From: Boyd Duffee Date: Wed, 1 Feb 2023 11:35:47 +0000 Subject: [PATCH 5/6] Update Entering-Units.html to angstrom Rebase onto develop and fix tests that use A for angstrom --- htdocs/helpFiles/Entering-Units.html | 4 ++-- t/units/basic_parser.t | 21 ++++++++++----------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/htdocs/helpFiles/Entering-Units.html b/htdocs/helpFiles/Entering-Units.html index f216909ffa..4bc0af1e76 100644 --- a/htdocs/helpFiles/Entering-Units.html +++ b/htdocs/helpFiles/Entering-Units.html @@ -71,7 +71,7 @@

Units Available in WeBWorK

Angstroms - A + angstrom Light years @@ -171,7 +171,7 @@

Units Available in WeBWorK

Amperes - amp + A Moles diff --git a/t/units/basic_parser.t b/t/units/basic_parser.t index 97fc349650..f3c5f03a31 100644 --- a/t/units/basic_parser.t +++ b/t/units/basic_parser.t @@ -147,7 +147,6 @@ subtest 'Check display methods' => sub { }; subtest 'Check possible answer format branches' => sub { - # re-write without check_score so we can get the messages to students is check_score($joule, '1 J'), 1, 'one Joule plain'; @@ -175,26 +174,26 @@ subtest 'Check possible answer format branches' => sub { subtest 'Check possible answers compared to the number 0.005 T' => sub { my $correct = NumberWithUnits('0.005 T'); - is check_score($correct, '0.005 T'), 1, '0.005 T is correct'; - is check_score($correct, '5*10^-13 T*m/A'), 1, '5*10^-13 T*m/A is correct'; - is check_score($correct, '0 T*m/A'), 0, '0 T*m/A is incorrect'; + is check_score($correct, '0.005 T'), 1, '0.005 T is correct'; + is check_score($correct, '5*10^-13 T*m/angstrom'), 1, '5*10^-13 T*m/angstrom is correct'; + is check_score($correct, '0 T*m/angstrom'), 0, '0 T*m/angstrom is incorrect'; }; subtest 'Check possible answers compared to the formula 0.005 T' => sub { my $correct = FormulaWithUnits('0.005 T'); - is check_score($correct, '0.005 T'), 1, '0.005 T is correct'; - is check_score($correct, '5*10^-13 T*m/A'), 1, '5*10^-13 T*m/A is correct'; - is check_score($correct, '0 T*m/A'), 0, '0 T*m/A is incorrect'; + is check_score($correct, '0.005 T'), 1, '0.005 T is correct'; + is check_score($correct, '5*10^-13 T*m/angstrom'), 1, '5*10^-13 T*m/angstrom is correct'; + is check_score($correct, '0 T*m/angstrom'), 0, '0 T*m/angstrom is incorrect'; }; subtest 'Check possible answers compared to the formula 0.009 x^2 T' => sub { my $correct = FormulaWithUnits('0.009 x^2 T'); - is check_score($correct, '0.009 x^2 T'), 1, '0.009 x^2 T is correct'; - is check_score($correct, '9*10^-13 x^2 T*m/A'), 1, '9*10^-13 x^2 T*m/A is correct'; - is check_score($correct, '0 T*m/A'), 0, '0 T*m/A is incorrect'; - is check_score($correct, '0 x^2 T*m/A'), 0, '0 x^2 T*m/A is incorrect'; + is check_score($correct, '0.009 x^2 T'), 1, '0.009 x^2 T is correct'; + is check_score($correct, '9*10^-13 x^2 T*m/angstrom'), 1, '9*10^-13 x^2 T*m/angstrom is correct'; + is check_score($correct, '0 T*m/angstrom'), 0, '0 T*m/angstrom is incorrect'; + is check_score($correct, '0 x^2 T*m/angstrom'), 0, '0 x^2 T*m/angstrom is incorrect'; }; subtest 'Check possible answers compared to the the number 1 amu' => sub { From 197efaaa3fbcf7cff5b0a3814224db953c8080c9 Mon Sep 17 00:00:00 2001 From: Boyd Duffee Date: Thu, 2 Feb 2023 10:51:54 +0000 Subject: [PATCH 6/6] Update Units.html helpfile Needs to be the same as Entering-Units.html --- htdocs/helpFiles/Units.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/helpFiles/Units.html b/htdocs/helpFiles/Units.html index f216909ffa..4bc0af1e76 100644 --- a/htdocs/helpFiles/Units.html +++ b/htdocs/helpFiles/Units.html @@ -71,7 +71,7 @@

Units Available in WeBWorK

Angstroms - A + angstrom Light years @@ -171,7 +171,7 @@

Units Available in WeBWorK

Amperes - amp + A Moles