Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added ros_analyzer tests and implementation and makefile

change to run tests
  • Loading branch information...
commit 93d87ecb1e59cc7b4869c921aa5230a87caa1933 1 parent 5171d43
Gianfranco Alongi authored
View
3  One/Solution/Makefile
@@ -5,4 +5,5 @@ all:
test:
erl -pa ebin/ -eval 'eunit:test(ros_reader,[verbose]),\
- eunit:test(ros_parser,[verbose]),init:stop().'
+ eunit:test(ros_parser,[verbose]),\
+ eunit:test(ros_analyzer,[verbose]),init:stop().'
View
19 One/Solution/src/ros_analyzer.erl
@@ -0,0 +1,19 @@
+-module(ros_analyzer).
+-include("include/ros.hrl").
+-export([analyze/1]).
+
+-spec(analyze(#ros{}) -> {error,{underflow,integer()}}).
+analyze(#ros{total = Total,entries = Entries}) ->
+ Entries_Total = sum_entries(Entries),
+ case Entries_Total - Total of
+ X when X < 0 ->
+ {error,{underflow,X}}
+ end.
+
+sum_entries([]) -> 0;
+sum_entries([#entry{projected = Projected}|T]) ->
+ Projected + sum_entries(T).
+
+
+
+
View
13 One/Solution/test/ros_analyzer_tests.erl
@@ -0,0 +1,13 @@
+-module(ros_analyzer_tests).
+-include_lib("eunit/include/eunit.hrl").
+-include("include/ros.hrl").
+
+analysis_underflow_discrepancy_test() ->
+ Entries = [#entry{type = "a",
+ sold = 1,
+ projected = 10}],
+ Analysis_input = #ros{entries = Entries,
+ total = 11},
+ ?assertEqual({error,{underflow,-1}},ros_analyzer:analyze(Analysis_input)).
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.