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.

54 lines
1.5 KiB

25 years ago
  1. #include "test_MI.h"
  2. int test_MI_mul (int iterations)
  3. {
  4. int error = 0;
  5. int i;
  6. // Check commutativity.
  7. for (i = iterations; i > 0; i--) {
  8. cl_I m = testrandom_I();
  9. cl_modint_ring R = cl_find_modint_ring(m);
  10. cl_MI a = R->canonhom(testrandom_I());
  11. cl_MI b = R->canonhom(testrandom_I());
  12. ASSERT3(a*b == b*a, m,a,b);
  13. }
  14. // Check associativity.
  15. for (i = iterations; i > 0; i--) {
  16. cl_I m = testrandom_I();
  17. cl_modint_ring R = cl_find_modint_ring(m);
  18. cl_MI a = R->canonhom(testrandom_I());
  19. cl_MI b = R->canonhom(testrandom_I());
  20. cl_MI c = R->canonhom(testrandom_I());
  21. ASSERT4((a*b)*c == a*(b*c), m,a,b,c);
  22. }
  23. // Check second binomial formula.
  24. for (i = iterations; i > 0; i--) {
  25. cl_I m = testrandom_I();
  26. cl_modint_ring R = cl_find_modint_ring(m);
  27. cl_MI a = R->canonhom(testrandom_I());
  28. cl_MI b = R->canonhom(testrandom_I());
  29. ASSERT3((a+b)*(a-b) == a*a-b*b, m,a,b);
  30. }
  31. // Check distributive formula.
  32. for (i = iterations; i > 0; i--) {
  33. cl_I m = testrandom_I();
  34. cl_modint_ring R = cl_find_modint_ring(m);
  35. cl_MI a = R->canonhom(testrandom_I());
  36. cl_MI b = R->canonhom(testrandom_I());
  37. cl_MI c = R->canonhom(testrandom_I());
  38. ASSERT4((a+c)*(b+c) == a*b+(a+b)*c+c*c, m,a,b,c);
  39. }
  40. // Check special cases 0, 1, -1.
  41. for (i = iterations; i > 0; i--) {
  42. cl_I m = testrandom_I();
  43. cl_modint_ring R = cl_find_modint_ring(m);
  44. cl_MI a = R->canonhom(testrandom_I());
  45. cl_MI z = R->zero();
  46. cl_MI o = R->one();
  47. cl_MI mo = R->canonhom(-1);
  48. ASSERT2(a*z == z, m,a);
  49. ASSERT2(a*o == a, m,a);
  50. ASSERT2(a*mo == -a, m,a);
  51. }
  52. return error;
  53. }