File tree 2 files changed +51
-6
lines changed
2 files changed +51
-6
lines changed Original file line number Diff line number Diff line change 1
1
defmodule Election do
2
2
defstruct (
3
- name: "Mayor" ,
4
- candidates: [
5
- Candidate . new ( 1 , "Will Ferrel" ) ,
6
- Candidate . new ( 2 , "Kristen Wiig" )
7
- ] ,
8
- next_id: 3
3
+ name: "" ,
4
+ candidates: [ ] ,
5
+ next_id: 1
9
6
)
10
7
11
8
def run ( ) do
@@ -29,6 +26,31 @@ defmodule Election do
29
26
|> run ( )
30
27
end
31
28
29
+ @ doc """
30
+ Updates Election Struct, based on provided command.
31
+
32
+ ## Parameters
33
+
34
+ - election: Election Struct
35
+ - cmd: String based command. Each command can be shortened to what's shown
36
+ in parenthesis.
37
+ - (n)ame command updates the election name
38
+ - example: "n Mayor"
39
+ - (a)dd command adds a new candidate
40
+ - example: "a Will Ferrell"
41
+ - (v)ote command increments the vote count for candidate
42
+ - example: "v 1"
43
+ - (q)uit command returns a quit atom
44
+ - example: "q"
45
+
46
+ Returns `Election` struct
47
+
48
+ ## Examples
49
+
50
+ iex> %Election{} |> Election.update("n Mayor")
51
+ %Election{name: "Mayor"}
52
+
53
+ """
32
54
def update ( election , cmd ) when is_binary ( cmd ) do
33
55
update ( election , String . split ( cmd ) )
34
56
end
Original file line number Diff line number Diff line change
1
+ defmodule ElectionTest do
2
+ use ExUnit.Case
3
+ doctest Election
4
+
5
+ setup do
6
+ % { election: % Election { } }
7
+ end
8
+
9
+ test "updating election name from a command" , ctx do
10
+ command = "name Will Ferrell"
11
+ election = Election . update ( ctx . election , command )
12
+ assert election == % Election { name: "Will Ferrell" }
13
+ end
14
+
15
+ test "adding a new candidate from a command"
16
+
17
+ test "voting for a candidate from a command"
18
+
19
+ test "invalid command"
20
+
21
+ test "quitting the app"
22
+
23
+ end
You can’t perform that action at this time.
0 commit comments