Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix high-score default argument check #234

Merged
merged 2 commits into from
Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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