瀏覽代碼

K5 Strings end with question mark. Two oldest ages.

Frederic G. MARAND 4 年之前
父節點
當前提交
ce3c687a1a

+ 11 - 0
go/.idea/runConfigurations/k7_strings_ends_with__.xml

@@ -0,0 +1,11 @@
+<component name="ProjectRunConfigurationManager">
+  <configuration default="false" name="k7 strings ends with ?" type="GoTestRunConfiguration" factoryName="Go Test">
+    <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/kyu7/strings_end_with_questionmark" />
+    <method v="2" />
+  </configuration>
+</component>

+ 11 - 0
go/.idea/runConfigurations/k7_two_oldest_ages.xml

@@ -0,0 +1,11 @@
+<component name="ProjectRunConfigurationManager">
+  <configuration default="false" name="k7 two oldest ages" type="GoTestRunConfiguration" factoryName="Go Test">
+    <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/kyu7/two_oldest_ages" />
+    <method v="2" />
+  </configuration>
+</component>

+ 9 - 0
go/kyu7/strings_end_with_questionmark/k.go

@@ -0,0 +1,9 @@
+package kata
+
+// Or just use strings.HasSuffix().
+func solution(str, ending string) bool {
+	if len(ending) > len(str) {
+		return false
+	}
+	return str[len(str)-len(ending):] == ending
+}

+ 24 - 0
go/kyu7/strings_end_with_questionmark/k_test.go

@@ -0,0 +1,24 @@
+// 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"
+)
+
+var _ = Describe("Example test:", func() {
+	It("Should work for fixed tests", func() {
+		Expect(solution("", "")).To(Equal(true))
+		Expect(solution(" ", "")).To(Equal(true))
+		Expect(solution("abc", "c")).To(Equal(true))
+		Expect(solution("banana", "ana")).To(Equal(true))
+		Expect(solution("a", "z")).To(Equal(false))
+		Expect(solution("", "t")).To(Equal(false))
+		Expect(solution("$a = $b + 1", "+1")).To(Equal(false))
+		Expect(solution("    ", "   ")).To(Equal(true))
+		Expect(solution("1oo", "100")).To(Equal(false))
+	})
+})

+ 13 - 0
go/kyu7/strings_end_with_questionmark/strings_end_with_questionmark_suite_test.go

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

+ 10 - 0
go/kyu7/two_oldest_ages/k.go

@@ -0,0 +1,10 @@
+package kata
+
+import "sort"
+
+func TwoOldestAges(ages []int) [2]int {
+	sort.Ints(ages)
+	res := [2]int{}
+	copy(res[:], ages[len(ages)-2:])
+	return res
+}

+ 17 - 0
go/kyu7/two_oldest_ages/k_test.go

@@ -0,0 +1,17 @@
+package kata_test
+
+import (
+	. "github.com/onsi/ginkgo"
+	. "github.com/onsi/gomega"
+
+	. "code.osinet.fr/fgm/codewars/kyu7/two_oldest_ages"
+)
+
+var _ = Describe("TwoOldestAges", func() {
+	It("should return 18 and 83 for input []int{6,5,83,5,3,18}", func() {
+		Expect(TwoOldestAges([]int{6, 5, 83, 5, 3, 18})).To(Equal([2]int{18, 83}))
+	})
+	It("should return 45 and 87 for input []int{1,5,87,45,8,8}", func() {
+		Expect(TwoOldestAges([]int{1, 5, 87, 45, 8, 8})).To(Equal([2]int{45, 87}))
+	})
+})

+ 13 - 0
go/kyu7/two_oldest_ages/two_oldest_ages_suite_test.go

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