k_test.go 791 B

1234567891011121314151617181920212223242526272829303132333435
  1. package kata_test
  2. import (
  3. . "github.com/onsi/ginkgo"
  4. . "github.com/onsi/gomega"
  5. . "code.osinet.fr/fgm/codewars/kyu5/some_egyptian_fractions"
  6. )
  7. func doTest(s string, exp []string) {
  8. var ans = Decompose(s)
  9. Expect(ans).To(Equal(exp))
  10. }
  11. var _ = Describe("Tests Decompose", func() {
  12. It("should handle 21/23", func() {
  13. doTest("21/23", []string{"1/2", "1/3", "1/13", "1/359", "1/644046"})
  14. })
  15. It("should handle 12/4", func() {
  16. doTest("12/4", []string{"3"})
  17. })
  18. It("should handle 0.66", func() {
  19. doTest("0.66", []string{"1/2", "1/7", "1/59", "1/5163", "1/53307975"})
  20. })
  21. It("should handle 0", func() {
  22. doTest("0", []string{})
  23. })
  24. It("should handle 1", func() {
  25. doTest("1", []string{"1"})
  26. })
  27. It("should handle 1.25", func() {
  28. doTest("1.25", []string{"1", "1/4"})
  29. })
  30. })