Skip to content

Commit

Permalink
Fix high-score default argument check (#234)
Browse files Browse the repository at this point in the history
* Add failing test

* Fix high-score default argument check
  • Loading branch information
angelikatyborska authored Nov 19, 2021
1 parent 22d3a62 commit 32c925a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 17 deletions.
4 changes: 4 additions & 0 deletions lib/elixir_analyzer/test_suite/high_score.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ defmodule ElixirAnalyzer.TestSuite.HighScore do
_ignore
end
end

form do
def add_player(_ignore, _ignore, _ignore \\ @_ignore)
end
end

feature "uses a module attribute to define the initial score" do
Expand Down
54 changes: 37 additions & 17 deletions test/elixir_analyzer/test_suite/high_score_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -64,30 +64,50 @@ defmodule ElixirAnalyzer.ExerciseTest.HighScoreTest do
]
end

test_exercise_analysis "requires add_player to have a default argument that's a module attribute",
comments_include: [Constants.high_score_use_default_argument_with_module_attribute()] do
[
defmodule HighScore do
def add_player(scores, name) do
Map.put(scores, name, @any_name)
end
describe "add_player and default argument" do
test_exercise_analysis "requires add_player to have a default argument that's a module attribute",
comments_include: [Constants.high_score_use_default_argument_with_module_attribute()] do
[
defmodule HighScore do
def add_player(scores, name) do
Map.put(scores, name, @any_name)
end

def add_player(scores, name, score) do
Map.put(scores, name, score)
def add_player(scores, name, score) do
Map.put(scores, name, score)
end
end,
defmodule HighScore do
def add_player(scores, name, score \\ nil) do
score = score || @initial_score
Map.put(scores, name, score)
end
end,
defmodule HighScore do
def add_player(scores, name, score \\ 0) do
Map.put(scores, name, score)
end
end
end,
]
end

test_exercise_analysis "accepts an empty function head",
comments_exclude: [Constants.high_score_use_default_argument_with_module_attribute()] do
defmodule HighScore do
def add_player(scores, name, score \\ nil) do
score = score || @initial_score
def new(), do: %{}

@score 0
def add_player(scores, name, score \\ @score)

def add_player(scores, name, score) do
Map.put(scores, name, score)
end
end,
defmodule HighScore do
def add_player(scores, name, score \\ 0) do
Map.put(scores, name, score)

def reset_score(scores, name) do
Map.put(scores, name, @score)
end
end
]
end
end

describe "looks for a module attribute with the initial score of 0" do
Expand Down

0 comments on commit 32c925a

Please sign in to comment.