forked from openwebwork/pg
-
Notifications
You must be signed in to change notification settings - Fork 1
Create a separate SignificantFiguresUnits context #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
|
|
||
| BEGIN { strict->import } | ||
|
|
||
| loadMacros('contextUnits.pl', 'contextSignificantFigures.pl'); | ||
|
|
||
| sub _contextSignificantFiguresUnits_init { | ||
| context::SignificantFiguresUnits::Init(@_); | ||
| } | ||
|
|
||
| package context::SignificantFiguresUnits::NumberWithUnit; | ||
| our @ISA = ('context::Units::NumberWithUnit'); | ||
|
|
||
| # call the postprocess for handling error messages and flags. | ||
| # This needs to be called for the SignificantFigure and Units separately. | ||
|
|
||
| sub cmp_postprocess { | ||
| my ($self, $ansHash) = @_; | ||
| $self->unit->cmp_postprocess($ansHash); | ||
|
|
||
| # Since the current $ansHash has the correct and student value as the NumberWithUnits type | ||
| # pass in just the number (SignificantFigure) to the postprocess. | ||
| $ansHash->{correct_value} = $ansHash->{correct_value}->number; | ||
| $ansHash->{student_value} = $ansHash->{student_value}->number; | ||
|
Comment on lines
+22
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you should probably cache the old values and replace them after doing the |
||
| $self->number->cmp_postprocess($ansHash); | ||
| } | ||
|
|
||
| package context::SignificantFiguresUnits; | ||
|
|
||
| sub Init { | ||
| my $context = $main::context{SignificantFiguresUnits} = context::Units::extending('SignificantFigures'); | ||
| $context->{value}{NumberWithUnit} = 'context::SignificantFiguresUnits::NumberWithUnit'; | ||
| $context->{value}{'Number-with-Unit'} = 'context::SignificantFiguresUnits::NumberWithUnit'; | ||
| $context = $main::context{LimitedSignificantFiguresUnits} = $context->copy; | ||
| $context->{name} = 'LimitedSignificantFiguresUnits'; | ||
| $context->parens->undefine('|', '{', '['); | ||
| $context->variables->remove('x'); | ||
| $context->operators->undefine('-', '+', '/', '//', ' /', '/ ', '!', '_', '.', 'U', '><'); | ||
| $context->flags->set(limitedSigFigs => 1); | ||
| } | ||
|
|
||
| 1; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should be calling
$self->SUPER::cmp_postprocess($ansHash)not the unit's post-processor in order to get the correct tests and messages. You don't want to post-process a student answer that is a number with units against just a unit (the unitcmp_postprocess()function returns immediately if the student value isn't a Unit object a number-with-units isn't a Unit.Also, you may wish to return early if
cmp_postprocess()produces any messages. Otherwise you may overwrite them. You will have to decide whose messages and partial credit take precedence, but I would say that you shouldn't give messages about the number being close if the units are not correct, so breaking out early seems the right solution.