Welcome both to the forum!
This is correct. Despite the test results making it seem that the “actual vs got” are equal, it’s looking at the internal state of the object and those are different. Feel free to inspect the code of TestAddMinutesStringless
to see this happening.
Your tests are currently failing with:
--- FAIL: TestAddMinutesStringless (0.00s)
--- FAIL: TestAddMinutesStringless/add_across_midnight (0.00s)
clock_test.go:54: New(23, 59).Add(2) = 00:01, want 00:01
--- FAIL: TestAddMinutesStringless/add_more_than_one_day_(1500_min_=_25_hrs) (0.00s)
clock_test.go:54: New(5, 32).Add(1500) = 06:32, want 06:32
--- FAIL: TestAddMinutesStringless/add_more_than_two_days (0.00s)
clock_test.go:54: New(1, 1).Add(3500) = 11:21, want 11:21
But opening a debugger, or inserting some prints in the tests can actually show what’s going on. Specifically, inserting this into the test:
fmt.Printf("actual: %#v (String(): %s), expected: %#v (String(): %s)\n", actual, actual.String(), expected, expected.String())
Will print:
actual: clock.Clock{minutes:1441} (String(): 00:01), expected: clock.Clock{minutes:1} (String(): 00:01)
actual: clock.Clock{minutes:1832} (String(): 06:32), expected: clock.Clock{minutes:392} (String(): 06:32)
actual: clock.Clock{minutes:3561} (String(): 11:21), expected: clock.Clock{minutes:681} (String(): 11:21)
This means that while your String
function is able to correctly take two different internal states and see them as equivalent strings, this test tests the internal state of the clock and not for the string representation (hence the “stringless” in the test name).
Maybe the test output can be improved a bit to showcase better what is going on. Feel free to open a PR in exercism/go suggesting changes :) The PR will be auto-closed but I can re-open it for you, just link this discussion in the PR.
@Nikola24 While it’s absolutely fine to ask for help here in the forum, consider also requesting mentoring, for situations like these. Using the online editor you can’t request mentoring if your tests are currently failing. However, if you submit solutions with the Exercism CLI you can request mentoring even with failing tests. I just mention this because while I’m a mentor on the Go track, I’m not sure all Go mentors see the forum regularly.