aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-215/lance-wicks/go/main.go38
-rw-r--r--challenge-215/lance-wicks/go/main_test.go47
2 files changed, 85 insertions, 0 deletions
diff --git a/challenge-215/lance-wicks/go/main.go b/challenge-215/lance-wicks/go/main.go
new file mode 100644
index 0000000000..318c627a2c
--- /dev/null
+++ b/challenge-215/lance-wicks/go/main.go
@@ -0,0 +1,38 @@
+package main
+
+import (
+ "fmt"
+ "os"
+ "sort"
+ "strings"
+)
+
+func IsNotAlphaOrder(input string) (res bool) {
+
+ chars := strings.Split(input, "")
+
+ sort.Strings(chars)
+ sorted := strings.Join(chars, "")
+
+ out_of_order := input != sorted
+ return out_of_order
+}
+
+func Count(list []string) (res int) {
+
+ count := 0
+ for _, word := range list {
+ if IsNotAlphaOrder(word) {
+ count++
+ }
+ }
+
+ return count
+}
+
+func main() {
+ words := os.Args[1:]
+ fmt.Println("Input: ", strings.Join(words, ", "))
+ fmt.Println(" Output: ", Count(words))
+
+}
diff --git a/challenge-215/lance-wicks/go/main_test.go b/challenge-215/lance-wicks/go/main_test.go
new file mode 100644
index 0000000000..5780a65ffa
--- /dev/null
+++ b/challenge-215/lance-wicks/go/main_test.go
@@ -0,0 +1,47 @@
+package main
+
+import "testing"
+
+func TestIsNotAlphaOrder(t *testing.T) {
+
+ got := IsNotAlphaOrder("abc")
+ want := false
+
+ if got != want {
+ t.Errorf("Did not return false")
+ }
+
+ got = IsNotAlphaOrder("acb")
+ want = true
+
+ if got != want {
+ t.Errorf("Did not return true")
+ }
+}
+
+func TestCount(t *testing.T) {
+
+ input := []string{"abc", "xyz", "tsu"}
+ got := Count(input)
+ want := 1
+
+ if got != want {
+ t.Errorf("got %d, wanted %d", got, want)
+ }
+
+ input = []string{"rat", "cab", "dad"}
+ got = Count(input)
+ want = 3
+
+ if got != want {
+ t.Errorf("got %d, wanted %d", got, want)
+ }
+
+ input = []string{"x", "y", "z"}
+ got = Count(input)
+ want = 0
+
+ if got != want {
+ t.Errorf("got %d, wanted %d", got, want)
+ }
+}