Permalink
Browse files

Added ros_analyzer tests and implementation and makefile

change to run tests
  • Loading branch information...
1 parent 5171d43 commit 93d87ecb1e59cc7b4869c921aa5230a87caa1933 Gianfranco Alongi committed Feb 19, 2012
Showing with 34 additions and 1 deletion.
  1. +2 −1 One/Solution/Makefile
  2. +19 −0 One/Solution/src/ros_analyzer.erl
  3. +13 −0 One/Solution/test/ros_analyzer_tests.erl
@@ -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().'
@@ -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).
+
+
+
+
@@ -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)).
+
+

0 comments on commit 93d87ec

Please sign in to comment.