k_test.go 951 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package kata_test
  2. import (
  3. "testing"
  4. . "github.com/onsi/ginkgo"
  5. . "github.com/onsi/gomega"
  6. . "code.osinet.fr/fgm/codewars/kyu7/growth_of_a_population"
  7. )
  8. var _ = Describe("NbYear", func() {
  9. It("fixed tests", func() {
  10. Expect(NbYear(1500, 5, 100, 5000)).To(Equal(15))
  11. Expect(NbYear(1500000, 2.5, 10000, 2000000)).To(Equal(10))
  12. Expect(NbYear(1500000, 0.25, 1000, 2000000)).To(Equal(94))
  13. Expect(NbYear(1500000, 0.25, -1000, 2000000)).To(Equal(151))
  14. })
  15. })
  16. func TestPopN(t *testing.T) {
  17. checks := []struct {
  18. year, p0 int
  19. percent float64
  20. aug, expected int
  21. }{
  22. {1, 1000, 2, 50, 1070},
  23. {2, 1000, 2, 50, 1141},
  24. {3, 1000, 2, 50, 1213},
  25. }
  26. for _, check := range checks {
  27. actual := PopN(check.p0, check.percent, check.aug, check.year)
  28. if actual != check.expected {
  29. t.Errorf("P0 %d + %0.2f + %d at year %d. Expected %d, got %d",
  30. check.p0, check.percent, check.aug, check.year, check.expected, actual)
  31. }
  32. }
  33. }