Skip to content

Commit 34b2b76

Browse files
committed
0710_testing
1 parent 9e51d38 commit 34b2b76

File tree

2 files changed

+51
-6
lines changed

2 files changed

+51
-6
lines changed

vote/lib/election.ex

+28-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
defmodule Election do
22
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
96
)
107

118
def run() do
@@ -29,6 +26,31 @@ defmodule Election do
2926
|> run()
3027
end
3128

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+
"""
3254
def update(election, cmd) when is_binary(cmd) do
3355
update(election, String.split(cmd))
3456
end

vote/test/election_test.exs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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

0 commit comments

Comments
 (0)