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

nucleotide-count: add generator and update example #1014

Merged
merged 11 commits into from
Jan 16, 2018
Merged

nucleotide-count: add generator and update example #1014

merged 11 commits into from
Jan 16, 2018

Conversation

ilmanzo
Copy link
Contributor

@ilmanzo ilmanzo commented Jan 12, 2018

reference issue #605

Copy link
Contributor

@leenipper leenipper left a comment

Choose a reason for hiding this comment

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

Looking good overall.
Consider using map[byte]int as the .expected type. Doing so would also allow retaining the stub file nucleotide_count.go as it is; then I think adding a .meta/hints.md file would be helpful to give instructions about competing the type declarations in the stub file.
@ferhatelmas and @tleen - Want to chime in about this ?

{
description: "empty strand",
strand: "",
expected: map[string]int{"A": 0, "C": 0, "G": 0, "T": 0},
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be easy enough to use this expected type ?

expected map[byte]int

and then generate this as

expected: map[byte]int{'A': 0, 'C': 0, 'G': 0, 'T': 0},

A nucleotide is one single letter after all. Perhaps too nit-picky, but it seems to match the exercise problem better.
What do you think ?

Copy link
Member

Choose a reason for hiding this comment

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

Seems reasonable to me. Always a fan of more content in hints.md as well.

@ilmanzo
Copy link
Contributor Author

ilmanzo commented Jan 14, 2018

Hi, I've changed the expected type to map[byte]int and added a little hints.md ; the problem in keeping the original nucleotide_count.go is that it suggests to implement a type 'Histogram' ...
but at this point should the cases_test.go be written against the Histogram type or map[byte]int ?

Copy link
Contributor

@leenipper leenipper left a comment

Choose a reason for hiding this comment

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

A couple of tiny changes.
Otherwise, it is looking good. Thanks for helping out!

for i := range validNucleotides {
nucleotide := validNucleotides[i]
h[nucleotide], _ = dna.Count(nucleotide)
total += h[nucleotide]
result[nucleotide], _ = dna.Count(nucleotide)
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps replace

result[nucleotide], _ = dna.Count(nucleotide)

with

if result[nucleotide], e = dna.Count(nucleotide); e != nil {
return nil, e
}

Then var total is unnecessary as well as the later if test using it; it also preserves the specific error from Count.

Copy link
Contributor Author

@ilmanzo ilmanzo Jan 14, 2018

Choose a reason for hiding this comment

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

That would fail the test with invalid nucleotides, like "AGXXACT" in the test suite... Because the algorithm only iterates on valid ones "ACGT". I'll remove pointless code :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I see now.

@@ -2,7 +2,7 @@ package dna

// Histogram is a mapping from nucleotide to its count in given DNA.
// Choose a suitable data type.
type Histogram
type Histogram
Copy link
Contributor

Choose a reason for hiding this comment

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

Unnecessary white space change ?

@ferhatelmas ferhatelmas changed the title add generator for nucleotide-count and update example nucleotide-count: add generator and update example Jan 15, 2018
strs = append(strs, `'`+k+`': `+strconv.FormatFloat(t, 'f', -1, 64))
default:
}

Copy link
Contributor

Choose a reason for hiding this comment

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

rm

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah,

default:

That line is unnecessary. Can remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok .. I made it a little more useful :)

in the meantime the problem specification json structure has changed, so I updated also the generator

Copy link
Contributor

@ferhatelmas ferhatelmas left a comment

Choose a reason for hiding this comment

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

Thanks for input change, too!

@ferhatelmas ferhatelmas merged commit c1d260a into exercism:master Jan 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants