Browse Source

K6 Counting duplicates.

Frederic G. MARAND 4 years ago
parent
commit
ab87cbe98b

+ 14 - 0
go/.idea/runConfigurations/k6_counting_duplicates.xml

@@ -0,0 +1,14 @@
+<component name="ProjectRunConfigurationManager">
+  <configuration default="false" name="k6 counting duplicates" type="GoTestRunConfiguration" factoryName="Go Test" singleton="false">
+    <module name="codewars" />
+    <working_directory value="$PROJECT_DIR$" />
+    <go_parameters value="-i" />
+    <framework value="gotest" />
+    <kind value="PACKAGE" />
+    <package value="code.osinet.fr/fgm/codewars/kyu6/counting_duplicates" />
+    <directory value="$PROJECT_DIR$/kyu6/counting_duplicates" />
+    <filePath value="$PROJECT_DIR$/" />
+    <pattern value="./..." />
+    <method v="2" />
+  </configuration>
+</component>

+ 13 - 0
go/kyu6/counting_duplicates/counting_duplicates_suite_test.go

@@ -0,0 +1,13 @@
+package kata_test
+
+import (
+	"testing"
+
+	. "github.com/onsi/ginkgo"
+	. "github.com/onsi/gomega"
+)
+
+func TestCountingDuplicates(t *testing.T) {
+	RegisterFailHandler(Fail)
+	RunSpecs(t, "CountingDuplicates Suite")
+}

+ 19 - 0
go/kyu6/counting_duplicates/k.go

@@ -0,0 +1,19 @@
+package kata
+
+import "unicode"
+
+func duplicate_count(s1 string) int {
+	hits := make(map[rune]int)
+	for _, r := range s1 {
+		l := unicode.ToLower(r)
+		n, _ := hits[l]
+		hits[l] = n + 1
+	}
+	count := 0
+	for _, n := range hits {
+		if n > 1 {
+			count++
+		}
+	}
+	return count
+}

+ 25 - 0
go/kyu6/counting_duplicates/k_test.go

@@ -0,0 +1,25 @@
+// TODO: replace with your own tests (TDD). An example to get you started is included below.
+// Ginkgo BDD Testing Framework <http://onsi.github.io/ginkgo></http:>
+// Gomega Matcher Library <http://onsi.github.io/gomega></http:>
+
+package kata
+
+import (
+	. "github.com/onsi/ginkgo"
+	. "github.com/onsi/gomega"
+)
+
+func dotest(prod string, exp int) {
+	var ans = duplicate_count(prod)
+	Expect(ans).To(Equal(exp))
+}
+
+var _ = Describe("Test Example", func() {
+
+	It("should handle basic cases", func() {
+		dotest("abcde", 0)
+		dotest("abcdea", 1)
+		dotest("abcdeaB11", 3)
+		dotest("indivisibility", 1)
+	})
+})