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.

31 lines
746 B

25 years ago
  1. #include "test_I.h"
  2. int test_I_xgcd (int iterations)
  3. {
  4. int error = 0;
  5. int i;
  6. // Check against gcd.
  7. for (i = iterations; i > 0; i--) {
  8. cl_I a = testrandom_I();
  9. cl_I b = testrandom_I();
  10. cl_I u, v;
  11. cl_I g = xgcd(a,b,&u,&v);
  12. ASSERT3(g == gcd(a,b), a,b,g);
  13. ASSERT4(g == u*a+v*b, a,b,u,v);
  14. if (a != 0 && b != 0) {
  15. if (abs(a) == abs(b)) {
  16. ASSERT4((u == signum(a) && v == 0) || (u == 0 && v == signum(b)), a,b,u,v);
  17. }
  18. else if (mod(abs(a),abs(b)) == 0) {
  19. ASSERT4(u == 0 && v == signum(b), a,b,u,v);
  20. }
  21. else if (mod(abs(b),abs(a)) == 0) {
  22. ASSERT4(u == signum(a) && v == 0, a,b,u,v);
  23. }
  24. else {
  25. ASSERT4(abs(u) <= floor1(abs(b),2*g) && abs(v) <= floor1(abs(a),2*g), a,b,u,v);
  26. }
  27. }
  28. }
  29. return error;
  30. }