Skip to content
Browse files

Added user acceptance test in EUnit and copied the user_acceptance_test/

to test/.
Also reordered so the output is alphabetic in the result file
  • Loading branch information...
1 parent 0fd09c8 commit f0dc55c53082bccfd670c32c653924e86139e00d Gianfranco Alongi committed
View
1 One/Solution/Makefile
@@ -8,4 +8,5 @@ test:
eunit:test(ros_parser,[verbose]),\
eunit:test(ros_analyzer,[verbose]),\
eunit:test(ros_engine,[verbose]),\
+ eunit:test(ros,[verbose]),\
init:stop().'
View
32 One/Solution/src/ros.erl
@@ -0,0 +1,32 @@
+-module(ros).
+-export([analyze/1]).
+
+-spec(analyze(string()) -> ok).
+analyze(Path) ->
+ Base = filename:basename(Path),
+ Result = ros_engine:run_dir(Path),
+ ToFile = build_result_string(Result),
+ File = "analysis_result_"++Base++".txt",
+ file:write_file(File,ToFile).
+
+build_result_string(Result) ->
+ brs(Result,"PASSED_FILES:\n","FAILED_FILES:\n").
+
+brs([],Good,Bad) ->
+ Good++"\n"++Bad;
+brs([{File,ok}|T],Good,Bad) ->
+ brs(T,Good++File++"\n",Bad);
+brs([{File,{error,Cause}}|T],Good,Bad) ->
+ brs(T,Good,Bad++File++","++cause_to_string(Cause)++"\n").
+
+cause_to_string({Cause,Num}) ->
+ atom_to_list(Cause)++","++integer_to_list(Num).
+
+
+
+
+
+
+
+
+
View
2 One/Solution/src/ros_engine.erl
@@ -1,7 +1,7 @@
-module(ros_engine).
-export([run_dir/1]).
--spec(run_dir(string()) -> [{string(),ok} | {error,no_total}]).
+-spec(run_dir(string()) -> [{string(),ok | {error,term()}}]).
run_dir(Dir) ->
case ros_reader:read_dir(Dir) of
{ok,Files_Content} ->
View
5 One/Solution/src/ros_reader.erl
@@ -14,8 +14,9 @@ read_file(File) ->
-spec(read_dir(string()) -> {ok,[{string(),term()}]} | {error,no_such_dir}).
read_dir(Dir) ->
case file:list_dir(Dir) of
- {ok,Files} ->
- Res = [{File, read_file(filename:join(Dir,File))} || File <- Files ],
+ {ok,Files} ->
+ OnlyRos = [ File || File <- Files, filename:extension(File) == ".ros"],
+ Res = [{File, read_file(filename:join(Dir,File))} || File <- OnlyRos ],
{ok,lists:sort(Res)};
{error,enoent} ->
{error,no_such_dir}
View
25 One/Solution/test/ros_tests.erl
@@ -0,0 +1,25 @@
+-module(ros_tests).
+-include_lib("eunit/include/eunit.hrl").
+
+-define(FILE_NAME,"analysis_result_user_acceptance_test.txt").
+-define(UAT_DIR,"test/user_acceptance_test/").
+
+user_acceptance_test_() ->
+ {setup,
+ fun setup/0,
+ fun cleanup/1,
+ fun uat/0}.
+
+setup() ->
+ file:delete(?FILE_NAME).
+
+cleanup(_) ->
+ file:delete(?FILE_NAME).
+
+uat() ->
+ ?assertEqual(ok, ros:analyze(?UAT_DIR)),
+ {ok,UAT_Result_Content} = file:read_file(?UAT_DIR++"user_acceptance_test.txt"),
+ {ok,Own_Result_Content} = file:read_file("analysis_result_user_acceptance_test.txt"),
+ ?assertEqual(UAT_Result_Content,Own_Result_Content).
+
+
View
4 One/Solution/test/user_acceptance_test/february-bad.ros
@@ -0,0 +1,4 @@
+paper,1,2
+water,1,2
+towel,10,2
+5
View
4 One/Solution/test/user_acceptance_test/february-good.ros
@@ -0,0 +1,4 @@
+paper,1,2
+water,1,2
+towel,10,2
+6
View
3 One/Solution/test/user_acceptance_test/january-bad.ros
@@ -0,0 +1,3 @@
+paper,1,1
+water,1,2
+4
View
3 One/Solution/test/user_acceptance_test/january-good.ros
@@ -0,0 +1,3 @@
+paper,1,1
+water,1,2
+3
View
4 One/Solution/test/user_acceptance_test/march-bad.ros
@@ -0,0 +1,4 @@
+paper,1,2
+water,0,0
+towel,0,0
+3
View
4 One/Solution/test/user_acceptance_test/march-good.ros
@@ -0,0 +1,4 @@
+paper,1,2
+water,0,0
+towel,0,0
+2
View
9 One/Solution/test/user_acceptance_test/user_acceptance_test.txt
@@ -0,0 +1,9 @@
+PASSED_FILES:
+february-good.ros
+january-good.ros
+march-good.ros
+
+FAILED_FILES:
+february-bad.ros,total_less_than_projected,1
+january-bad.ros,total_greater_than_projected,1
+march-bad.ros,total_greater_than_projected,1
View
4 One/user_acceptance_test/user_acceptance_test.txt
@@ -1,9 +1,9 @@
PASSED_FILES:
-january-good.ros
february-good.ros
+january-good.ros
march-good.ros
FAILED_FILES:
-january-bad.ros,total_greater_than_projected,1
february-bad.ros,total_less_than_projected,1
+january-bad.ros,total_greater_than_projected,1
march-bad.ros,total_greater_than_projected,1

0 comments on commit f0dc55c

Please sign in to comment.
Something went wrong with that request. Please try again.