Last active
August 29, 2020 01:53
-
-
Save lukaswilkeer/8cb6296a263f1843c6c3a2675cc432ee to your computer and use it in GitHub Desktop.
rever number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(reverse). | |
-export([reverse/1]). | |
%% @doc reverse a number | |
-spec(reverse(number() | string() | atom()) -> string()). | |
reverse(ANumber) -> | |
%% convert the number to an string | |
Nmbr = string:reverse(atom_to_list(ANumber)), | |
Check = not_a_number(Nmbr), | |
if | |
Check == true -> erro; | |
Check == false -> Nmbr | |
end. | |
%% @doc verify if it's a number | |
-spec(not_a_number(number() | string() | atom()) -> atom()). | |
not_a_number(Nmbr) when is_number(Nmbr) -> | |
true; | |
not_a_number(Nmbr) when is_list(Nmbr) -> | |
erro; | |
not_a_number(_) -> | |
erro. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(reverse_SUITE). | |
-export([all/0]). | |
-import(reverse, [reverse/1]). | |
-include_lib("eunit/include/eunit.hrl"). | |
all() -> [reverse_test]. | |
reverse_test() -> | |
[?_assert(reverse(1234) =:= 4321), | |
?_assert(reverse(12) =:= 21), | |
?_assert(reverse(6641112222223333333345678901118) =:= 8111098765433333333222222111466), | |
?_assert(reverse("lala") =:= error) | |
]. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment