test_lastseen.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Not sure where to begin with gtest?
  2. //
  3. // What can I test with gtest?
  4. //
  5. // googletest/googletest/docs/primer.md
  6. #include "lastseen.h"
  7. #include "gtest/gtest.h"
  8. namespace {
  9. TEST(LastSeenTest, negative) {
  10. LastSeen zero(2);
  11. // buffer: -1, -1
  12. EXPECT_TRUE(zero.seen_before(-1));
  13. EXPECT_TRUE(zero.seen_before(-1));
  14. }
  15. TEST(LastSeenTest, basic) {
  16. LastSeen one(1);
  17. EXPECT_FALSE(one.seen_before(0));
  18. EXPECT_TRUE(one.seen_before(0));
  19. EXPECT_TRUE(one.seen_before(0));
  20. EXPECT_FALSE(one.seen_before(1));
  21. EXPECT_TRUE(one.seen_before(1));
  22. EXPECT_FALSE(one.seen_before(0));
  23. }
  24. TEST(LastSeenTest, Deep2) {
  25. LastSeen two(2);
  26. EXPECT_FALSE(two.seen_before(0));
  27. EXPECT_FALSE(two.seen_before(1));
  28. // buffer: 0, 1
  29. EXPECT_TRUE(two.seen_before(0));
  30. EXPECT_TRUE(two.seen_before(1));
  31. EXPECT_TRUE(two.seen_before(0));
  32. EXPECT_TRUE(two.seen_before(1));
  33. EXPECT_FALSE(two.seen_before(2));
  34. // buffer: 1, 2
  35. EXPECT_TRUE(two.seen_before(2));
  36. EXPECT_TRUE(two.seen_before(1));
  37. EXPECT_TRUE(two.seen_before(2));
  38. EXPECT_TRUE(two.seen_before(1));
  39. EXPECT_FALSE(two.seen_before(0));
  40. }
  41. TEST(LastSeenTest, More) {
  42. int x;
  43. LastSeen seven(7);
  44. for (x = 0; x < 7; x++) {
  45. EXPECT_FALSE(seven.seen_before(x));
  46. }
  47. for (x = 0; x < 7; x++) {
  48. EXPECT_TRUE(seven.seen_before(x));
  49. }
  50. EXPECT_FALSE(seven.seen_before(8));
  51. }
  52. } // namespace