-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(firstword): update solution and test to match new subject
- Loading branch information
1 parent
97e9d5e
commit d344053
Showing
3 changed files
with
34 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package solutions | ||
|
||
import "strings" | ||
|
||
func FirstWord(s string) string { | ||
words := strings.Fields(s) | ||
res := "\n" | ||
if len(words) > 0 { | ||
res = words[0] + res | ||
} | ||
return res | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,30 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/01-edu/go-tests/lib/challenge" | ||
"github.com/01-edu/go-tests/lib/chars" | ||
"github.com/01-edu/go-tests/lib/random" | ||
"fmt" | ||
"os" | ||
student "student" | ||
) | ||
|
||
var testCases = []struct { | ||
in string | ||
want string | ||
}{ | ||
{"", "\n"}, | ||
{" a as", "a\n"}, | ||
{" f d", "f\n"}, | ||
{" asd ad", "asd\n"}, | ||
{" salut !!! ", "salut\n"}, | ||
{" salut ! ! !", "salut\n"}, | ||
{"salut ! !", "salut\n"}, | ||
} | ||
|
||
func main() { | ||
table := append(random.StrSlice(chars.Words), | ||
"", | ||
" a as", | ||
" f d", | ||
" asd ad", | ||
" salut !!! ", | ||
" salut ! ! !", | ||
"salut ! !", | ||
) | ||
for _, s := range table { | ||
challenge.Program("firstword", s) | ||
for _, tc := range testCases { | ||
got := student.FirstWord(tc.in) | ||
if got != tc.want { | ||
fmt.Printf("FirstWord(%q) = %q instead of %q\n", tc.in, got, tc.want) | ||
os.Exit(1) | ||
} | ||
} | ||
} |