Skip to content

Commit

Permalink
feat(repeatalpha): udpate test according to 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 d344053 commit 0c11292
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 42 deletions.
18 changes: 18 additions & 0 deletions solutions/repeatalpha.go
Original file line number Diff line number Diff line change
@@ -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
}
22 changes: 0 additions & 22 deletions solutions/repeatalpha/main.go

This file was deleted.

37 changes: 17 additions & 20 deletions tests/repeatalpha_test/main.go
Original file line number Diff line number Diff line change
@@ -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", "", "")
}

0 comments on commit 0c11292

Please sign in to comment.