Ver código fonte

K5: Not very secure.

Frederic G. MARAND 4 anos atrás
pai
commit
9bae768201

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

@@ -0,0 +1,11 @@
+<component name="ProjectRunConfigurationManager">
+  <configuration default="false" name="k5 not very secure" 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/kyu5/not_very_secure" />
+    <method v="2" />
+  </configuration>
+</component>

+ 15 - 0
go/kyu5/not_very_secure/k.go

@@ -0,0 +1,15 @@
+package kata
+
+func alphanumeric(str string) bool {
+	if len(str) == 0 {
+		return false
+	}
+	for _, r := range str {
+		if !((r >= '0' && r <= '9') ||
+			(r >= 'A' && r <= 'Z') ||
+			(r >= 'a' && r <= 'z')) {
+			return false
+		}
+	}
+	return true
+}

+ 27 - 0
go/kyu5/not_very_secure/k_test.go

@@ -0,0 +1,27 @@
+// 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("Sample Test Cases:", func() {
+	It("Should return the correct values for the sample test cases!", func() {
+		Expect(alphanumeric(".*?")).To(Equal(false))
+		Expect(alphanumeric("a")).To(Equal(true))
+		Expect(alphanumeric("Mazinkaiser")).To(Equal(true))
+		Expect(alphanumeric("hello world_")).To(Equal(false))
+		Expect(alphanumeric("PassW0rd")).To(Equal(true))
+		Expect(alphanumeric("     ")).To(Equal(false))
+		Expect(alphanumeric("")).To(Equal(false))
+		Expect(alphanumeric("\n\t\n")).To(Equal(false))
+		Expect(alphanumeric("ciao\n$$_")).To(Equal(false))
+		Expect(alphanumeric("__ * __")).To(Equal(false))
+		Expect(alphanumeric("&)))(((")).To(Equal(false))
+		Expect(alphanumeric("43534h56jmTHHF3k")).To(Equal(true))
+	})
+})

+ 13 - 0
go/kyu5/not_very_secure/not_very_secure_suite_test.go

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