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.

26 lines
671 B

25 years ago
  1. #include "test_I.h"
  2. int test_I_logcount (int iterations)
  3. {
  4. int error = 0;
  5. int i;
  6. // Check additivity.
  7. for (i = iterations; i > 0; i--) {
  8. cl_I a = testrandom_I();
  9. cl_I b = testrandom_I();
  10. if (a >= 0 && b >= 0)
  11. ASSERT2(logcount(a) == logcount(logand(a,b)) + logcount(logandc2(a,b)), a,b);
  12. }
  13. // Check behaviour on sign change.
  14. for (i = iterations; i > 0; i--) {
  15. cl_I a = testrandom_I();
  16. ASSERT1(logcount(lognot(a)) == logcount(a), a);
  17. }
  18. // Check shift invariance.
  19. for (i = iterations; i > 0; i--) {
  20. cl_I a = testrandom_I();
  21. sintL b = random32() % 1024;
  22. ASSERT2(logcount(ash(a,b)) == logcount(a) + (minusp(a) ? b : 0), a,b);
  23. }
  24. return error;
  25. }