Download:
child 25:e7df778c2cdc
parent 23:af20828828e5
24:19a7ba960f8e
Anton Shestakov <engored@ya.ru>, Sun, 02 Mar 2014 00:02:23 +0900
Tests.

3 файлов изменено, 17 вставок(+), 42 удалений(-) [+]
Emakefile file | annotate | diff | comparison | revisions
src/rps3.erl file | annotate | diff | comparison | revisions
test/rps3_tests.erl file | annotate | diff | comparison | revisions
--- a/Emakefile Sat Mar 01 23:07:50 2014 +0900
+++ b/Emakefile Sun Mar 02 00:02:23 2014 +0900
@@ -1,3 +1,2 @@
-{'src/*', [debug_info,
- {i, 'src'},
- {outdir, 'ebin'}]}.
+{"src/*", [debug_info, {i,"include/"}, {outdir, "ebin/"}]}.
+{"test/*", [debug_info, {i,"include/"}, {outdir, "ebin/"}]}.
--- a/src/rps3.erl Sat Mar 01 23:07:50 2014 +0900
+++ b/src/rps3.erl Sun Mar 02 00:02:23 2014 +0900
@@ -1,15 +1,8 @@
-module(rps3).
--export([
- get_rules/0,
- beats/1, test_beats/0,
- loses/1, test_loses/0,
- winning_hand/1, test_winning_hand/0]).
+-export([get_rules/0, winning_hand/1]).
get_rules() -> [rock, paper, scissors].
-beats(H) ->
- beats(H, get_rules()).
-
beats(H, [H|Tail]) ->
lists:last(Tail);
@@ -22,20 +15,6 @@
loses(H) ->
beats(H, lists:reverse(get_rules())).
-test_beats() ->
- lists:foreach(
- fun(H) ->
- io:format("~w beats ~w.~n", [H, beats(H)])
- end,
- get_rules()).
-
-test_loses() ->
- lists:foreach(
- fun(H) ->
- io:format("~w loses to ~w.~n", [H, loses(H)])
- end,
- get_rules()).
-
% winner for 3 hands is:
% rock, rock, rock -> rock
% rock, paper, scissors -> undefined
@@ -51,20 +30,3 @@
false -> Hand
end
end, undefined, HSet).
-
-test_winning_hand() ->
- Cases = [
- [rock, rock, rock],
- [rock, paper, scissors],
- [rock, paper, paper],
- [rock, rock, paper],
- [rock, paper],
- [paper, scissors],
- [scissors, rock]
- ],
- lists:foreach(
- fun(Hands) ->
- Winner = winning_hand(Hands),
- io:format("~w wins in ~w.~n", [Winner, Hands])
- end,
- Cases).
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/rps3_tests.erl Sun Mar 02 00:02:23 2014 +0900
@@ -0,0 +1,14 @@
+-module(rps3_tests).
+-include_lib("eunit/include/eunit.hrl").
+
+get_rules_test() ->
+ ?assertEqual(length(rps3:get_rules()), 3).
+
+winning_hand_test() ->
+ ?assertEqual(rps3:winning_hand([rock, paper]), paper),
+ ?assertEqual(rps3:winning_hand([paper, scissors]), scissors),
+ ?assertEqual(rps3:winning_hand([scissors, rock]), rock),
+ ?assertEqual(rps3:winning_hand([rock, rock, rock]), rock),
+ ?assertEqual(rps3:winning_hand([rock, paper, scissors]), undefined),
+ ?assertEqual(rps3:winning_hand([rock, paper, paper]), paper),
+ ?assertEqual(rps3:winning_hand([rock, rock, paper]), paper).