Skip to content
Open
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
1 change: 1 addition & 0 deletions lib/elixir_analyzer/constants.ex
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ defmodule ElixirAnalyzer.Constants do
captains_log_do_not_use_rand_uniform_real: "elixir.captains-log.do_not_use_rand_uniform_real",
captains_log_use_rand_uniform: "elixir.captains-log.use_rand_uniform",
captains_log_use_io_lib: "elixir.captains-log.use_io_lib",
captains_log_use_erlang: "elixir.captains-log.use_erlang",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This value is a path to a file in this repo that contains the text of the analyzer comment, so you need to create a new file over there for the analyzer to work. Could you do the appropriate change over there, link to the PR in this PR's description and request a review from me?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exercism/website-copy#2395

I cannot ask anyone for a review on the repo.


# Community Garden Comments
community_garden_use_get_and_update: "elixir.community-garden.use_get_and_update",
Expand Down
9 changes: 9 additions & 0 deletions lib/elixir_analyzer/test_suite/captains_log.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,14 @@ defmodule ElixirAnalyzer.TestSuite.CaptainsLog do
calling_fn module: CaptainsLog, name: :format_stardate
called_fn module: :io_lib, name: :_
comment Constants.captains_log_use_io_lib()
suppress_if "format_stardate uses :erlang", :pass
end

assert_call "format_stardate uses :erlang" do
type :essential
calling_fn module: CaptainsLog, name: :format_stardate
called_fn module: :erlang, name: :_
comment Constants.captains_log_use_erlang()
suppress_if "format_stardate uses :io_lib", :pass
end
end
34 changes: 26 additions & 8 deletions test/elixir_analyzer/test_suite/captains_log_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,32 @@ defmodule ElixirAnalyzer.ExerciseTest.CaptainsLogTest do
end
end

test_exercise_analysis "format_stardate uses Float.round",
comments_include: [Constants.captains_log_use_io_lib()] do
defmodule CaptainsLog do
def format_stardate(stardate) do
if is_float(stardate) do
Float.round(stardate, 1) |> to_string()
else
raise ArgumentError
describe "format_stardate uses :io_lib or :erlang" do
test_exercise_analysis "format_stardate uses Float.round",
comments_include: [Constants.captains_log_use_io_lib(), Constants.captains_log_use_erlang()] do
defmodule CaptainsLog do
def format_stardate(stardate) do
if is_float(stardate) do
Float.round(stardate, 1) |> to_string()
else
raise ArgumentError
end
end
end
end

test_exercise_analysis "format_stardate uses :io_lib" do
defmodule CaptainsLog do
def format_stardate(stardate) do
to_string(:io_lib.format("~.1f", [stardate]))
end
end
end

text_exercise_analysis "format_stardate uses :erlang" do
defmodule CaptainsLog do
def format_stardate(stardate) do
:erlang.float_to_binary(stardate, [{:decimals, 1}])
end
end
end
Expand Down