UtilityTests.cpp 823 B

12345678910111213141516171819202122
  1. #include "tests/UtilityTests.h"
  2. #include "test/Test.h"
  3. #include "utils/Utility.h"
  4. static void testPopCount(Core::Test& test) {
  5. test.checkEqual(4, Core::popCount(0xF), "pop count 1");
  6. test.checkEqual(0, Core::popCount(0x0), "pop count 2");
  7. test.checkEqual(2, Core::popCount(0x6), "pop count 3");
  8. test.checkEqual(7, Core::popCount(0x7F), "pop count 4");
  9. test.checkEqual(3, Core::popCount(0x2A), "pop count 5");
  10. test.checkEqual(32, Core::popCount(0xFFFFFFFF), "pop count 6");
  11. test.checkEqual(64, Core::popCount(0xFFFFFFFFFFFFFFFFL), "pop count 7");
  12. test.checkEqual(44, Core::popCount(0xFFFF0FFFFFFF), "pop count 8");
  13. test.checkEqual(32, Core::popCount(-1), "pop count 9");
  14. }
  15. void Core::UtilityTests::test() {
  16. Core::Test test("Utility");
  17. testPopCount(test);
  18. test.finalize();
  19. }