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

CON-2665 [CHECKPOINT-RESTRUCTURE] Update tests and solution for lastword to be a function instead of a program #186

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions solutions/lastword.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package solutions

import (
"strings"
)

func LastWord(s string) string {
words := strings.Fields(s)
if len(words) > 0 {
return words[len(words)-1] + "\n"
}
return "\n"
}
16 changes: 0 additions & 16 deletions solutions/lastword/main.go

This file was deleted.

52 changes: 35 additions & 17 deletions tests/lastword_test/main.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,43 @@
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"
"log"
"reflect"
student "student"
)

func main() {
args := []string{
"FOR PONY",
"this ... is sparta, then again, maybe not",
" ",
" lorem,ipsum ",
}

args = append(args, random.StrSlice(chars.Words)...)
var testCases = []struct {
in string
want string
}{
{
in: " ",
want: "\n",
},
{
in: "FOR PONY",
want: "PONY\n",
},
{
in: "this ... is sparta, then again, maybe not",
want: "not\n",
},
{
in: " lorem,ipsum ",
want: "lorem,ipsum\n",
},
}

for _, v := range args {
challenge.Program("lastword", v)
func main() {
for _, tc := range testCases {
got := student.LastWord(tc.in)
if !reflect.DeepEqual(got, tc.want) {
log.Fatalf("%s(%q) == %q instead of %q\n",
"RevConcatAlternate",
tc.in,
got,
tc.want,
)
}
}

challenge.Program("lastword", "a", "b")
challenge.Program("lastword")
}
Loading