diff options
author | Louis Pilfold <louis@lpil.uk> | 2019-04-22 22:33:15 +0000 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2019-04-22 22:33:15 +0000 |
commit | 077aaf3468c640b84ff53fc92171292ddae55bf4 (patch) | |
tree | a152edcc2240f053681ca6ba315dfeb9ed8fa793 /test | |
parent | afdabad5cd2df77eb3f309aab9da3d34e36a0b49 (diff) | |
download | gleam_stdlib-077aaf3468c640b84ff53fc92171292ddae55bf4.tar.gz gleam_stdlib-077aaf3468c640b84ff53fc92171292ddae55bf4.zip |
Int and float modules
Diffstat (limited to 'test')
-rw-r--r-- | test/float_test.gleam | 38 | ||||
-rw-r--r-- | test/int_test.gleam | 52 | ||||
-rw-r--r-- | test/list_test.gleam | 3 | ||||
-rw-r--r-- | test/str_test.gleam | 86 |
4 files changed, 92 insertions, 87 deletions
diff --git a/test/float_test.gleam b/test/float_test.gleam new file mode 100644 index 0000000..161f6df --- /dev/null +++ b/test/float_test.gleam @@ -0,0 +1,38 @@ +import expect +import float + +pub fn parse_test() { + "1.23" + |> float:parse + |> expect:equal(_, Ok(1.23)) + + "5.0" + |> float:parse + |> expect:equal(_, Ok(5.0)) + + "0.123456789" + |> float:parse + |> expect:equal(_, Ok(0.123456789)) + + "" + |> float:parse + |> expect:is_error + + "what" + |> float:parse + |> expect:is_error + + "1" + |> float:parse + |> expect:is_error +} + +pub fn to_string_test() { + 123.0 + |> float:to_string + |> expect:equal(_, "123.0") + + -8.1 + |> float:to_string + |> expect:equal(_, "-8.1") +} diff --git a/test/int_test.gleam b/test/int_test.gleam new file mode 100644 index 0000000..d5f0f58 --- /dev/null +++ b/test/int_test.gleam @@ -0,0 +1,52 @@ +import expect +import int + +pub fn to_string() { + 123 + |> int:to_string + |> expect:equal(_, "123") + + -123 + |> int:to_string + |> expect:equal(_, "-123") + + 0123 + |> int:to_string + |> expect:equal(_, "123") +} + +pub fn parse() { + "123" + |> int:parse + |> expect:equal(_, Ok(123)) + + "-123" + |> int:parse + |> expect:equal(_, Ok(-123)) + + "0123" + |> int:parse + |> expect:equal(_, Ok(123)) + + "" + |> int:parse + |> expect:is_error + + "what" + |> int:parse + |> expect:is_error + + "1.23" + |> int:parse + |> expect:is_error +} + +pub fn to_base_string() { + 100 + |> int:to_base_string(_, 16) + |> expect:equal(_, "64") + + -100 + |> int:to_base_string(_, 16) + |> expect:equal(_, "-64") +} diff --git a/test/list_test.gleam b/test/list_test.gleam index 493dfb7..ba5c4c5 100644 --- a/test/list_test.gleam +++ b/test/list_test.gleam @@ -1,5 +1,6 @@ import expect import list +import int import str pub fn length_test() { @@ -255,7 +256,7 @@ pub fn index_map_test() { |> expect:equal(_, [{0, 3}, {1, 4}, {2, 5}]) let f = fn(i, x) { - str:append(x, str:from_int(i)) + str:append(x, int:to_string(i)) } list:index_map(["a", "b", "c"], f) |> expect:equal(_, ["a0", "b1", "c2"]) diff --git a/test/str_test.gleam b/test/str_test.gleam index 49e45e7..5d0d6ba 100644 --- a/test/str_test.gleam +++ b/test/str_test.gleam @@ -47,89 +47,3 @@ pub fn append_test() { str:append("Test", " Me") |> expect:equal(_, "Test Me") } - -pub fn from_int_test() { - 123 - |> str:from_int - |> expect:equal(_, "123") - - -123 - |> str:from_int - |> expect:equal(_, "-123") - - 0123 - |> str:from_int - |> expect:equal(_, "123") -} - -pub fn parse_int_test() { - "123" - |> str:parse_int - |> expect:equal(_, Ok(123)) - - "-123" - |> str:parse_int - |> expect:equal(_, Ok(-123)) - - "0123" - |> str:parse_int - |> expect:equal(_, Ok(123)) - - "" - |> str:parse_int - |> expect:is_error - - "what" - |> str:parse_int - |> expect:is_error - - "1.23" - |> str:parse_int - |> expect:is_error -} - -pub fn parse_float_test() { - "1.23" - |> str:parse_float - |> expect:equal(_, Ok(1.23)) - - "5.0" - |> str:parse_float - |> expect:equal(_, Ok(5.0)) - - "0.123456789" - |> str:parse_float - |> expect:equal(_, Ok(0.123456789)) - - "" - |> str:parse_float - |> expect:is_error - - "what" - |> str:parse_float - |> expect:is_error - - "1" - |> str:parse_float - |> expect:is_error -} - -pub fn base_from_int_test() { - 100 - |> str:base_from_int(_, 16) - |> expect:equal(_, "64") - - -100 - |> str:base_from_int(_, 16) - |> expect:equal(_, "-64") -} - -pub fn from_float_test() { - 123.0 - |> str:from_float - |> expect:equal(_, "123.0") - - -8.1 - |> str:from_float - |> expect:equal(_, "-8.1") -} |