Hello!
I am attempting to test a solution in the Bird Watcher track. When attempting test increment_day_count/1 adds 1 to today's bird count
the test output fails (I know my result of 8
isn’t correct) because somehow mix seems to be using Sigils only on this test case.
Here’s the test in question:
defmodule BirdCountTest do
use ExUnit.Case
describe "increment_day_count/1" do
@tag task_id: 2
test "creates entry for today if no bird watching data recorded" do
assert BirdCount.increment_day_count([]) == [1]
end
@tag task_id: 2
test "adds 1 to today's bird count" do
assert BirdCount.increment_day_count([7]) == [8]
assert BirdCount.increment_day_count([4, 2, 1, 0, 10]) == [5, 2, 1, 0, 10]
end
end
end
And here is the code I wrote to achieve it:
defmodule BirdCount do
def increment_day_count([]), do: [1]
def increment_day_count(list), do: Kernel.hd(list) + 1
end
But here is the output I get:
1) test increment_day_count/1 adds 1 to today's bird count (BirdCountTest)
test/bird_count_test.exs:24
Assertion with == failed
code: assert BirdCount.increment_day_count(~c"\a") == ~c"\b"
left: 8
right: ~c"\b"
stacktrace:
test/bird_count_test.exs:26: (test)
If I modify the test to be:
assert BirdCount.increment_day_count([7]) == 1
the test runs fine, sigil-free…on the result side (I still don’t see the input):
1) test increment_day_count/1 adds 1 to today's bird count (BirdCountTest)
test/bird_count_test.exs:24
Assertion with == failed
code: assert BirdCount.increment_day_count(~c"\a") == 1
left: 8
right: 1
stacktrace:
test/bird_count_test.exs:25: (test)
and I’m at least able to see the expected output.
Eventually the test passed but suddenly seeing a test display sigils instead of human-readable expected/got was a bit of a hinderance in using the tests as a tool to guide me to the light.
What is something to check or change if this happens again in the future?