Skip to content
Browse files

Added core engine file for ROS analyzer with tests

Also added new entry in Makefile to execute this
Modified ros_reader so that it splices out the binary from the file:read_file/1
Modified incorrect totals number after running tests ; )
  • Loading branch information...
1 parent 9b98384 commit f778b6ca79a24923ae5b8ef599b7eab4afb3daf2 Gianfranco Alongi committed Feb 19, 2012
View
2 One/ROS_files/february-north_branch-2011.ros
@@ -5,4 +5,4 @@ pencil,10,20
printer paper,200,2000
coke,124,124
hot dog,215,215
-2484
+4284
View
2 One/ROS_files/january-south_branch-2011.ros
@@ -5,4 +5,4 @@ pencil,3,6
printer paper,10,100
coke,25,25
hot dog,25,25
-120766
+12766
View
4 One/Solution/Makefile
@@ -6,4 +6,6 @@ all:
test:
erl -pa ebin/ -eval 'eunit:test(ros_reader,[verbose]),\
eunit:test(ros_parser,[verbose]),\
- eunit:test(ros_analyzer,[verbose]),init:stop().'
+ eunit:test(ros_analyzer,[verbose]),\
+ eunit:test(ros_engine,[verbose]),\
+ init:stop().'
View
16 One/Solution/src/ros_engine.erl
@@ -0,0 +1,16 @@
+-module(ros_engine).
+-export([run_dir/1]).
+
+-spec(run_dir(string()) -> [{string(),ok}]).
+run_dir(Dir) ->
+ case ros_reader:read_dir(Dir) of
+ {ok,Files_Content} ->
+ work_on_files(Files_Content)
+ end.
+
+work_on_files([]) -> [];
+work_on_files([{File,Contains}|Rest]) ->
+ case ros_parser:parse(binary_to_list(Contains)) of
+ {ok,Ros} ->
+ [{File,ros_analyzer:analyze(Ros)} | work_on_files(Rest)]
+ end.
View
2 One/Solution/src/ros_reader.erl
@@ -8,7 +8,7 @@ read_file(File) ->
case file:read_file(File) of
{error,enoent} ->
{error,no_such_file};
- R -> R
+ {ok,R} -> R
end.
-spec(read_dir(string()) -> {ok,[{string(),term()}]} | {error,no_such_dir}).
View
13 One/Solution/test/ros_engine_tests.erl
@@ -0,0 +1,13 @@
+-module(ros_engine_tests).
+-include_lib("eunit/include/eunit.hrl").
+
+ros_engine_negative_test() ->
+ Dir = "../ROS_files/",
+ Res = ros_engine:run_dir(Dir),
+ ?assertEqual(
+ [{"february-north_branch-2011.ros",ok},
+ {"february-south_branch-2011.ros",ok},
+ {"january-north_branch-2011.ros",ok},
+ {"january-south_branch-2011.ros",ok}],Res).
+
+

0 comments on commit f778b6c

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