Permalink
Browse files

Added ros record for internal analysis usage, produced by ros_parser

Added include to test and code
  • Loading branch information...
1 parent a37080c commit d1f12c18441b925990d1744f4cd281b39ad5fb92 Gianfranco Alongi committed Feb 19, 2012
Showing with 40 additions and 2 deletions.
  1. +9 −0 One/Solution/include/ros.hrl
  2. +16 −2 One/Solution/src/ros_parser.erl
  3. +15 −0 One/Solution/test/ros_parser_tests.erl
@@ -0,0 +1,9 @@
+
+-record(entry,{type :: string(),
+ sold :: integer(),
+ projected :: integer()
+ }).
+
+-record(ros,{entries :: [#entry{}],
+ total :: integer()
+ }).
@@ -1,7 +1,21 @@
-module(ros_parser).
-export([parse/1]).
+-include("include/ros.hrl").
--spec(parse(string()) -> {error,no_total}).
-parse("")-> {error,no_total}.
+-spec(parse(string()) -> {error,no_total} | {ok,#ros{}}).
+parse("")-> {error,no_total};
+
+parse(Input) ->
+ [Total|Lines] = lists:reverse(string:tokens(Input,"\n")),
+ Entries = lists:sort([ parse_row(Line) || Line <- Lines]),
+ {ok,#ros{total = list_to_integer(Total),
+ entries = Entries}}.
+
+parse_row(Line) ->
+ [Type,Sold,Projected] = string:tokens(Line,","),
+ #entry{type = Type,
+ sold = list_to_integer(Sold),
+ projected = list_to_integer(Projected)}.
+
@@ -1,6 +1,21 @@
-module(ros_parser_tests).
-include_lib("eunit/include/eunit.hrl").
+-include("include/ros.hrl").
ros_parse_empty_test() ->
Input = "",
?assertMatch({error,no_total},ros_parser:parse(Input)).
+
+ros_parse_basic_test() ->
+ Input = "a,1,1\nb,2,2\n3",
+ ?assertMatch({ok,
+ #ros{ entries = [#entry{type = "a",
+ sold = 1,
+ projected = 1},
+ #entry{type = "b",
+ sold = 2,
+ projected = 2}
+ ],
+ total = 3}},
+ ros_parser:parse(Input)).
+

0 comments on commit d1f12c1

Please sign in to comment.