-
-
Notifications
You must be signed in to change notification settings - Fork 657
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
pig-latin: add generator and update example #994
Conversation
exercises/pig-latin/example.go
Outdated
|
||
//translate a sentence |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please start with PigLatin
for lint
exercises/pig-latin/example.go
Outdated
} | ||
return strings.Join(sw, " ") | ||
} | ||
|
||
//translates a single word |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space after //
exercises/pig-latin/example.go
Outdated
} else if x := cons.FindStringSubmatchIndex(s); x != nil { | ||
result = s[x[3]:] + s[:x[3]] + "ay" | ||
} | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's refactor naked return
t.Fatalf("PigLatin(%q) = %q, want %q.", test.in, pl, test.pl) | ||
for _, test := range testCases { | ||
if pl := PigLatin(test.input); pl != test.expected { | ||
t.Fatalf("FAIL: %s\nPigLatin(%q) = %q, want %q.", test.description, test.input, pl, test.expected) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also add a line of description for successful case ?
exercises/pig-latin/.meta/gen.go
Outdated
} | ||
|
||
// Template to generate test cases. | ||
var tmpl = `package igpay |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it was there before but what does it mean ? IMHO, better to make it piglatin
and rename the functions to Sentence
and Word
. what do you think ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks ❤️
It's great but also see my inline comments to make it a bit better.
|
||
func TestPigLatin(t *testing.T) { | ||
for _, test := range testCases { | ||
if pl := PigLatin(test.input); pl != test.expected { | ||
t.Fatalf("FAIL: %s\nPigLatin(%q) = %q, want %q.", test.description, test.input, pl, test.expected) | ||
fmt.Printf("Test: %s\n", test.description) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If test fails we will see it twice, let's write it after if
and also we can write PASS
instead of Test
since we know it passed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for updates.
a part of #605.