Skip to content

Commit cc7277d

Browse files
authored
Merge pull request #408 from openwebwork/PG-2.15
PG-2.15
2 parents dfef4c6 + 0d73e68 commit cc7277d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+31520
-1041
lines changed

VERSION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
$PG_VERSION ='PG-2.14';
2-
$PG_COPYRIGHT_YEARS = '1996-2018';
1+
$PG_VERSION ='2.15';
2+
$PG_COPYRIGHT_YEARS = '1996-2019';
33

44
1;

lib/AnswerHash.pm

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
manipulation methods. More of these may be added as it
2525
becomes necessary.
2626
27-
Useage: $rh_ans = new AnswerHash;
27+
Usage: $rh_ans = new AnswerHash;
2828
2929
AnswerEvaluator -- this class organizes the construction of
3030
answer evaluator subroutines which check the
@@ -37,7 +37,7 @@
3737
thus greatly reducing the programming and maintenance
3838
required for constructing answer evaluators.
3939
40-
Useage: $ans_eval = new AnswerEvaluator;
40+
Usage: $ans_eval = new AnswerEvaluator;
4141
4242
=cut
4343

@@ -203,14 +203,14 @@ sub setKeys {
203203

204204
=head4 data
205205
206-
Useage: $rh_ans->data('foo'); set $rh_ans->{student_ans} = 'foo';
206+
Usage: $rh_ans->data('foo'); set $rh_ans->{student_ans} = 'foo';
207207
$student_input = $rh_ans->data(); retrieve value of $rh_ans->{student_ans}
208208
209209
synonym for input
210210
211211
=head4 input
212212
213-
Useage: $rh_ans->input('foo') sets $rh_ans->{student_ans} = 'foo';
213+
Usage: $rh_ans->input('foo') sets $rh_ans->{student_ans} = 'foo';
214214
$student_input = $rh_ans->input();
215215
216216
synonym for data
@@ -231,7 +231,7 @@ sub input { #$rh_ans->input('foo') is a synonym for $rh_ans->{student_ans}='
231231

232232
=head4 input
233233
234-
Useage: $rh_ans->score(1)
234+
Usage: $rh_ans->score(1)
235235
$score = $rh_ans->score();
236236
237237
Retrieve or set $rh_ans->{score}, the student's score on the problem.
@@ -266,7 +266,7 @@ sub stringify_hash {
266266

267267
=head4 throw_error
268268
269-
Useage: $rh_ans->throw_error("FLAG", "message");
269+
Usage: $rh_ans->throw_error("FLAG", "message");
270270
271271
FLAG is a distinctive word that describes the type of error.
272272
Examples are EVAL for an evaluation error or "SYNTAX" for a syntax error.
@@ -279,7 +279,7 @@ sub stringify_hash {
279279
280280
=head4 catch_error
281281
282-
Useage: $rh_ans->catch_error("FLAG2");
282+
Usage: $rh_ans->catch_error("FLAG2");
283283
284284
Returns true (1) if $rh_ans->{error_flag} equals "FLAG2", otherwise it returns
285285
false (empty string).
@@ -288,7 +288,7 @@ sub stringify_hash {
288288
289289
=head4 clear_error
290290
291-
Useage: $rh_ans->clear_error("FLAG2");
291+
Usage: $rh_ans->clear_error("FLAG2");
292292
293293
If $rh_ans->{error_flag} equals "FLAG2" then the {error_flag} entry is set to
294294
the empty string as is the entry {error_message}
@@ -297,7 +297,7 @@ sub stringify_hash {
297297
298298
=head4 error_message
299299
300-
Useage: $flag = $rh_ans -> error_flag();
300+
Usage: $flag = $rh_ans -> error_flag();
301301
302302
$message = $rh_ans -> error_message();
303303
@@ -352,7 +352,7 @@ sub error_message {
352352
# =head4 pretty_print
353353
#
354354
#
355-
# Useage: $rh_ans -> pretty_print();
355+
# Usage: $rh_ans -> pretty_print();
356356
#
357357
#
358358
# Returns a string containing a representation of the AnswerHash as an HTML table.
@@ -396,7 +396,7 @@ sub error_message {
396396

397397
=head4 OR
398398
399-
Useage: $rh_ans->OR($rh_ans2);
399+
Usage: $rh_ans->OR($rh_ans2);
400400
401401
Returns a new AnswerHash whose score is the maximum of the scores in $rh_ans and $rh_ans2.
402402
The correct answers for the two hashes are combined with "OR".
@@ -408,7 +408,7 @@ sub error_message {
408408
=head4 AND
409409
410410
411-
Useage: $rh_ans->AND($rh_ans2);
411+
Usage: $rh_ans->AND($rh_ans2);
412412
413413
Returns a new AnswerHash whose score is the minimum of the scores in $rh_ans and $rh_ans2.
414414
The correct answers for the two hashes are combined with "AND".
@@ -817,7 +817,7 @@ sub rh_ans {
817817
A filter is a subroutine which takes one AnswerHash as an input, followed by
818818
a hash of options.
819819
820-
Useage: filter($ans_hash, option1 =>value1, option2=> value2 );
820+
Usage: filter($ans_hash, option1 =>value1, option2=> value2 );
821821
822822
823823
The filter performs some operations on the input AnswerHash and returns an

lib/Matrix.pm

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,8 @@ sub new_from_col_vecs
377377

378378
sub cp { # MEG makes new copies of complex number
379379
my $z = shift;
380-
return $z unless ref($z);
381-
my $w = Complex1::cplx($z->Re,$z->Im);
382-
return $w;
380+
return $z unless ref($z) eq 'Complex1';
381+
Complex1::cplx($z->Re,$z->Im);
383382
}
384383

385384
=head4
@@ -600,4 +599,4 @@ sub decompose_LR
600599

601600

602601

603-
1;
602+
1;

lib/PGalias.pm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ sub initialize {
102102
$self->{externalGif2PngPath} = $envir->{externalGif2PngPath};
103103
$self->{courseID} = $envir->{courseName};
104104
$self->{problemSeed} = $envir->{problemSeed};
105+
$self->{problemUUID} = $envir->{problemUUID}//0;
105106

106107
$self->{appletPath} = $self->{envir}->{pgDirectories}->{appletPath};
107108
#
@@ -117,7 +118,8 @@ sub initialize {
117118
$self->{courseID},
118119
'set'.$self->{setNumber},
119120
'prob'.$self->{probNum},
120-
$self->{problemSeed}
121+
$self->{problemSeed},
122+
$self->{problemUUID},
121123
);
122124

123125
##################################

lib/PGcore.pm

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ use Tie::IxHash;
2929
use WeBWorK::Debug;
3030
use MIME::Base64();
3131
use PGUtil();
32-
32+
use Encode qw(encode_utf8 decode_utf8);
33+
use utf8;
34+
binmode(STDOUT, ":utf8");
3335
##################################
3436
# PGcore object
3537
##################################
@@ -565,13 +567,15 @@ sub PG_restricted_eval {
565567
sub decode_base64 ($) {
566568
my $self = shift;
567569
my $str = shift;
568-
MIME::Base64::decode_base64($str);
570+
$str = MIME::Base64::decode_base64($str);
571+
decode_utf8($str);
569572
}
570573

571574
sub encode_base64 ($;$) {
572575
my $self = shift;
573576
my $str = shift;
574577
my $option = shift;
578+
$str = encode_utf8($str);
575579
MIME::Base64::encode_base64($str);
576580
}
577581

lib/PGloadfiles.pm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ our $debugON =0;
7070

7171
package PGloadfiles;
7272
use strict;
73+
#use Encode(qw(encode decode));
7374
use Exporter;
7475
use PGcore;
7576
use WeBWorK::PG::Translator;
@@ -232,8 +233,9 @@ sub compile_file {
232233
local($/);
233234
$/ = undef; # allows us to treat the file as a single line
234235

235-
open(MACROFILE, "<$filePath") || die "Cannot open file: $filePath";
236+
open(MACROFILE, "<:raw", $filePath) || die "Cannot open file: $filePath";
236237
my $string = 'BEGIN {push @__eval__, __FILE__};' . "\n" . <MACROFILE>;
238+
utf8::decode($string); # can't yet use :encoding(UTF-8)
237239
#warn "compiling $string";
238240
my ($result,$error,$fullerror) = $self->PG_macro_file_eval($string);
239241
eval ('$main::__files__->{pop @main::__eval__} = $filePath'); #used to keep track of which file is being evaluated.

lib/Parser/Context/Default.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ $functions = {
174174
'asinh' => {class => 'Parser::Function::hyperbolic', TeX => '\sinh^{-1}'},
175175
'acosh' => {class => 'Parser::Function::hyperbolic', TeX => '\cosh^{-1}'},
176176
'atanh' => {class => 'Parser::Function::hyperbolic', TeX => '\tanh^{-1}'},
177-
'asech' => {class => 'Parser::Function::hyperbolic', TeX => '\mathop{\rm sech}^{-1}'},
178-
'acsch' => {class => 'Parser::Function::hyperbolic', TeX => '\mathop{\rm csch}^{-1}'},
177+
'asech' => {class => 'Parser::Function::hyperbolic', TeX => '\mathop{\rm sech}\nolimits^{-1}'},
178+
'acsch' => {class => 'Parser::Function::hyperbolic', TeX => '\mathop{\rm csch}\nolimits^{-1}'},
179179
'acoth' => {class => 'Parser::Function::hyperbolic', TeX => '\coth^{-1}'},
180180

181181
'ln' => {class => 'Parser::Function::numeric', inverse => 'exp',

lib/Parser/Function.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ sub TeX {
300300
my @pstr = (); my $fn_precedence = $fn->{precedence};
301301
$fn_precedence = $fn->{parenPrecedence} if $fn->{parenPrecedence};
302302
$fn = $self->{def};
303-
my $name = '\mathop{\rm '.$self->{name}.'}';
303+
my $name = '\mathop{\rm '.$self->{name}.'}\nolimits';
304304
$name = $fn->{TeX} if defined($fn->{TeX});
305305
foreach my $x (@{$self->{params}}) {push(@pstr,$x->TeX)}
306306
if ($fn->{braceTeX}) {$TeX = $name.'{'.join(',',@pstr).'}'}

lib/Units.pm

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,18 @@ our %known_units = ('m' => {
185185
'factor' => 86400,
186186
's' => 1
187187
},
188+
'month' => {
189+
'factor' => 60*60*24*30,
190+
's' => 1
191+
},
192+
'months' => {
193+
'factor' => 60*60*24*30,
194+
's' => 1
195+
},
196+
'mo' => {
197+
'factor' => 60*60*24*30,
198+
's' => 1
199+
},
188200
'yr' => {
189201
'factor' => 31557600,
190202
's' => 1
@@ -283,7 +295,7 @@ our %known_units = ('m' => {
283295
'm' => 1
284296
},
285297
'parsec' => {
286-
'factor' => 30.857E15,
298+
'factor' => 3.08567758149137E16, #30.857E15,
287299
'm' => 1
288300
},
289301
# VOLUME
@@ -441,6 +453,12 @@ our %known_units = ('m' => {
441453
'kg' => 1,
442454
's' => -2
443455
},
456+
'lbs' => {
457+
'factor' => 4.4482216152605,
458+
'm' => 1,
459+
'kg' => 1,
460+
's' => -2
461+
},
444462
'ton' => {
445463
'factor' => 8900,
446464
'm' => 1,

lib/Value/Matrix.pm

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ sub numberMatrix { #internal
186186
my @M = (); my $isFormula = 0;
187187
foreach my $x (@_) {
188188
$x = Value::makeValue($x,context=>$context);
189-
Value::Error("Matrix row entries must be numbers") unless Value::isNumber($x);
189+
Value::Error("Matrix row entries must be numbers: $x ") unless _isNumber($x);
190190
push(@M,$x); $isFormula = 1 if Value::isFormula($x);
191191
}
192192
return $self->formula([@M]) if $isFormula;
@@ -249,7 +249,7 @@ sub isRow {
249249
}
250250

251251
#
252-
# See if the matrix is an Indenity matrix
252+
# See if the matrix is an Identity matrix
253253
#
254254
sub isOne {
255255
my $self = shift;
@@ -275,6 +275,11 @@ sub isZero {
275275
return 1;
276276
}
277277

278+
sub _isNumber {
279+
my $n = shift;
280+
return Value::isNumber($n) || Value::classMatch($n, 'Fraction');
281+
}
282+
278283
#
279284
# Make arbitrary data into a matrix, if possible
280285
#
@@ -327,7 +332,7 @@ sub mult {
327332
#
328333
# Constant multiplication
329334
#
330-
if (Value::isNumber($r)) {
335+
if (_isNumber($r)) {
331336
my @coords = ();
332337
foreach my $x (@{$l->data}) {push(@coords,$x*$r)}
333338
return $self->make(@coords);
@@ -365,7 +370,7 @@ sub mult {
365370
sub div {
366371
my ($l,$r,$flag) = @_; my $self = $l;
367372
Value::Error("Can't divide by a Matrix") if $flag;
368-
Value::Error("Matrices can only be divided by Numbers") unless Value::isNumber($r);
373+
Value::Error("Matrices can only be divided by Numbers") unless _isNumber($r);
369374
Value::Error("Division by zero") if $r == 0;
370375
my @coords = ();
371376
foreach my $x (@{$l->data}) {push(@coords,$x/$r)}
@@ -377,11 +382,11 @@ sub power {
377382
Value::Error("Can't use Matrices in exponents") if $flag;
378383
Value::Error("Only square matrices can be raised to a power") unless $l->isSquare;
379384
$r = Value::makeValue($r,context=>$context);
380-
if ($r->isNumber && $r =~ m/^-\d+$/) {
385+
if (_isNumber($r) && $r =~ m/^-\d+$/) {
381386
$l = $l->inverse; $r = -$r;
382387
$self->Error("Matrix is not invertible") unless defined($l);
383388
}
384-
Value::Error("Matrix powers must be non-negative integers") unless $r->isNumber && $r =~ m/^\d+$/;
389+
Value::Error("Matrix powers must be non-negative integers") unless _isNumber($r) && $r =~ m/^\d+$/;
385390
return $context->Package("Matrix")->I($l->length,$context) if $r == 0;
386391
my $M = $l; foreach my $i (2..$r) {$M = $M*$l}
387392
return $M;

0 commit comments

Comments
 (0)