home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pmos2002.zip / TESTS / SRC / RANTEST.MOD < prev    next >
Text File  |  1996-09-26  |  4KB  |  115 lines

  1. MODULE RanTest;
  2.  
  3.         (********************************************************)
  4.         (*                                                      *)
  5.         (*          Test of random number generator             *)
  6.         (*                                                      *)
  7.         (*  Programmer:         P. Moylan                       *)
  8.         (*  Last edited:        25 June 1996                    *)
  9.         (*  Status:             OK                              *)
  10.         (*                                                      *)
  11.         (********************************************************)
  12.  
  13. FROM Random IMPORT
  14.     (* proc *)  RANDOM, Randomize;
  15.  
  16. FROM RandCard IMPORT
  17.     (* var  *)  seed;
  18.  
  19. FROM STextIO IMPORT
  20.     (* proc *)  WriteString, WriteLn,
  21.                 ReadChar;
  22.  
  23. FROM SWholeIO IMPORT
  24.     (* proc *)  WriteCard;
  25.  
  26. FROM SRealIO IMPORT
  27.     (* proc *)  WriteReal;
  28.  
  29. (************************************************************************)
  30. (*                              SPEED TEST                              *)
  31. (************************************************************************)
  32.  
  33. PROCEDURE SpeedTest (TestSize: CARDINAL);
  34.  
  35.     (* Generates a lot of random numbers.  Relies on the keyboard user  *)
  36.     (* having a stopwatch, because the timing is not built into this    *)
  37.     (* module.                                                          *)
  38.  
  39.     VAR j: CARDINAL;  result: REAL;
  40.  
  41.     BEGIN
  42.         FOR j := 1 TO TestSize DO
  43.             result := RANDOM();
  44.         END (*FOR*);
  45.     END SpeedTest;
  46.  
  47. (************************************************************************)
  48. (*                          PLAUSIBILITY TESTS                          *)
  49. (************************************************************************)
  50.  
  51. PROCEDURE TenThousandTest;
  52.  
  53.     (* Starting with seed = 1, after 10000 calls we should end up with  *)
  54.     (* seed = 1043618065.                                               *)
  55.  
  56.     VAR j: CARDINAL;  dummy: REAL;
  57.  
  58.     BEGIN
  59.         Randomize(1);
  60.         FOR j := 1 TO 10000 DO dummy := RANDOM(); END (*FOR*);
  61.         WriteString ("The current value of seed is ");
  62.         WriteCard (seed, 11);
  63.         WriteString (".  It should be 1043618065");
  64.         WriteLn;
  65.     END TenThousandTest;
  66.  
  67. (************************************************************************)
  68.  
  69. PROCEDURE DisplayNumbers;
  70.  
  71.     CONST TestSize = 100;
  72.  
  73.     VAR j: CARDINAL;  result: REAL;
  74.  
  75.     BEGIN
  76.         WriteString ("Start of plausibility test");  WriteLn;
  77.         FOR j := 1 TO TestSize DO
  78.             result := RANDOM();
  79.             WriteReal (result, 6);
  80.             IF j MOD 8 <> 0 THEN
  81.                 WriteString ("  ");
  82.             ELSE
  83.                 WriteLn;
  84.             END (*IF*);
  85.         END (*FOR*);
  86.         WriteLn;
  87.         WriteString ("End of plausibility test");  WriteLn;
  88.     END DisplayNumbers;
  89.  
  90. (************************************************************************)
  91.  
  92. PROCEDURE RunTheTests;
  93.  
  94.     CONST TestSize = 1000000;
  95.     VAR dummy: CHAR;
  96.  
  97.     BEGIN
  98.         DisplayNumbers;  TenThousandTest;
  99.         WriteString ("Hit <Enter> to start speed test");  WriteLn;
  100.         ReadChar (dummy);
  101.         SpeedTest (TestSize);
  102.         WriteString ("End of speed test, ");
  103.         WriteCard (TestSize, 6);  WriteString (" numbers generated");
  104.         WriteLn;
  105.     END RunTheTests;
  106.  
  107. (************************************************************************)
  108. (*                              MAIN PROGRAM                            *)
  109. (************************************************************************)
  110.  
  111. BEGIN
  112.     RunTheTests;
  113. END RanTest.
  114.  
  115.