From 0c11292bc072cd4a2cbda79dc7f22bc48265c1a2 Mon Sep 17 00:00:00 2001 From: nprimo Date: Mon, 3 Jun 2024 12:31:13 +0100 Subject: [PATCH] feat(repeatalpha): udpate test according to new subject --- solutions/repeatalpha.go | 18 +++++++++++++++++ solutions/repeatalpha/main.go | 22 -------------------- tests/repeatalpha_test/main.go | 37 ++++++++++++++++------------------ 3 files changed, 35 insertions(+), 42 deletions(-) create mode 100644 solutions/repeatalpha.go delete mode 100644 solutions/repeatalpha/main.go diff --git a/solutions/repeatalpha.go b/solutions/repeatalpha.go new file mode 100644 index 00000000..6ee31863 --- /dev/null +++ b/solutions/repeatalpha.go @@ -0,0 +1,18 @@ +package solutions + +import "unicode" + +func RepeatAlpha(s string) string { + res := "" + for _, r := range s { + if unicode.IsLetter(r) { + rep := unicode.ToLower(r) - 'a' + 1 + for i := 0; i < int(rep); i++ { + res += string(r) + } + } else { + res += string(r) + } + } + return res +} diff --git a/solutions/repeatalpha/main.go b/solutions/repeatalpha/main.go deleted file mode 100644 index d2ec0712..00000000 --- a/solutions/repeatalpha/main.go +++ /dev/null @@ -1,22 +0,0 @@ -package main - -import ( - "fmt" - "os" - "unicode" -) - -func main() { - if len(os.Args) == 2 { - for _, r := range os.Args[1] { - fmt.Printf("%c", r) - if unicode.IsLetter(r) { - rep := unicode.ToLower(r) - 'a' - for i := 0; i < int(rep); i++ { - fmt.Printf("%c", r) - } - } - } - fmt.Println() - } -} diff --git a/tests/repeatalpha_test/main.go b/tests/repeatalpha_test/main.go index d2579c72..2f353dca 100644 --- a/tests/repeatalpha_test/main.go +++ b/tests/repeatalpha_test/main.go @@ -1,29 +1,26 @@ 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" ) func main() { - args := []string{ - "", - "Hello", - "World", - "Home", - "Theorem", - "Choumi is the best cat", - "abracadaba 01!", - "abc", - "MaTheMatiCs", + testCases := []struct { + in string + want string + }{ + {"abc", "abbccc"}, + {"Choumi.", "CCChhhhhhhhooooooooooooooouuuuuuuuuuuuuuuuuuuuummmmmmmmmmmmmiiiiiiiii."}, + {"", ""}, + {"abacadaba 01!", "abbacccaddddabba 01!"}, } - - args = append(args, random.StrSlice(chars.Alnum)...) - - for _, v := range args { - challenge.Program("repeatalpha", v) + for _, tc := range testCases { + got := student.RepeatAlpha(tc.in) + if got != tc.want { + fmt.Printf("RepeatAlpha(%q) = %q instead of %q\n", tc.in, got, tc.want) + os.Exit(1) + } } - challenge.Program("repeatalpha") - challenge.Program("repeatalpha", "", "") }