Prechádzať zdrojové kódy

Go K7 on other machine.

Frederic G. MARAND 4 rokov pred
rodič
commit
cf77f38477

+ 2 - 0
.idea/.gitignore

@@ -0,0 +1,2 @@
+# Default ignored files
+/workspace.xml

+ 6 - 0
.idea/vcs.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
+  </component>
+</project>

+ 13 - 0
go/kyu7/floating_point_approximation/floating_point_approximation_suite_test.go

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

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

@@ -0,0 +1,9 @@
+package kata
+
+import "math"
+
+func Quadratic(a float64, b float64, c float64) float64 {
+	// Citardauq formula.
+	x2 := 2 * c / (-b - math.Sqrt(b*b-4*a*c))
+	return x2
+}

+ 41 - 0
go/kyu7/floating_point_approximation/k_test.go

@@ -0,0 +1,41 @@
+package kata_test
+
+import (
+	"fmt"
+	"math"
+
+	. "github.com/onsi/ginkgo"
+	. "github.com/onsi/gomega"
+
+	. "code.osinet.fr/fgm/codewars/kyu7/floating_point_approximation"
+)
+
+func assertFuzzyEquals(a float64, b float64, c float64) {
+	var inrange bool
+	var merr = 1e-12
+	fmt.Printf("a: %1.6e b: %1.6e c: %1.6e\n", a, b, c)
+	var x = Quadratic(a, b, c)
+	var smallest = math.Abs(x) < 1.e-1
+	if smallest == false {
+		fmt.Printf("This root is not the good one: %1.6e \n", x)
+	}
+	var y = a*x*x + b*x + c
+	inrange = math.Abs(y) <= merr
+	if inrange == false {
+		fmt.Printf("Expected f(x) should be near: 0 , but got: %1.6e\n", y)
+	}
+	//fmt.Printf("%t \n", inrange && smallest)
+	Expect(inrange && smallest).To(Equal(true))
+}
+
+var _ = Describe("Test quadratic", func() {
+
+	It("should handle basic cases", func() {
+		assertFuzzyEquals(7, 4.00e+13, 8)
+		assertFuzzyEquals(9, 1.00e+14, 1)
+		assertFuzzyEquals(3, 3.00e+09, 1)
+		assertFuzzyEquals(7, 4.00e+09, 7)
+
+	})
+
+})

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

@@ -0,0 +1,10 @@
+package kata
+
+func WordsToMarks(s string) int {
+	sum := 0
+	var start rune = 'a' - 1
+	for _, r := range s {
+		sum += int(r - start)
+	}
+	return sum
+}

+ 16 - 0
go/kyu7/love_vs_friendship/k_test.go

@@ -0,0 +1,16 @@
+package kata_test
+
+import (
+	. "github.com/onsi/ginkgo"
+	. "github.com/onsi/gomega"
+
+	. "code.osinet.fr/fgm/codewars/kyu7/love_vs_friendship"
+)
+
+var _ = Describe("basic tests", func() {
+	It("Testing for attitude", func() { Expect(WordsToMarks("attitude")).To(Equal(100)) })
+	It("Testing for friends", func() { Expect(WordsToMarks("friends")).To(Equal(75)) })
+	It("Testing for family", func() { Expect(WordsToMarks("family")).To(Equal(66)) })
+	It("Testing for selfness", func() { Expect(WordsToMarks("selfness")).To(Equal(99)) })
+	It("Testing for knowledge", func() { Expect(WordsToMarks("knowledge")).To(Equal(96)) })
+})

+ 13 - 0
go/kyu7/love_vs_friendship/love_vs_friendship_suite_test.go

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