Molar Mass: Resolve conflicting triggers issue and add new triggers (#4250)
* Molar Mass: Remove conflicting triggers and update tests * Molar Mass: Increased flexibility of triggers * Molar Mass: forgot the apostrophe * Molar Mass: Fix Regex * Molar Mass: widen triggersmaster
parent
db93ca9b76
commit
9edc2f66bc
|
@ -7,6 +7,7 @@ use warnings;
|
|||
|
||||
use YAML::XS 'LoadFile';
|
||||
use Math::Round 'nearest';
|
||||
use Text::Trim;
|
||||
|
||||
zci answer_type => 'molar_mass';
|
||||
zci is_cached => 1;
|
||||
|
@ -14,13 +15,16 @@ zci is_cached => 1;
|
|||
my %masses = %{ LoadFile(share('elements.yml')) };
|
||||
my %compounds = %{ LoadFile(share('compounds.yml')) };
|
||||
|
||||
triggers start => 'molar mass of', 'atomic mass of', 'atomic weight of';
|
||||
triggers any => 'molar mass';
|
||||
|
||||
# Handle statement
|
||||
handle remainder => sub {
|
||||
|
||||
my $remainder = $_;
|
||||
|
||||
$remainder =~ s/(what is|whats|what\'s|the|of|for|\?)//g;
|
||||
$remainder = trim $remainder;
|
||||
|
||||
return unless $remainder;
|
||||
|
||||
# Check if input is in list of common compounds
|
||||
|
|
|
@ -50,13 +50,23 @@ sub build_test_alt { test_zci(build_alternate_answer(@_)) }
|
|||
ddg_goodie_test(
|
||||
[qw( DDG::Goodie::MolarMass )],
|
||||
|
||||
# - primary_example_queries
|
||||
# primary example queries
|
||||
'molar mass of H2O' => build_test_alt('H2O', '18.01528', 'Water'),
|
||||
|
||||
# - secondary_example_queries
|
||||
# secondary example queries
|
||||
'molar mass of Al2(SO4)3' => build_test_alt('Al2(SO4)3', '342.150876', 'Aluminium Sulfate'),
|
||||
'molar mass of NaCl' => build_test_alt('NaCl', '58.44277', 'Sodium Chloride'),
|
||||
'molar mass of HCl' => build_test_alt('HCl', '36.46094', 'Hydrochloric Acid'),
|
||||
'molar mass of Sulfuric Acid' => build_test_alt('H2SO4', '98.07848', 'Sulfuric Acid'),
|
||||
|
||||
# lowercase example queries
|
||||
'molar mass of al2(so4)3' => build_test_alt('Al2(SO4)3', '342.150876', 'Aluminium Sulfate'),
|
||||
'molar mass of nacl' => build_test_alt('NaCl', '58.44277', 'Sodium Chloride'),
|
||||
'molar mass of sulfuric acid' => build_test_alt('H2SO4', '98.07848', 'Sulfuric Acid'),
|
||||
'molar mass of h2so4' => build_test_alt('H2SO4', '98.07848', 'Sulfuric Acid'),
|
||||
'molar mass of hcl' => build_test_alt('HCl', '36.46094', 'Hydrochloric Acid'),
|
||||
|
||||
# edge case tests
|
||||
'molar mass of Uuo2' => build_test('Uuo2', '588'),
|
||||
'molar mass of C2H3NaO2' => build_test('C2H3NaO2', '82.0347'),
|
||||
'molar mass of Al123(S4(Uuo2Lv4)3Ca4)8' => build_test('Al123(S4(Uuo2Lv4)3Ca4)8', '47867.3854'),
|
||||
|
@ -65,10 +75,19 @@ ddg_goodie_test(
|
|||
'molar mass of ()()Na(())Cl' => build_test('()()Na(())Cl', '58.4426'),
|
||||
|
||||
# Other Triggers
|
||||
'atomic mass of NaCl' => build_test_alt('NaCl', '58.44277', 'Sodium Chloride'),
|
||||
'what is the molar mass of Al2(SO4)3' => build_test_alt('Al2(SO4)3', '342.150876', 'Aluminium Sulfate'),
|
||||
'whats the molar mass of NaCl' => build_test_alt('NaCl', '58.44277', 'Sodium Chloride'),
|
||||
'hydrochloric acid molar mass' => build_test_alt('HCl', '36.46094', 'Hydrochloric Acid'),
|
||||
'whats the molar mass of hydrochloric acid?' => build_test_alt('HCl', '36.46094', 'Hydrochloric Acid'),
|
||||
'what\'s the molar mass of hydrochloric acid?' => build_test_alt('HCl', '36.46094', 'Hydrochloric Acid'),
|
||||
'molar mass nacl' => build_test_alt('NaCl', '58.44277', 'Sodium Chloride'),
|
||||
|
||||
## Failing tests:
|
||||
|
||||
|
||||
# ----- Failing tests: ------
|
||||
# Primary failing example queries:
|
||||
'molar mass of asdf' => undef,
|
||||
'molar mass of' => undef,
|
||||
|
||||
# Mismatched brackets:
|
||||
'molar mass of Al2(SO4))3' => undef,
|
||||
|
@ -83,6 +102,13 @@ ddg_goodie_test(
|
|||
|
||||
# Unwanted Characters:
|
||||
'molar mass of *(&)H2' => undef,
|
||||
'molar mass of Al2H^2' => undef,
|
||||
|
||||
# Random placement of the words molar mass
|
||||
'something something molar mass haha' => undef,
|
||||
'mmolar masses' => undef,
|
||||
'hmolar mass' => undef,
|
||||
'molar mass' => undef,
|
||||
);
|
||||
|
||||
done_testing;
|
||||
|
|
Loading…
Reference in New Issue