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.

33 lines
841 B

25 years ago
  1. #include "test_I.h"
  2. #define floor(a,b) ((a) / (b))
  3. int test_I_sqrtp (int iterations)
  4. {
  5. int error = 0;
  6. int i;
  7. // Check against isqrt.
  8. for (i = iterations; i > 0; i--) {
  9. cl_I a = testrandom_I();
  10. if (a >= 0) {
  11. cl_I w;
  12. cl_boolean squarep = sqrtp(a,&w);
  13. cl_I correct_w;
  14. cl_boolean correct_squarep = isqrt(a,&correct_w);
  15. ASSERT1(squarep == correct_squarep, a);
  16. if (squarep)
  17. ASSERT1(w == correct_w, a);
  18. }
  19. }
  20. // Check certain special cases.
  21. for (i = iterations; i > 0; i--) {
  22. cl_I a = abs(testrandom_I());
  23. cl_I w;
  24. // Check a^2 is a square.
  25. ASSERT1(sqrtp(a*a,&w) && w == a, a);
  26. // Check a^2+1 is not a square, except when a=0.
  27. if (a > 0) ASSERT1(!isqrt(a*a+1,&w) && w == a, a);
  28. // Check a^2+2*a is not a square, except when a=0.
  29. ASSERT1(isqrt(a*(a+2),&w)==(a==0) && w == a, a);
  30. }
  31. return error;
  32. }