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.

138 lines
4.1KB

  1. #include "testrunner.hpp"
  2. #include "../src/PrimeClock.hpp"
  3. using namespace SynthDevKit;
  4. uint8_t test_primeclock_exception ( ) {
  5. bool has_exception = 0;
  6. PrimeClock *clock = {0};
  7. try {
  8. clock = new PrimeClock(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_primeclock_primes ( ) {
  17. PrimeClock *clock = new PrimeClock(8, 1.5);
  18. std::vector<uint16_t>::iterator it;
  19. uint16_t total;
  20. for (it = clock->primes.begin(), total = 0; it != clock->primes.end(); it++, total++) {
  21. if (total == 0) {
  22. check(*it == 2, "first prime is correct");
  23. } else if (total == 1) {
  24. check(*it == 3, "second prime is correct");
  25. } else if (total == 2) {
  26. check(*it == 5, "third prime is correct");
  27. } else if (total == 3) {
  28. check(*it == 7, "fourth prime is correct");
  29. } else if (total == 4) {
  30. check(*it == 11, "fifth prime is correct");
  31. } else if (total == 5) {
  32. check(*it == 13, "sixth prime is correct");
  33. } else if (total == 6) {
  34. check(*it == 17, "seventh prime is correct");
  35. } else if (total == 7) {
  36. check(*it == 19, "eighth prime is correct");
  37. }
  38. }
  39. check(total == 16, "the count is correct");
  40. done();
  41. }
  42. uint8_t test_primeclock_update ( ) {
  43. PrimeClock *clock = new PrimeClock(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] == false, "first entry not 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. check(results[0] == false, "first entry is still not triggered");
  64. check(results[1] == false, "second entry is still not triggered");
  65. check(results[2] == false, "third entry is still not triggered");
  66. check(results[3] == false, "fourth entry is still not triggered");
  67. // 2
  68. results = clock->update(1.5);
  69. check(results[0] == true, "first entry is triggered");
  70. check(results[1] == false, "second entry is still not triggered");
  71. check(results[2] == false, "third entry is still not triggered");
  72. check(results[3] == false, "fourth entry is still not triggered");
  73. clock->update(0);
  74. // 3
  75. results = clock->update(1.5);
  76. check(results[0] == false, "first entry is not triggered");
  77. check(results[1] == true, "second entry is triggered");
  78. check(results[2] == false, "third entry is not triggered");
  79. check(results[3] == false, "fourth entry is not triggered");
  80. clock->update(0);
  81. // 4
  82. results = clock->update(1.5);
  83. check(results[0] == false, "first entry not is triggered");
  84. check(results[1] == false, "second entry is not triggered");
  85. check(results[2] == false, "third entry is not triggered");
  86. check(results[3] == false, "fourth entry is not triggered");
  87. clock->update(0);
  88. // 5
  89. results = clock->update(1.5);
  90. check(results[0] == false, "first entry is not triggered");
  91. check(results[1] == false, "second entry is not triggered");
  92. check(results[2] == true, "third entry is triggered");
  93. check(results[3] == false, "fourth entry is not triggered");
  94. clock->update(0);
  95. // 6
  96. results = clock->update(1.5);
  97. check(results[0] == false, "first entry is not triggered");
  98. check(results[1] == false, "second entry is not triggered");
  99. check(results[2] == false, "third entry is not triggered");
  100. check(results[3] == false, "fourth entry is not triggered");
  101. clock->update(0);
  102. // 7
  103. results = clock->update(1.5);
  104. check(results[0] == false, "first entry is not triggered");
  105. check(results[1] == false, "second entry is not triggered");
  106. check(results[2] == false, "third entry is not triggered");
  107. check(results[3] == true, "fourth entry is triggered");
  108. done();
  109. }