loops_test.nim 1015 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import unittest
  2. import tables
  3. import basics / loops_exercises
  4. proc testLoops* =
  5. suite "Loops":
  6. test "Collatz Conjecture":
  7. check collatzConjecture(5) == @[5, 16, 8, 4, 2, 1]
  8. test "Vowels from name":
  9. check vowelsFromName("alexander") == @['a', 'e', 'a', 'e']
  10. test "Fizz buzz 30":
  11. check fizzBuzz(30) == @[
  12. "1",
  13. "2",
  14. "fizz",
  15. "4",
  16. "buzz",
  17. "fizz",
  18. "7",
  19. "8",
  20. "fizz",
  21. "buzz",
  22. "11",
  23. "fizz",
  24. "13",
  25. "14",
  26. "fizzbuzz",
  27. "16",
  28. "17",
  29. "fizz",
  30. "19",
  31. "buzz",
  32. "fizz",
  33. "22",
  34. "23",
  35. "fizz",
  36. "buzz",
  37. "26",
  38. "fizz",
  39. "28",
  40. "29",
  41. "fizzbuzz"]
  42. test "Inches to cents":
  43. check inchesToCentsTable(1, 19, 3) == {
  44. 1: 2.54,
  45. 4: 10.16,
  46. 7: 17.78,
  47. 10: 25.4,
  48. 13: 33.02,
  49. 16: 40.64,
  50. 19: 48.26
  51. }.toOrderedTable