RingBufferTest.ino 897 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. WiFiEsp test: RingBufferTest
  3. Test of the RingBuffer class.
  4. */
  5. #include "WiFiEsp.h"
  6. RingBuffer buf(5);
  7. void setup()
  8. {
  9. Serial.begin(115200);
  10. Serial.println("Starting tests");
  11. buf.init();
  12. buf.push('a');
  13. assert(10, buf.endsWith("a"), true);
  14. assert(11, buf.endsWith("A"), false);
  15. assert(12, buf.endsWith("ab"), false);
  16. buf.push('b');
  17. assert(21, buf.endsWith("a"), false);
  18. assert(22, buf.endsWith("A"), false);
  19. assert(23, buf.endsWith("ab"), true);
  20. buf.push('c');
  21. buf.push('d');
  22. buf.push('e');
  23. assert(31, buf.endsWith("abcde"), true);
  24. assert(32, buf.endsWith("de"), true);
  25. buf.push('f');
  26. assert(43, buf.endsWith("bcdef"), true);
  27. assert(44, buf.endsWith("ef"), true);
  28. Serial.println("Done");
  29. }
  30. void loop()
  31. {
  32. // nothing to do
  33. }
  34. void assert(int i, bool x, bool y)
  35. {
  36. if (x!=y)
  37. {
  38. Serial.print ("FAIL ");
  39. Serial.println(i);
  40. }
  41. }