Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement lab 3 - letters #634

Merged
merged 3 commits into from
Oct 6, 2019
Merged

Implement lab 3 - letters #634

merged 3 commits into from
Oct 6, 2019

Conversation

jimbosoft
Copy link
Collaborator

Fixes #633

Review of colleague's PR #534

Changes proposed in this PR:

  • Implement Lab3 letters
  • Test Lab3

-

@codecov
Copy link

codecov bot commented Sep 6, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@dc16318). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##             master   #634   +/-   ##
=======================================
  Coverage          ?   100%           
=======================================
  Files             ?    274           
  Lines             ?   5704           
  Branches          ?      0           
=======================================
  Hits              ?   5704           
  Misses            ?      0           
  Partials          ?      0
Impacted Files Coverage Δ
03_letters/jimbotech/lab3_letter.go 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dc16318...be3c733. Read the comment docs.

runnerdave
runnerdave previously approved these changes Sep 7, 2019
Copy link
Collaborator

@runnerdave runnerdave left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think is all good, being such a simple exercise, I would recommend you to implement tables for testing though, the Code Owners seem to always want that method instead of the multiple tests you did. Here is explained: table driven testing

@runnerdave runnerdave mentioned this pull request Sep 7, 2019
Copy link
Contributor

@camscale camscale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mostly nitpicks which i expect you'll consistently ignore, but again, error strings have a certain requirements in Go for reasons, so at least please fix that.

+1 on sizing the slice capacity in sortLetters

)

func TestLetters(t *testing.T) {
var sentence = "marry had a little lamb"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: "mary" is spelt with one "r".

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

t.Errorf("Result %v differs from expected %v", res, expected)
}
}
func TestEmptySorter(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: blank line between functions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}
res := sortLetters(testMap)

eq := reflect.DeepEqual(res, expected)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: idiomatic Go eschews simple variables like this, instead preferring:

    if !reflect.DeepEqual(res, expected) {

Splitting your if over multiple lines by using an intermediate variable actually makes it less readable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

expected := []string{
"\x00:0", "a:93", "ß:100000", "å:-1",
}
res := sortLetters(testMap)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A far more common name for res here is actual. You'll see that is very common in most tests.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


eq := reflect.DeepEqual(res, expected)
if !eq {
t.Errorf("Result maps %v differs from expected %v", res, expected)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go error strings should not start with capital letters: https://github.com/golang/go/wiki/CodeReviewComments#error-strings

please fix throughout.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

func TestMain(t *testing.T) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I'm not going to go hard on what I see as unnecessary extra blank lines, but please be consistent. All your other functions do not have a blank line after the function signature; this one does.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


func TestMain(t *testing.T) {

want := "a:2\nb:1\n"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is usually called expected (along with actual). got and want are also fine, but be consistent. In a previous test you used expected, so I expect you to also use that here.

result := buf.String()

if result != want {
t.Errorf("expected %v, got %v", want, result)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow. this is tortured. expected == want, got == result. just use the same name in the code as the string. i.e:

t.Errorf("want %v, got %v", want, got)

or

t.Errorf("expected %v, actual %v", expected, actual)

Either way, more consistency please.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

@camscale camscale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

I don't know whether you noticed or not, but I can tell you that reading your tests now that you have consistent "expected" and "actual" naming, it reads quite a lot better to me. I can read it so much faster than before. It may seem like trivial nitpicking, but it does really make a difference. Thanks.

@jimbosoft jimbosoft merged commit 653e6fe into anz-bank:master Oct 6, 2019
@jimbosoft jimbosoft deleted the letters branch October 6, 2019 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lab 3 - Letter frequency
3 participants