Skip to content

Commit

Permalink
Fix handling blocks in dna-encoding recursion check (#397)
Browse files Browse the repository at this point in the history
* Fix handling blocks in dna-encoding recursion check

* Upgrade elixir submodule
  • Loading branch information
angelikatyborska authored Sep 30, 2023
1 parent f5232af commit 7bb938a
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
2 changes: 1 addition & 1 deletion elixir
Submodule elixir updated 72 files
+3 −3 .github/workflows/ci.yml
+1 −1 .github/workflows/pr-comment.yml
+4 −0 concepts/pipe-operator/links.json
+1 −1 concepts/structs/about.md
+1 −1 concepts/structs/introduction.md
+43 −24 config.json
+1 −1 exercises/concept/community-garden/test/community_garden_test.exs
+5 −0 exercises/concept/german-sysadmin/test/username_test.exs
+1 −1 exercises/concept/log-parser/.meta/design.md
+1 −1 exercises/concept/paint-by-number/.docs/instructions.md
+1 −1 exercises/concept/remote-control-car/.docs/introduction.md
+5 −5 exercises/practice/acronym/.docs/instructions.md
+2 −2 exercises/practice/affine-cipher/.docs/instructions.md
+4 −4 exercises/practice/all-your-base/.docs/instructions.md
+4 −4 exercises/practice/all-your-base/.meta/example.ex
+1 −1 exercises/practice/all-your-base/test/all_your_base_test.exs
+1 −1 exercises/practice/allergies/.docs/instructions.md
+2 −2 exercises/practice/armstrong-numbers/.docs/instructions.md
+1 −1 exercises/practice/bank-account/.meta/example.ex
+1 −1 exercises/practice/bank-account/lib/bank_account.ex
+1 −2 exercises/practice/binary-search-tree/.meta/config.json
+1 −1 exercises/practice/binary-search/.docs/instructions.md
+4 −4 exercises/practice/book-store/.docs/instructions.md
+57 −0 exercises/practice/bottle-song/.docs/instructions.md
+4 −0 exercises/practice/bottle-song/.formatter.exs
+26 −0 exercises/practice/bottle-song/.gitignore
+19 −0 exercises/practice/bottle-song/.meta/config.json
+1 −0 exercises/practice/bottle-song/.meta/design.md
+51 −0 exercises/practice/bottle-song/.meta/example.ex
+31 −0 exercises/practice/bottle-song/.meta/tests.toml
+9 −0 exercises/practice/bottle-song/lib/bottle_song.ex
+28 −0 exercises/practice/bottle-song/mix.exs
+144 −0 exercises/practice/bottle-song/test/bottle_song_test.exs
+2 −0 exercises/practice/bottle-song/test/test_helper.exs
+3 −3 exercises/practice/bowling/.docs/instructions.md
+32 −16 exercises/practice/circular-buffer/.docs/instructions.md
+1 −2 exercises/practice/clock/.meta/config.json
+8 −0 exercises/practice/darts/.docs/instructions.md
+1 −1 exercises/practice/dot-dsl/.docs/instructions.md
+1 −1 exercises/practice/isogram/.docs/instructions.md
+3 −3 exercises/practice/killer-sudoku-helper/.docs/instructions.md
+4 −1 exercises/practice/knapsack/.docs/instructions.md
+14 −0 exercises/practice/ledger/.docs/instructions.md
+4 −0 exercises/practice/ledger/.formatter.exs
+26 −0 exercises/practice/ledger/.gitignore
+17 −0 exercises/practice/ledger/.meta/config.json
+127 −0 exercises/practice/ledger/.meta/example.ex
+43 −0 exercises/practice/ledger/.meta/tests.toml
+104 −0 exercises/practice/ledger/lib/ledger.ex
+28 −0 exercises/practice/ledger/mix.exs
+153 −0 exercises/practice/ledger/test/ledger_test.exs
+2 −0 exercises/practice/ledger/test/test_helper.exs
+10 −8 exercises/practice/list-ops/.docs/instructions.md
+1 −1 exercises/practice/meetup/.meta/config.json
+1 −1 exercises/practice/parallel-letter-frequency/.meta/example.ex
+49 −0 exercises/practice/parallel-letter-frequency/.meta/tests.toml
+235 −58 exercises/practice/parallel-letter-frequency/test/frequency_test.exs
+2 −3 exercises/practice/perfect-numbers/.docs/instructions.md
+2 −2 exercises/practice/phone-number/.docs/instructions.md
+6 −4 exercises/practice/phone-number/.meta/example.ex
+10 −0 exercises/practice/phone-number/.meta/tests.toml
+2 −2 exercises/practice/phone-number/test/phone_number_test.exs
+2 −1 exercises/practice/pig-latin/.docs/instructions.md
+10 −10 exercises/practice/protein-translation/.docs/instructions.md
+1 −1 exercises/practice/resistor-color-trio/.docs/instructions.md
+2 −2 exercises/practice/rotational-cipher/.docs/instructions.md
+10 −10 exercises/practice/scale-generator/.docs/instructions.md
+2 −2 exercises/practice/series/.docs/instructions.md
+1 −1 exercises/practice/sgf-parsing/.docs/instructions.md
+1 −1 exercises/practice/strain/.meta/config.json
+1 −1 exercises/practice/wordy/.docs/instructions.md
+16 −16 exercises/practice/yacht/.docs/instructions.md
2 changes: 1 addition & 1 deletion lib/elixir_analyzer/test_suite/dna_encoding.ex
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ defmodule ElixirAnalyzer.TestSuite.DNAEncoding do

last_call_in_function_def =
case opts[:do] do
{:__block, _, calls} when is_list(calls) ->
{:__block__, _, calls} when is_list(calls) ->
List.last(calls)

calls when is_list(calls) ->
Expand Down
58 changes: 58 additions & 0 deletions test/elixir_analyzer/test_suite/dna_encoding_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,64 @@ defmodule ElixirAnalyzer.ExerciseTest.DNAEncodingTest do
end
end

test_exercise_analysis "a different reasonable solution",
comments: [] do
defmodule DNA do
def encode_nucleotide(code_point) do
case code_point do
?\s -> 0b0000
?A -> 0b0001
?C -> 0b0010
?G -> 0b0100
?T -> 0b1000
end
end

def decode_nucleotide(encoded_code) do
case encoded_code do
0b0000 -> ?\s
0b0001 -> ?A
0b0010 -> ?C
0b0100 -> ?G
0b1000 -> ?T
end
end

def encode(dna) do
do_encode(dna, <<>>)
end

defp do_encode([], encoded), do: encoded

defp do_encode([head | tail], encoded) do
encoded_head = encode_nucleotide(head)
do_encode(tail, <<encoded::bitstring, encoded_head::4>>)
end

def decode(dna) do
do_decode(dna, [])
|> reverse()
end

defp do_decode(<<>>, list), do: list

defp do_decode(<<head::4, rest::bitstring>>, list) do
decoded_head = decode_nucleotide(head)
do_decode(rest, [decoded_head | list])
end

defp reverse(list) do
do_reverse(list, [])
end

defp do_reverse([], reversed_list), do: reversed_list

defp do_reverse([head | tail], reversed_list) do
do_reverse(tail, [head | reversed_list])
end
end
end

test_exercise_analysis "detects the usage of the Enum module",
comments: [Constants.dna_encoding_use_recursion()] do
[
Expand Down

0 comments on commit 7bb938a

Please sign in to comment.