Skip to content

Commit

Permalink
Initial code
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiante committed Oct 13, 2020
1 parent 506d082 commit 1c1ba03
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
30 changes: 30 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package main

import (
"bufio"
"fmt"
"os"
sponge_case "sponge-case/sponge-case"
)

func main() {
if len(os.Args) == 2 {
applyToArgs()
} else {
applyToStdin()
}
}

func applyToStdin() {
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
fmt.Println(sponge_case.ApplyStr(scanner.Text()))
}
if err := scanner.Err(); err != nil {
fmt.Println(err)
}
}

func applyToArgs() {
fmt.Println(sponge_case.ApplyStr(os.Args[1]))
}
23 changes: 23 additions & 0 deletions sponge-case/sponge-case.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package sponge_case

import (
"math/rand"
"unicode"
)

func ApplyStr(in string) string {
out := make([]rune, len(in))
var newChar rune

for pos, char := range []rune(in) {
toUpper := rand.Float32() > 0.5
if toUpper {
newChar = unicode.ToUpper(char)
} else {
newChar = unicode.ToLower(char)
}
out[pos] = newChar
}

return string(out)
}
10 changes: 10 additions & 0 deletions sponge-case/sponge-case_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package sponge_case

import (
"fmt"
"testing"
)

func TestApplyStr(t *testing.T) {
fmt.Println(ApplyStr("Das ist wirklich nicht witzig!"))
}

0 comments on commit 1c1ba03

Please sign in to comment.