-
Notifications
You must be signed in to change notification settings - Fork 323
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
Decimal remainder, pow, div #9566
Changes from 9 commits
e5ec856
c3365b5
d8c86b2
df52a69
1788f1e
e851945
540dfc0
ed1aa43
7419985
1483e0c
3aa6ab6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -492,6 +492,74 @@ add_specs suite_builder = | |
nd2 = -d2 | ||
nd2 . should_equal 5 | ||
|
||
suite_builder.group "remainder" group_builder-> | ||
group_builder.specify "should define remainder" <| | ||
cases = [] | ||
+ [[5, 3, 2], [5.0, 3.0, 2.0], [3.5, 2, 1.5], [10.5, 1.0, 0.5], [3, 1, 0], [3.0, 1.0, 0]] | ||
+ [[-5, 3, -2], [-5.0, 3.0, -2.0], [-3.5, 2, -1.5], [-10.5, 1.0, -0.5], [-3, 1, 0], [-3.0, 1.0, 0]] | ||
+ [["9223372036854775807", 10, 7], ["9223372036854775808", 10, 8], ["922337203685477580000000000008", 10, 8]] | ||
+ [["-9223372036854775808", 10, -8], ["-9223372036854775809", 10, -9], ["-922337203685477580000000000008", 10, -8]] | ||
cases.map c-> | ||
base = c.at 0 | ||
modulus = c.at 1 | ||
residue = c.at 2 | ||
(Decimal.new base % modulus) . should_equal residue | ||
(Decimal.new base % Decimal.new modulus) . should_equal residue | ||
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'd probably add a test case for something like 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. Done. |
||
|
||
group_builder.specify "should define remainder (example)" <| | ||
(Decimal.new 10 . remainder 3) . should_equal 1 | ||
(Decimal.new 10 % 3) . should_equal 1 | ||
|
||
group_builder.specify "remainder 0 should throw" <| | ||
(Decimal.new 3 % 0) . should_fail_with Arithmetic_Error | ||
(Decimal.new 3 % Decimal.new 0) . should_fail_with Arithmetic_Error | ||
|
||
suite_builder.group "div" group_builder-> | ||
group_builder.specify "should define div" <| | ||
Decimal.new "10" . div (Decimal.new "3") . should_equal 3 | ||
Decimal.new "10.28" . div (Decimal.new "3.01") . should_equal 3 | ||
|
||
Decimal.new "35" . div (Decimal.new "6") . should_equal 5 | ||
Decimal.new "-35" . div (Decimal.new "6") . should_equal -5 | ||
Decimal.new "35" . div (Decimal.new "-6") . should_equal -5 | ||
Decimal.new "-35" . div (Decimal.new "-6") . should_equal 5 | ||
Decimal.new "35.0" . div (Decimal.new "6") . should_equal 5 | ||
Decimal.new "35.3" . div (Decimal.new "6") . should_equal 5 | ||
|
||
Decimal.new "35" . div (Decimal.new "5") . should_equal 7 | ||
|
||
Decimal.new "0" . div (Decimal.new "5") . should_equal 0 | ||
|
||
Decimal.new "12" . div (Decimal.new "0") . should_fail_with Arithmetic_Error | ||
|
||
suite_builder.group "pow" group_builder-> | ||
group_builder.specify "should define pow" <| | ||
Decimal.new "10" . pow 3 . should_equal 1000 | ||
|
||
(Decimal.new "10" ^ 3) . should_equal 1000 | ||
|
||
(Decimal.new "-10" ^ 2) . should_equal 100 | ||
(Decimal.new "-10" ^ 3) . should_equal -1000 | ||
|
||
(Decimal.new "2" ^ 5) . should_equal 32 | ||
(Decimal.new "3" ^ 4) . should_equal 81 | ||
(Decimal.new "-2" ^ 5) . should_equal -32 | ||
(Decimal.new "-3" ^ 4) . should_equal 81 | ||
|
||
(Decimal.new "2.25" ^ 5) . should_equal 57.6650390625 | ||
|
||
(Decimal.new "10" ^ 1) . should_equal 10 | ||
(Decimal.new "2" ^ 1) . should_equal 2 | ||
(Decimal.new "10" ^ 0) . should_equal 1 | ||
(Decimal.new "2" ^ 0) . should_equal 1 | ||
|
||
(Decimal.new "23234" ^ 12) . should_equal (Decimal.new "24745020631916033678933049360198248076412726408646656") | ||
(Decimal.new "-794" ^ 112) . should_equal (Decimal.new "6024156861645760455373941610695035918372130160062114486642167348130629475133139191309665922068844301194118714216190697635299124619812230483098091272538558376111325623532711124479664789034731517753138259958467197045503553217529624389271803885423122798234927557537822587658929087103065356345719502482054440067247048272417652736") | ||
|
||
group_builder.specify "should throw an error for exponent out of range" <| | ||
Decimal.new "10" . pow -1 . should_fail_with Arithmetic_Error | ||
Decimal.new "10" . pow 99999999999 . should_fail_with Arithmetic_Error | ||
|
||
main = | ||
suite = Test.build suite_builder-> | ||
add_specs suite_builder | ||
|
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.
This sounds to me like the result of the operation will undergo conversions, which as far as I understand is not the case and you mean the arguments, right?
Maybe we can rephrase it to make it clearer?
maybe something like that?
in Enso
there - this is an Enso library so that is rather assumed,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.
Done.