-
-
Notifications
You must be signed in to change notification settings - Fork 13
Closed
Description
I noticed that several students have submitted versions where they are returning -1
alongside the error. This is because they are misreading the test cases, and think that they are required to do so. I also noticed that in the solutions in this repo, solutions 1, and 3-7 are all returning that same value. Would it be more idiomatic to return the zero value in case of an error?
I would propose some variation of the following message be suggested:
It is more idiomatic to return the zero value (since it's an int
, it would be 0
) instead of -1
. The test cases appear at first glance to be asking for a -1, but if you look at line 10 of hamming_test.go, it's just using a negative tc.want
value to indicate that there should be some error.
if tc.want < 0 {
// check if err is of error type
var _ error = err
// we expect error
if err == nil {
t.Fatalf("Distance(%q, %q). error is nil.",
tc.s1, tc.s2)
}
...
Metadata
Metadata
Assignees
Labels
No labels