RingBufferBitsetTests.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <AzNetworking/DataStructures/RingBufferBitset.h>
  9. #include <AzCore/UnitTest/TestTypes.h>
  10. namespace UnitTest
  11. {
  12. AzNetworking::RingbufferBitset<128> test;
  13. TEST(RingbufferBitset, Push2Bits)
  14. {
  15. test.PushBackBits(2);
  16. test.SetBit(0, true);
  17. test.SetBit(1, true);
  18. EXPECT_TRUE(test.GetBit(0));
  19. EXPECT_TRUE(test.GetBit(1));
  20. }
  21. TEST(RingbufferBitset, Push4Bits)
  22. {
  23. test.PushBackBits(2);
  24. EXPECT_FALSE(test.GetBit(0));
  25. EXPECT_FALSE(test.GetBit(1));
  26. EXPECT_TRUE (test.GetBit(2));
  27. EXPECT_TRUE (test.GetBit(3));
  28. }
  29. TEST(RingbufferBitset, Push44Bits)
  30. {
  31. test.PushBackBits(40);
  32. test.SetBit(41, true);
  33. EXPECT_FALSE(test.GetBit(40));
  34. EXPECT_TRUE (test.GetBit(41));
  35. EXPECT_TRUE (test.GetBit(42));
  36. EXPECT_TRUE (test.GetBit(43));
  37. }
  38. TEST(RingbufferBitset, Push84Bits)
  39. {
  40. test.PushBackBits(40);
  41. test.SetBit(80, true);
  42. EXPECT_TRUE(test.GetBit(80));
  43. EXPECT_TRUE(test.GetBit(81));
  44. EXPECT_TRUE(test.GetBit(82));
  45. EXPECT_TRUE(test.GetBit(83));
  46. }
  47. TEST(RingbufferBitset, Push124Bits)
  48. {
  49. test.PushBackBits(40);
  50. EXPECT_TRUE(test.GetBit(120));
  51. EXPECT_TRUE(test.GetBit(121));
  52. EXPECT_TRUE(test.GetBit(122));
  53. EXPECT_TRUE(test.GetBit(123));
  54. }
  55. TEST(RingbufferBitset, TestWrap)
  56. {
  57. // Bits should reset to false after wrapping and falling out of our window
  58. test.PushBackBits(40);
  59. EXPECT_FALSE(test.GetBit(160 - 128));
  60. EXPECT_FALSE(test.GetBit(161 - 128));
  61. EXPECT_FALSE(test.GetBit(162 - 128));
  62. EXPECT_FALSE(test.GetBit(163 - 128));
  63. }
  64. }