Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added negative test for when the input does not contain

the total even though there are rows.
  • Loading branch information...
commit 5171d4348062a388054039054fc62b764ed6510f 1 parent d1f12c1
Gianfranco Alongi authored
View
17 One/Solution/src/ros_parser.erl
@@ -6,16 +6,21 @@
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}}.
+ [Total|Lines] = lists:reverse(string:tokens(Input,"\n")),
+ case (catch list_to_integer(Total)) of
+ {'EXIT',_ } ->
+ {error,no_total};
+ IntTotal ->
+ Entries = lists:sort([ parse_row(Line) || Line <- Lines]),
+ {ok,#ros{total = IntTotal,
+ entries = Entries}}
+ end.
parse_row(Line) ->
[Type,Sold,Projected] = string:tokens(Line,","),
#entry{type = Type,
- sold = list_to_integer(Sold),
- projected = list_to_integer(Projected)}.
+ sold = list_to_integer(Sold),
+ projected = list_to_integer(Projected)}.
View
5 One/Solution/test/ros_parser_tests.erl
@@ -18,4 +18,9 @@ ros_parse_basic_test() ->
],
total = 3}},
ros_parser:parse(Input)).
+
+ros_parse_negative_no_total_but_rows_test() ->
+ Input = "a,1,1\nb,2,2",
+ ?assertMatch({error,no_total},ros_parser:parse(Input)).
+
Please sign in to comment.
Something went wrong with that request. Please try again.