aboutsummaryrefslogtreecommitdiff
path: root/learn-you-some-erlang/tests/functions_tests.erl
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2024-02-23 07:08:18 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2024-02-23 07:08:18 +0100
commit5a9cdd3cc89507d4d74f8bded56ce5e037b3b56e (patch)
tree982ca2e7f9ac4e8c350dfb5c4f60bcfdfff5afaf /learn-you-some-erlang/tests/functions_tests.erl
parent05ae56e5e89abf2993f84e6d52b250131f247c35 (diff)
downloaderlang-workshop-5a9cdd3cc89507d4d74f8bded56ce5e037b3b56e.tar.gz
erlang-workshop-5a9cdd3cc89507d4d74f8bded56ce5e037b3b56e.tar.bz2
erlang-workshop-5a9cdd3cc89507d4d74f8bded56ce5e037b3b56e.tar.xz
erlang-workshop-5a9cdd3cc89507d4d74f8bded56ce5e037b3b56e.zip
wip
Diffstat (limited to 'learn-you-some-erlang/tests/functions_tests.erl')
-rw-r--r--learn-you-some-erlang/tests/functions_tests.erl27
1 files changed, 27 insertions, 0 deletions
diff --git a/learn-you-some-erlang/tests/functions_tests.erl b/learn-you-some-erlang/tests/functions_tests.erl
new file mode 100644
index 0000000..7973b9e
--- /dev/null
+++ b/learn-you-some-erlang/tests/functions_tests.erl
@@ -0,0 +1,27 @@
+-module(functions_tests).
+-include_lib("eunit/include/eunit.hrl").
+-test_warnings([valid_time_test/0]).
+
+head_test() -> ?assertEqual(1, functions:head([1,2,3,4])).
+
+second_test() -> ?assertEqual(2, functions:second([1,2,3,4])).
+
+same_test_() ->
+ [?_assertEqual(true, functions:same(a,a)),
+ ?_assertEqual(true, functions:same(12,12)),
+ ?_assertEqual(false, functions:same(a,b)),
+ ?_assertEqual(false, functions:same(12.0, 12))].
+
+%% no clean way to test valid_time's io stuff, so this one is p. much the
+%% same thing as the main objective was to test pattern matching.
+%% io:format should be used as least as possible to do testing :(
+valid_time({_Date = {_Y,_M,_D}, _Time = {_H,_Min,_S}}) ->
+ matches;
+valid_time(_) ->
+ nomatch.
+
+valid_time_test_() ->
+ [?_assertEqual(matches, valid_time({{2011,09,06},{09,04,43}})),
+ ?_assertEqual(nomatch, valid_time({{2011,09,06},{09,04}}))].
+
+