Skip to content

Commit

Permalink
feat(firstword): update solution and test to match new subject
Browse files Browse the repository at this point in the history
  • Loading branch information
nprimo authored and HarryVasanth committed Jun 27, 2024
1 parent 97e9d5e commit d344053
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 30 deletions.
12 changes: 12 additions & 0 deletions solutions/firstword.go
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
}
16 changes: 0 additions & 16 deletions solutions/firstword/main.go

This file was deleted.

36 changes: 22 additions & 14 deletions tests/firstword_test/main.go
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)
}
}
}

0 comments on commit d344053

Please sign in to comment.