GDI
Cond evaluation failing on LogLevel exercise
Hi, I’m learning Elixir by doing Exercism courses. I’m on the LogLevel exercise that has to do with Atoms and Cond, I’ve been pulling my hair out over the failing test for a cond evaluation.
Here’s the issue, in the code snippet below, if the log level is 0 and the legacy? is false, it should return an atom of :trace, otherwise it should return an atom of :unknown. The tests for the two lines that have an and operator in the cond evaluation are failing and i don’t know why. I pasted the code in my local editor and there were no errors, I’m confused. Is there something I’m doing wrong?
defmodule LogLevel do
def to_label(level, legacy?) do
# Please implement the to_label/2 function
cond do
(level === 0 and legacy? == false) -> :trace
level === 1 -> :debug
level === 2 -> :info
level === 3 -> :warning
level === 4 -> :error
(level === 5 and legacy? == false) -> :fatal
true -> :unkown
end
end
def alert_recipient(level, legacy?) do
# Please implement the alert_recipient/2 function
end
end
Marked As Solved
dimitarvp
Not sure about the rest because I don’t remember the exercise but you have a typo here.
:unkown → :unknown
Also Liked
al2o3cr
Static typing still gives you error messages you have to correctly understand to find the error; for instance, the failing test for this exercise:
will fail on the assert LogLevel.to_label(0, true) == :unknown line with a message:
1) test LogLevel.to_label/1 level 0 has label trace only in a non-legacy app (LogLevelTest)
test/log_level_test.exs:6
Assertion with == failed
code: assert LogLevel.to_label(0, true) == :unknown
left: :unkown
right: :unknown
stacktrace:
test/log_level_test.exs:8: (test)
dimitarvp
True, but let’s not forget that somebody has to make this proper test. This is a fact in this exercise but it’s not always a fact in the commercial projects.
dimitarvp
The woes of dynamic languages.
Elixir is fantastic but Rust would have yelled at you on the first compilation.
Glad that you are unblocked!
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








