Skip to content
Snippets Groups Projects
Unverified Commit 650bafc3 authored by Mat-Ge's avatar Mat-Ge Committed by GitHub
Browse files

decimalplaces(ex,n) for n=0 or integerp(ex); two test cases

parent 1afbea5c
Branches
No related tags found
No related merge requests found
......@@ -736,7 +736,13 @@ decimalplacesfun(ex, n, dispdps) := block([ex2],
if dispdps then ex2:displaydp(ex2, n),
return(ex2)
)$
decimalplaces(ex, n) := decimalplacesfun(ex, n, false)$
decimalplaces(ex, n):= block(
if n=0 then return(round(ex)),
if integerp(ex) then return(ex),
decimalplacesfun(ex, n, false)
)$
dispdp(ex, n) := block(
if not(real_numberp(ex)) then error("dispdp requires a real number argument."),
if not(integerp(n)) then error("dispdp cannot create a non-integer number of decimal places."),
......
......@@ -816,12 +816,12 @@ class castext_test extends qtype_stack_testcase {
}
$cs2 = new stack_cas_session2($s2, null, 0);
$at1 = castext2_evaluatable::make_from_source('{@dispdp(a,2)@}, {@dispdp(b,3)@}, {@dispsf(b,4)@}', 'test-case');
$at1 = castext2_evaluatable::make_from_source('{@dispdp(a,2)@}, {@dispdp(b,3)@}, {@dispsf(b,4)@}, {@decimalplaces(a,0)@}, {@decimalplaces(1,2)@}', 'test-case');
$this->assertTrue($at1->get_valid());
$cs2->add_statement($at1);
$cs2->instantiate();
$this->assertEquals('\({2.72}\), \({4.000}\), \({4.000}\)', $at1->get_rendered());
$this->assertEquals('\({2.72}\), \({4.000}\), \({4.000}\), \({3}\), \({1}\)', $at1->get_rendered());
}
/**
......@@ -835,12 +835,12 @@ class castext_test extends qtype_stack_testcase {
}
$cs2 = new stack_cas_session2($s2, null, 0);
$at1 = castext2_evaluatable::make_from_source('{@dispdp(a,0)*x^2@}, {@dispdp(b,3)@}, {@dispsf(b,4)@}', 'test-case');
$at1 = castext2_evaluatable::make_from_source('{@dispdp(a,0)*x^2@}, {@dispdp(b,3)@}, {@dispsf(b,4)@}, {@decimalplaces(a,0)@}, {@decimalplaces(1,2)@}', 'test-case');
$this->assertTrue($at1->get_valid());
$cs2->add_statement($at1);
$cs2->instantiate();
$this->assertEquals('\({3\cdot x^2}\), \({-4.000}\), \({-4.000}\)', $at1->get_rendered());
$this->assertEquals('\({3\cdot x^2}\), \({-4.000}\), \({-4.000}\), \({3}\), \({1}\)', $at1->get_rendered());
}
/**
......@@ -854,7 +854,7 @@ class castext_test extends qtype_stack_testcase {
}
$cs2 = new stack_cas_session2($s2, null, 0);
$at1 = castext2_evaluatable::make_from_source('{@dispdp(a1,0)*x^2@}, {@dispdp(b,3)@}, {@dispsf(b,4)@}', 'test-case');
$at1 = castext2_evaluatable::make_from_source('{@dispdp(a1,0)*x^2@}, {@dispdp(b,3)@}, {@dispsf(b,4)@}, {@decimalplaces(a,0)@}, {@decimalplaces(1,2)@}', 'test-case');
$this->assertTrue($at1->get_valid());
$cs2->add_statement($at1);
$cs2->instantiate();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment