@@ -39,6 +39,22 @@ defmodule Numbers do
|
|||||||
assert Integer.parse("2A", 16) == {___, ""}
|
assert Integer.parse("2A", 16) == {___, ""}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
koan "The remaining unparsable part is also returned" do
|
||||||
|
assert Integer.parse("5 years") == {5, ___}
|
||||||
|
end
|
||||||
|
|
||||||
|
koan "What if you parse a floating point value as an integer?" do
|
||||||
|
assert Integer.parse("1.2") == {___, ___}
|
||||||
|
end
|
||||||
|
|
||||||
|
koan "Just want to parse to a float" do
|
||||||
|
assert Float.parse("34.5") == {___, ""}
|
||||||
|
end
|
||||||
|
|
||||||
|
koan "Hmm, I want to parse this but it has some strings" do
|
||||||
|
assert Float.parse("1.5 million dollars") == {___, " million dollars"}
|
||||||
|
end
|
||||||
|
|
||||||
koan "I don't want this decimal point, let's round up" do
|
koan "I don't want this decimal point, let's round up" do
|
||||||
assert Float.ceil(34.25) == ___
|
assert Float.ceil(34.25) == ___
|
||||||
end
|
end
|
||||||
@@ -55,14 +71,6 @@ defmodule Numbers do
|
|||||||
assert Float.floor(12.345, 2) == ___
|
assert Float.floor(12.345, 2) == ___
|
||||||
end
|
end
|
||||||
|
|
||||||
koan "Just want to parse to a float" do
|
|
||||||
assert Float.parse("34.5") == {___, ""}
|
|
||||||
end
|
|
||||||
|
|
||||||
koan "Hmm, I want to parse this but it has some strings" do
|
|
||||||
assert Float.parse("1 million dollars") == {___, " million dollars"}
|
|
||||||
end
|
|
||||||
|
|
||||||
koan "Round the number up or down for me" do
|
koan "Round the number up or down for me" do
|
||||||
assert Float.round(5.5) == ___
|
assert Float.round(5.5) == ___
|
||||||
assert Float.round(5.4) == ___
|
assert Float.round(5.4) == ___
|
||||||
|
|||||||
@@ -11,12 +11,14 @@ defmodule NumbersTests do
|
|||||||
'7',
|
'7',
|
||||||
"1234",
|
"1234",
|
||||||
42,
|
42,
|
||||||
|
" years",
|
||||||
|
{:multiple, [1, ".2"]},
|
||||||
|
34.5,
|
||||||
|
1.5,
|
||||||
35.0,
|
35.0,
|
||||||
34.3,
|
34.3,
|
||||||
99.0,
|
99.0,
|
||||||
12.34,
|
12.34,
|
||||||
34.5,
|
|
||||||
1.0,
|
|
||||||
{:multiple, [6.0, 5.0, 8.9, -5.567]},
|
{:multiple, [6.0, 5.0, 8.9, -5.567]},
|
||||||
{:multiple, [1, 10]},
|
{:multiple, [1, 10]},
|
||||||
{:multiple, [true, true, false]},
|
{:multiple, [true, true, false]},
|
||||||
|
|||||||
Reference in New Issue
Block a user