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

Lab1 fib first submission #610

Closed
wants to merge 1 commit into from
Closed

Lab1 fib first submission #610

wants to merge 1 commit into from

Conversation

BaiJieCN
Copy link
Collaborator

Fixes #609

Review of colleague's PR #196

Changes proposed in this PR:

  • Implement Lab1 Fibonacci numbers
  • Test Lab1

01_fib/baijie/fib.go Show resolved Hide resolved
{input: 1,
expected: strconv.Quote("1\n")},
{input: -1,
expected: strconv.Quote("1\n")},

Choose a reason for hiding this comment

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

File is not goimports-ed (from goimports)

Suggested change
expected: strconv.Quote("1\n")},
expected: strconv.Quote("1\n")},

@codecov
Copy link

codecov bot commented Aug 26, 2019

Codecov Report

Merging #610 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #610   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files         209    210    +1     
  Lines        3952   3966   +14     
=====================================
+ Hits         3952   3966   +14
Impacted Files Coverage Δ
01_fib/baijie/fib.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 fa5b659...bd15b9b. Read the comment docs.

Copy link
Contributor

@juliaogris juliaogris left a comment

Choose a reason for hiding this comment

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

Please read through the Collected Code Review Comments

Please fix commit messages with git rebase -i HASH

Do not comment the obvious (pretty much all comments in this code base) - save comments to explain what cannot be derived from the code in one glance

actual := strconv.Quote(buf.String())

if expected != actual {
t.Errorf("Unexpected output in main()\nexpected: %q\nactual: %q", expected, actual)
Copy link
Collaborator

Choose a reason for hiding this comment

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

please fix typo

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

@juliaogris juliaogris left a comment

Choose a reason for hiding this comment

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

Just a couple of minor things, looks mostly good.
Also, please fix commit messages with git rebase -i HASH

01_fib/baijie/fib.go Show resolved Hide resolved

tests := []test{
{input: 0,
expected: strconv.Quote("")},
Copy link
Contributor

Choose a reason for hiding this comment

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

to me it would be more readable if you put it on one line.

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: strconv.Quote("1\n")},
{input: 7,
expected: strconv.Quote(`1
1
Copy link
Contributor

Choose a reason for hiding this comment

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

sorry should have said this early: consider writing this as: strings.Join([]string{"1","1","2","3"}, "\n") or similar.

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

@juliaogris juliaogris left a comment

Choose a reason for hiding this comment

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

This PR should only contain two files:

  • 01_fib/baijie/main.go
  • 01_fib/baijie/main_test.go

You have added 24.
Please fix your commit.


var out io.Writer = os.Stdout

// fib function to generate fibonacci sequence
Copy link
Collaborator

Choose a reason for hiding this comment

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

This comment is a bit redundant - it's easy to see what the function does without it. If you feel that you must comment, a suggestion would be

Suggested change
// fib function to generate fibonacci sequence
// fib generates a fibonacci sequence for _n_. It expects the existence of a
// variable named _out_ of type _io.Writer_, and will output the sequence
// to that variable; this can be used for eg. printing on screen or testing.

Personally I'd just leave it out for simplicity.

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


// fib function to generate fibonacci sequence
func fib(i int) {
// initial values
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is positively a comment that can be left out, as in my opinion it does not add value to the code.

Suggested change
// initial values

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

m, n = n, m
fmt.Fprintln(out, m)
}
// negative case
Copy link
Collaborator

Choose a reason for hiding this comment

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

Another comment that I don't think adds much value. If you must, I suggest aligning it with the upper comment for legibility. Personally, I would leave both out.

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


// main function
func main() {
fib(1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please correct this as the specs say fib(7), not fib(1): https://github.com/anz-bank/go-course/blob/master/01_fib/README.md

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

out = &buf

main()
expected := strconv.Quote("1\n")
Copy link
Collaborator

Choose a reason for hiding this comment

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

You also want to change this to test for the output on the spec.

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


main()
expected := strconv.Quote("1\n")
actual := strconv.Quote(buf.String())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let me know if I'm wrong, but I don't think using strconv.Quote here and above adds value.

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

01_fib/baijie/fib_test.go Show resolved Hide resolved
01_fib/baijie/fib_test.go Show resolved Hide resolved
{input: -1, expected: strconv.Quote("1\n")},
{input: 7, expected: strconv.Quote(strings.Join(s1, "\n") + "\n")},
{input: -7, expected: strconv.Quote(strings.Join(s2, "\n") + "\n")},
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

While I agree that the strings look much neater like this, pushing everything inside a anonymous struct literal makes it look even better. Have a look at https://dave.cheney.net/2019/05/07/prefer-table-driven-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

if test.expected != actual {
t.Errorf("Unexpected output in main()\ninput: %d\nexpected: %q\nactual : %q", test.input, test.expected, actual)
}
buf.Reset()
Copy link
Collaborator

Choose a reason for hiding this comment

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

You could avoid having to do a buf.Reset() if you pushed lines 24-25 inside the for loop.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Do you mean move below lines inside the for loop?

var buf bytes.Buffer
out = &buf

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. If you moved them inside the loop at the top, each iteration of the loop would start with a fresh buffer that you do not need to Reset() at the end of the loop.

}
}


Choose a reason for hiding this comment

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

File is not goimports-ed (from goimports)

Suggested change

@BaiJieCN
Copy link
Collaborator Author

Alex, could you advise what change is required pls?

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.

This is a pretty good submission for the first lap. There are a couple of minor things that could be cleaned up in the code, but there is also the problems that your linked issue is empty and your linked review does not exist.

While the issue and review are not directly related to Go, they are related to software engineering and are a requirement of this course. Please have a read of https://github.com/anz-bank/go-course/wiki/Software-Engineering-with-Go to understand a bit more of what I mean about "software engineering".

Then, please add some content to your linked issue, and perform a peer review of someone elses PR.

Thanks

if i >= 0 {
for j := 0; j < i; j++ {
m += n
m, n = n, m
Copy link
Contributor

Choose a reason for hiding this comment

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

These two lines are confusing. You are first changing m, and then changing it again in the next line, but referencing the first change. You can write this as one line:

m, n = n, m+n

This applies to the other case of the if statement too.

01_fib/baijie/fib_test.go Show resolved Hide resolved
if test.expected != actual {
t.Errorf("Unexpected output in main()\ninput: %d\nexpected: %q\nactual : %q", test.input, test.expected, actual)
}
buf.Reset()
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. If you moved them inside the loop at the top, each iteration of the loop would start with a fresh buffer that you do not need to Reset() at the end of the loop.

@juliaogris
Copy link
Contributor

The go-course is now closed. Thank you very much for participating.

@juliaogris juliaogris closed this Feb 8, 2020
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.

Lab1 - fib: Fibonacci Series
6 participants