Shortreal.Execution.Test 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # Oberon language test and validation suite
  2. # options --mayTrap --prolog="Compiler.Compile TesterInput.txt" --command="System.Free Test B A;System.Load Test" --logFile="FoxExecutionTest.Log" --result="Shortreal.Execution.Test.Diff"
  3. # test halt and assert statements and simple procedure call (basics for the test suite)
  4. positive: test scalar SHORTREAL operators
  5. MODULE Test;
  6. IMPORT Shortreal, Random;
  7. CONST NumRetries = 100000;
  8. VAR
  9. rnd: Random.Generator;
  10. t, x0, y0, z0: REAL;
  11. x, y, z: Shortreal.SHORTREAL;
  12. i: SIZE;
  13. BEGIN
  14. NEW(rnd);
  15. FOR i := 0 TO NumRetries-1 DO
  16. t := 2*rnd.Uniform()-1;
  17. x0 := LONG(SHORT(t));
  18. ASSERT(ABS(x0 - t) <= LONG(Shortreal.eps));
  19. t := 2*rnd.Uniform()-1;
  20. y0 := LONG(SHORT(t));
  21. ASSERT(ABS(y0 - t) <= LONG(Shortreal.eps));
  22. x := SHORT(x0);
  23. y := SHORT(y0);
  24. z := SHORT(z0);
  25. ASSERT((x0 = y0) = (x = y));
  26. ASSERT((x0 # y0) = (x # y));
  27. ASSERT((x0 < y0) = (x < y));
  28. ASSERT((x0 <= y0) = (x <= y));
  29. ASSERT((x0 > y0) = (x > y));
  30. ASSERT((x0 >= y0) = (x >= y));
  31. ASSERT(-x0 = LONG(-x));
  32. ASSERT(-y0 = LONG(-y));
  33. ASSERT(ABS(x0) = LONG(ABS(x)));
  34. ASSERT(ABS(y0) = LONG(ABS(y)));
  35. ASSERT(MAX(x0,y0) = LONG(MAX(x,y)));
  36. ASSERT(MAX(y0,x0) = LONG(MAX(y,x)));
  37. ASSERT(MIN(x0,y0) = LONG(MIN(x,y)));
  38. ASSERT(MIN(y0,x0) = LONG(MIN(y,x)));
  39. z0 := x0 + y0;
  40. z := x + y;
  41. ASSERT(ABS(LONG(z) - z0) <= LONG(Shortreal.eps));
  42. z0 := x0 - y0;
  43. z := x - y;
  44. ASSERT(ABS(LONG(z) - z0) <= LONG(Shortreal.eps));
  45. z0 := x0 * y0;
  46. z := x * y;
  47. ASSERT(ABS(LONG(z) - z0) <= LONG(Shortreal.eps));
  48. IF ABS(y0) < LONG(Shortreal.eps) THEN
  49. y0 := LONG(SHORT(y0+1));
  50. y := SHORT(y0);
  51. ASSERT(ABS(LONG(y) - y0) <= LONG(Shortreal.eps));
  52. END;
  53. z0 := x0 / y0;
  54. z := x / y;
  55. ASSERT(ABS(LONG(z*y) - x0) <= LONG(Shortreal.eps));
  56. END;
  57. END Test.