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.

41 lines
969 B

25 years ago
  1. #include "test_I.h"
  2. int test_I_mul (int iterations)
  3. {
  4. int error = 0;
  5. int i;
  6. // Check commutativity.
  7. for (i = iterations; i > 0; i--) {
  8. cl_I a = testrandom_I();
  9. cl_I b = testrandom_I();
  10. ASSERT2(a*b == b*a, a,b);
  11. }
  12. // Check associativity.
  13. for (i = iterations; i > 0; i--) {
  14. cl_I a = testrandom_I();
  15. cl_I b = testrandom_I();
  16. cl_I c = testrandom_I();
  17. ASSERT3((a*b)*c == a*(b*c), a,b,c);
  18. }
  19. // Check second binomial formula.
  20. for (i = iterations; i > 0; i--) {
  21. cl_I a = testrandom_I();
  22. cl_I b = testrandom_I();
  23. ASSERT2((a+b)*(a-b) == a*a-b*b, a,b);
  24. }
  25. // Check distributive formula.
  26. for (i = iterations; i > 0; i--) {
  27. cl_I a = testrandom_I();
  28. cl_I b = testrandom_I();
  29. cl_I c = testrandom_I();
  30. ASSERT3((a+c)*(b+c) == a*b+(a+b)*c+c*c, a,b,c);
  31. }
  32. // Check special cases 0, 1, -1.
  33. for (i = iterations; i > 0; i--) {
  34. cl_I a = testrandom_I();
  35. ASSERT1(a*0 == 0, a);
  36. ASSERT1(a*1 == a, a);
  37. ASSERT1(a*-1 == -a, a);
  38. }
  39. return error;
  40. }