- NumberConversionTask: staticCheck() sign handling with optional leading zeros fixed
This commit is contained in:
parent
0625aab454
commit
cf8c7a3e21
@ -76,20 +76,31 @@ class NumberConversionTask extends OpenEndedTask
|
||||
$this->src_rep = "u";
|
||||
}
|
||||
|
||||
// switch between source and destination constrains
|
||||
if ($this->hasFlag("sourceconstrain")) {
|
||||
$base = $this->src_base;
|
||||
$n_digits = $this->src_n_digits;
|
||||
$rep = $this->src_rep;
|
||||
} else {
|
||||
$base = $this->dst_base;
|
||||
$n_digits = $this->dst_n_digits;
|
||||
$rep = $this->dst_rep;
|
||||
}
|
||||
|
||||
// specify the range
|
||||
$max = 1;
|
||||
$min = 0;
|
||||
switch ($this->dst_rep) {
|
||||
switch ($rep) {
|
||||
case "u":
|
||||
$max = pow($this->dst_base, $this->dst_n_digits) - 1;
|
||||
$max = pow($base, $n_digits) - 1;
|
||||
$min = 0;
|
||||
break;
|
||||
case "s":
|
||||
$max = pow($this->dst_base, $this->dst_n_digits) - 1;
|
||||
$max = pow($base, $n_digits) - 1;
|
||||
$min = -$max;
|
||||
break;
|
||||
case "c":
|
||||
$max = pow($this->dst_base, $this->dst_n_digits - 1) - 1;
|
||||
$max = pow($base, $n_digits - 1) - 1;
|
||||
$min = -($max + 1);
|
||||
break;
|
||||
}
|
||||
@ -106,11 +117,17 @@ class NumberConversionTask extends OpenEndedTask
|
||||
{
|
||||
$mark = 0.0;
|
||||
$pa = strtolower($this->player_answer);
|
||||
if ($this->hasFlag("acceptwithoutleadingzeros")) {
|
||||
$mark = (ltrim($pa, " 0") === ltrim($this->correct_answer, "0")) ? $this->getMaxMark() : 0.0;
|
||||
} else {
|
||||
$mark = (trim($pa) === trim($this->correct_answer)) ? $this->getMaxMark() : 0.0;
|
||||
$ca = $this->correct_answer;
|
||||
if (($ca[0] === "-") && ($pa[0] !== "-")) {
|
||||
goto setmark;
|
||||
}
|
||||
if ($this->hasFlag("acceptwithoutleadingzeros")) {
|
||||
$mark = (ltrim($pa, "+- 0") === ltrim($ca, "-0")) ? $this->getMaxMark() : 0.0;
|
||||
} else {
|
||||
$mark = (trim($pa) === trim($ca)) ? $this->getMaxMark() : 0.0;
|
||||
}
|
||||
|
||||
setmark:
|
||||
$this->setMark($mark);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user