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.

36 lines
1.0 KiB

25 years ago
  1. #include "test_I.h"
  2. int test_I_ash (int iterations)
  3. {
  4. int error = 0;
  5. int i;
  6. // Check against "*" and floor1.
  7. for (i = iterations; i > 0; i--) {
  8. cl_I a = testrandom_I();
  9. uintL b = random32() % 1024;
  10. cl_I pow2 = 1;
  11. for (uintL j = 0; j < b; j++)
  12. pow2 = pow2+pow2;
  13. ASSERT1(ash(1,(sintL)b) == pow2, b);
  14. ASSERT1(ash(1,(cl_I)b) == pow2, b);
  15. ASSERT2(ash(a,(sintL)b) == a*pow2, a,b);
  16. ASSERT2(ash(a,-(sintL)b) == floor1(a,pow2), a,b);
  17. }
  18. // Check homomorphism w.r.t. second argument.
  19. for (i = iterations; i > 0; i--) {
  20. cl_I a = testrandom_I();
  21. sintL b = random32() % 1024;
  22. sintL c = random32() % 1024;
  23. ASSERT3(ash(ash(a,b),c) == ash(a,b+c), a,b,c);
  24. ASSERT3(ash(ash(a,b),-c) == ash(a,b-c), a,b,c);
  25. ASSERT3(ash(ash(a,-b),-c) == ash(a,-b-c), a,b,c);
  26. }
  27. // Check against each other.
  28. for (i = iterations; i > 0; i--) {
  29. cl_I a = testrandom_I();
  30. uintL b = random32() % 1024;
  31. ASSERT2(ash(a,(cl_I)b) == ash(a,(sintL)b), a,b);
  32. ASSERT2(ash(a,-(cl_I)b) == ash(a,-(sintL)b), a,b);
  33. }
  34. return error;
  35. }