k_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package kata_test
  2. import (
  3. "testing"
  4. . "github.com/onsi/ginkgo"
  5. . "github.com/onsi/gomega"
  6. . "code.osinet.fr/fgm/codewars/kyu5/product_of_consecutive_fib_numbers"
  7. )
  8. func dotest(prod uint64, exp [3]uint64) {
  9. var ans = ProductFib(prod)
  10. Expect(ans).To(Equal(exp))
  11. }
  12. var _ = Describe("Test Example", func() {
  13. It("should handle basic cases", func() {
  14. dotest(4895, [3]uint64{55, 89, 1})
  15. dotest(5895, [3]uint64{89, 144, 0})
  16. dotest(229970, [3]uint64{377, 610, 1})
  17. dotest(74049690, [3]uint64{6765, 10946, 1})
  18. dotest(84049690, [3]uint64{10946, 17711, 0})
  19. dotest(193864606, [3]uint64{10946, 17711, 1})
  20. dotest(427859097160, [3]uint64{514229, 832040, 1})
  21. dotest(5456077604922913920, [3]uint64{2971215073, 4807526976, 0})
  22. })
  23. })
  24. func TestBinet(t *testing.T) {
  25. OEIS_A000045 := [...]uint64{
  26. 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597,
  27. 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418,
  28. 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465,
  29. 14930352, 24157817, 39088169, 63245986, 102334155,
  30. }
  31. var n int
  32. var actual, expected uint64
  33. for n, expected = range OEIS_A000045 {
  34. actual = Binet(uint64(n))
  35. if actual != expected {
  36. t.Errorf("n: %d, expected: %d, got %d\n", n, expected, actual)
  37. }
  38. }
  39. }