You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
3.6KB

  1. #include "testrunner.hpp"
  2. #include "../src/FibonacciClock.hpp"
  3. using namespace SynthDevKit;
  4. uint8_t test_fibonacciclock_exception ( ) {
  5. bool has_exception = 0;
  6. FibonacciClock *clock = {0};
  7. try {
  8. clock = new FibonacciClock(CLOCK_LIMIT + 1, 1.5);
  9. } catch (int err) {
  10. has_exception = true;
  11. }
  12. check(!clock, "clock is null");
  13. check(has_exception, "exception is thrown");
  14. done();
  15. }
  16. uint8_t test_fibonacciclock_fibonaccis ( ) {
  17. FibonacciClock *clock = new FibonacciClock(8, 1.5);
  18. std::vector<uint16_t>::iterator it;
  19. uint16_t total;
  20. for (it = clock->fibonaccis.begin(), total = 0; it != clock->fibonaccis.end(); it++, total++) {
  21. if (total == 0) {
  22. check(*it == 1, "first fibonacci is correct");
  23. } else if (total == 1) {
  24. check(*it == 2, "second fibonacci is correct");
  25. } else if (total == 2) {
  26. check(*it == 3, "third fibonacci is correct");
  27. } else if (total == 3) {
  28. check(*it == 5, "fourth fibonacci is correct");
  29. } else if (total == 4) {
  30. check(*it == 8, "fifth fibonacci is correct");
  31. } else if (total == 5) {
  32. check(*it == 13, "sixth fibonacci is correct");
  33. } else if (total == 6) {
  34. check(*it == 21, "seventh fibonacci is correct");
  35. } else if (total == 7) {
  36. check(*it == 34, "eighth fibonacci is correct");
  37. }
  38. }
  39. check(total == 8, "the count is correct");
  40. done();
  41. }
  42. uint8_t test_fibonacciclock_update ( ) {
  43. FibonacciClock *clock = new FibonacciClock(4, 1.5);
  44. bool *results;
  45. results = clock->update(0);
  46. for (uint16_t i = 0; i < 4; i++) {
  47. check(results[i] == false, "not triggered before ready");
  48. }
  49. results = clock->update(1.5);
  50. for (uint16_t i = 0; i < 4; i++) {
  51. check(results[i] == false, "not triggered on first trigger");
  52. }
  53. results = clock->update(0);
  54. results = clock->update(0);
  55. results = clock->update(0);
  56. // 1
  57. results = clock->update(1.5);
  58. check(results[0] == true, "first entry is triggered");
  59. check(results[1] == false, "second entry is not triggered");
  60. check(results[2] == false, "third entry is not triggered");
  61. check(results[3] == false, "fourth entry is not triggered");
  62. results = clock->update(0);
  63. results = clock->update(0);
  64. check(results[0] == false, "first entry is not triggered");
  65. check(results[1] == false, "second entry is still not triggered");
  66. check(results[2] == false, "third entry is still not triggered");
  67. check(results[3] == false, "fourth entry is still not triggered");
  68. // 2
  69. results = clock->update(1.5);
  70. check(results[0] == false, "first entry not is triggered");
  71. check(results[1] == true, "second entry is triggered");
  72. check(results[2] == false, "third entry is still not triggered");
  73. check(results[3] == false, "fourth entry is still not triggered");
  74. clock->update(0);
  75. // 3
  76. results = clock->update(1.5);
  77. check(results[0] == false, "first entry is not triggered");
  78. check(results[1] == false, "second entry is not triggered");
  79. check(results[2] == true, "third entry is triggered");
  80. check(results[3] == false, "fourth entry is not triggered");
  81. clock->update(0);
  82. // 4
  83. results = clock->update(1.5);
  84. check(results[0] == false, "first entry is not triggered");
  85. check(results[1] == false, "second entry is not triggered");
  86. check(results[2] == false, "third entry is not triggered");
  87. check(results[3] == false, "fourth entry is not triggered");
  88. clock->update(0);
  89. // 5
  90. results = clock->update(1.5);
  91. check(results[0] == false, "first entry is not triggered");
  92. check(results[1] == false, "second entry is not triggered");
  93. check(results[2] == false, "third entry is not triggered");
  94. check(results[3] == true, "fourth entry is triggered");
  95. done();
  96. }