Bird Count Test Case Appears to Use Sigils

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?

Also, for what ultimately ended up being my solution, I ended up doing this:

def increment_day_count([today | other_days]), do: [today + 1 | other_days]

and the test passed fine.

Hi!

This is one of those Elixir gotchas that every newcomer stumbles into sooner or later.

See " My list of integers is printing as a string (charlists)" in this thread: Elixir Gotchas and Common Issues Wiki - Wikis - Elixir Programming Language Forum

TL;DR: there’s nothing you can do and nothing that we can change in the test runner.

1 Like

I certainly didn’t intend to imply that there was a problem with what was provided; I assumed I was malfunctioning somehow. :smiley:

Thank you for the help!