Skip to content
This repository has been archived by the owner on Sep 10, 2024. It is now read-only.

Commit

Permalink
#146 fix is-int and is-float; add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
c71n93 committed Oct 23, 2023
1 parent 9c714de commit 0fc324f
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/main/eo/org/eolang/math/number.eo
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@
[] > is-int
^.n > value!
if. > @
value.eq 0
^.is-int-zero
TRUE
if.
value.eq 0.0
^.is-float-zero
FALSE
eq.
div.
Expand All @@ -55,17 +55,38 @@
[] > is-float
^.n > value!
if. > @
value.eq 0.0
^.is-float-zero
TRUE
if.
value.eq 0
^.is-int-zero
FALSE
eq.
div.
value
value
1.0

# Checking if number is integer 0
[] > is-int-zero
^.n > value!
eq. > @
value.as-bytes
value.neg.as-bytes

# Checking if number is floatint point 0.0 or -0.0
[] > is-float-zero
^.n > value!
if. > @
eq.
value.as-bytes
0.0.as-bytes
eq.
value.neg.as-bytes
-0.0.as-bytes
eq.
value.neg.as-bytes
0.0.as-bytes

# Checking if number is NaN
[] > is-nan
not. > @
Expand Down
96 changes: 96 additions & 0 deletions src/test/eo/org/eolang/math/number-tests.eo
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,90 @@
$.equal-to FALSE
"check is nan of not nan"

[] > check-is-float-zero-of-float-zero
assert-that > @
(number 0.0).is-float-zero
$.equal-to TRUE
"check is float zero of float zero"

[] > check-is-float-zero-of-float-neg-zero
assert-that > @
(number -0.0).is-float-zero
$.equal-to TRUE
"check is float zero of float negative zero"

[] > check-is-float-zero-of-positive-float
assert-that > @
(number 4.26).is-float-zero
$.equal-to FALSE
"check is float zero of positive float"

[] > check-is-float-zero-of-negative-float
assert-that > @
(number -2.07).is-float-zero
$.equal-to FALSE
"check is float zero of negative float"

[] > check-is-float-zero-of-int-zero
assert-that > @
(number 0).is-float-zero
$.equal-to FALSE
"check is float zero of int zero"

[] > check-is-float-zero-of-positive-int
assert-that > @
(number 414).is-float-zero
$.equal-to FALSE
"check is float zero of positive int"

[] > check-is-float-zero-of-negative-int
assert-that > @
(number -201).is-float-zero
$.equal-to FALSE
"check is float zero of negative int"

[] > check-is-int-zero-of-float-zero
assert-that > @
(number 0.0).is-int-zero
$.equal-to FALSE
"check is int zero of float zero"

[] > check-is-int-zero-of-float-neg-zero
assert-that > @
(number -0.0).is-int-zero
$.equal-to FALSE
"check is int zero of float negative zero"

[] > check-is-int-zero-of-positive-float
assert-that > @
(number 4.26).is-int-zero
$.equal-to FALSE
"check is int zero of positive float"

[] > check-is-int-zero-of-negative-float
assert-that > @
(number -2.07).is-int-zero
$.equal-to FALSE
"check is int zero of negative float"

[] > check-is-int-zero-of-int-zero
assert-that > @
(number 0).is-int-zero
$.equal-to TRUE
"check is int zero of int zero"

[] > check-is-int-zero-of-positive-int
assert-that > @
(number 414).is-int-zero
$.equal-to FALSE
"check is int zero of positive int"

[] > check-is-int-zero-of-negative-int
assert-that > @
(number -201).is-int-zero
$.equal-to FALSE
"check is int zero of negative int"

[] > check-is-int-of-int-zero
assert-that > @
(number 0).is-int
Expand All @@ -81,6 +165,18 @@
$.equal-to TRUE
"check is-float of float zero"

[] > check-is-float-of-float-neg-zero
assert-that > @
(number -0.0).is-float
$.equal-to TRUE
"check is-float of float negative zero"

[] > check-is-int-of-float-neg-zero
assert-that > @
(number -0.0).is-int
$.equal-to FALSE
"check is-int of float negative zero"

[] > check-is-int-positive-float
assert-that > @
(number 123.35).is-int
Expand Down

0 comments on commit 0fc324f

Please sign in to comment.