         Edinburgh IMP77 Compiler - Version 8.4

    1  !* Program name : IMULT
    2  
    3  !*   Title      :  VI.a    The IMP  INTEGER  Facilities
    4  !*   Version    :  II
    5  !*   Date       :  24 August 1985
    6  !*   Description:  Tests the Multiplication, Division, Exponentiation and
    7  !*                 the REM function.
    8  
    9  %Begin
   10  
   11     %string(255) param    { Used to get input from CLI}
   12  
   13     %Integer J 
   14     %Integer K 
   15     %Integer M
   16     %Integer P
   17     %Integer Q
   18  
   19     %Constant %Integer  CInt3 = 10
   20     %Constant %Integer  CInt4 = 3
   21  
   22  %owninteger failures=0
   23  
   24  %routine pass
   25    printstring("Pass")
   26    New Line
   27  %end
   28  %routine fail
   29    printstring("FAIL")
   30    New Line
   31    failures = failures+1
   32  %end
   33  
   34  
   35        
   36  
   37     %Integer %Function  F
   38  
   39       !*  An extremely simple integer function that merely
   40       !*  returns the number THREE.  Note that this function 
   41       !*  does not presuppose parameter passing or expression
   42       !*  evaluation within functions.  It merely tests the
   43       !*  ability to encorporate functions within expressions. 
   44                                                             
   45       %Result = 3
   46  
   47      %End
   48  
   49  
   50  
   51     ! Code to find out where the output is to be sent
   52     ! -----------------------------------------------
   53     ! Where the output goes to depends on the parameter after the
   54     ! name used to run the program.
   55     !                       Parameter   |   Result
   56     !                       ------------|-------------
   57     !                     No parameter  |  No output
   58     !                          "s"      |  The screen
   59     !                          "j"      |  "journal"
   60     !                     anything else |  file name entered
   61  
   62     ! NOTE THAT THIS CODE USES STRING COMPARISONS, WHICH MAY NOT HAVE BEEN
   63     ! TESTED YET. IF THE PROGRAM FAILS CHECK IT WAS NOT IN THIS PART.
   64  
   65     param=cliparam
   66     %if param = "" %then select output (2) %c
   67+    %else %if param="s" %or param="S" %then select output(1) %c
   68+    %else %if param="j" %or param="J" %then  %c
   69+       open output(2,"journal") %and select output (2) %c
   70+    %else open output(2,param) %and select output (2)
   71     
   72  
   73  
   74  
   75     New Lines(2)
   76     Print String ("INTEGER Arithmetic Validation");   New Line
   77     Print String ("=============================");   New Lines (3)
   78  
   79  
   80  
   81     Print String ("Test the INTEGER Arithmetic Operators");  New Line
   82     Print String ("-------------------------------------");  New Line
   83  
   84  
   85  
   86  
   87     !*   Test the INTEGER MULTIPLICATION 
   88            
   89     !*  Test the ability to be assigned after a expression evaluation.
   90     !*  In each of the following six tests, the destination variable
   91     !*  is the same as one of the expression arguments.  All arguments
   92     !*  are at full %INTEGER precision.
   93  
   94     New Lines (2)
   95  
   96     Print String ("Test INTEGER MULTIPLICATION.");   New Line
   97     Print String ("----------------------------");   New Line
   98  
   99  
  100     J = 50
  101     K = 10
  102  
  103     J = J * 10       { J = 500
  104     %If J = 500 %then pass %else fail
  105  
  106     J = 10 * J       { J = 5000
  107     %If J = 5000 %then pass %else fail
  108  
  109     J = 5
  110  
  111     J = J * CInt3    { J = 50
  112     %If J = 50 %then pass %else fail
  113  
  114     J = CInt3 * J    { J = 500
  115     %If J = 500 %then pass %else fail
  116  
  117     J = J * K       { J = 5000
  118     %If J = 5000 %then pass %else fail
  119  
  120     J = K * J        { J = 50000
  121     %If J = 50000 %then pass %else fail
  122  
  123     
  124     !*  Test that assignment after evaluation still works when the
  125     !*  destination variable does not appear in the expression.
  126  
  127     J = 5
  128  
  129     M = J * K    
  130     %If M = 50 %then pass %else fail
  131  
  132     
  133     !*  Now test the values of the two main variables: J and K
  134  
  135     %If J = 5 %and K = 10 %then pass %else fail
  136  
  137  
  138  
  139  
  140  
  141     !*    INTEGER EXPONENTIATION
  142  
  143     New Lines (2)
  144  
  145     Print String ("Test INTEGER EXPONENTIATION.");  New Line
  146     Print String ("----------------------------");  New Line
  147  
  148     K = 3
  149     M = 5
  150  
  151     J = K ^^ 0
  152     %If J = 1 %then pass %else fail
  153  
  154     J = K ^^ M
  155     %If J = 243 %then pass %else fail
  156  
  157     J = K ^^ CInt4
  158     %If J = 27 %then pass %else fail
  159  
  160     J = 3 ^^ 0
  161     %If J = 1 %then pass %else fail
  162  
  163     J = 3 ^^ M
  164     %If J = 243 %then pass %else fail
  165  
  166     J = 3 ^^ CInt4
  167     %If J = 27 %then pass %else fail
  168  
  169     J = CInt4 ^^ 0
  170     %If J = 1 %then pass %else fail
  171  
  172     J = CInt4 ^^ M
  173     %If J = 243 %then pass %else fail
  174  
  175     J = CInt3 ^^ CInt4
  176     %If J = 1000 %then pass %else fail
  177     
  178  
  179     New Line
  180     Print String ("Let:  J = 3  before every test with J as argument."); New Line
  181     Print String ("---") ; New Line
  182  
  183     J = 3
  184     J = J ^^ 0
  185     %If J = 1 %then pass %else fail
  186  
  187     J = 3
  188     J = J ^^ M
  189     %If J = 243 %then pass %else fail
  190  
  191     J = 3
  192     J = J ^^ Cint4
  193     %If J = 27 %then pass %else fail
  194  
  195     J = 3
  196     J = J ^^ J
  197     %If J = 27 %then pass %else fail
  198  
  199     J = M ^^ M
  200     %If J = 3125 %then pass %else fail
  201  
  202   
  203   
  204  
  205     !*    INTEGER Division
  206  
  207     New Lines (2)
  208  
  209     Print String ("Test INTEGER Division.");  New Line
  210     Print String ("----------------------");  New Line
  211  
  212     K = 30
  213     M = 5
  214  
  215     
  216     J = K // M
  217     %If J = 6 %then pass %else fail
  218  
  219     J = K // CInt4
  220     %If J = 10 %then pass %else fail
  221  
  222     J = 30 // M
  223     %If J = 6 %then pass %else fail
  224  
  225     J = 30 // CInt4
  226     %If J = 10 %then pass %else fail
  227  
  228     J = CInt3 // M
  229     %If J = 2 %then pass %else fail
  230  
  231     J = CInt3 // CInt4
  232     %If J = 3 %then pass %else fail
  233     
  234     New Line
  235     Print String ("Let:  J = 30  before every test with J as argument."); New Line
  236     Print String ("---")
  237     New Line
  238  
  239     J = 30
  240     J = J // M
  241     %If J = 6 %then pass %else fail
  242  
  243     J = 30
  244     J = J // Cint4
  245     %If J = 10 %then pass %else fail
  246  
  247     J = 30
  248     J = J // J
  249     %If J = 1 %then pass %else fail
  250  
  251     J = M // M
  252     %If J = 1 %then pass %else fail
  253  
  254  
  255  
  256  
  257     New Lines (2)
  258  
  259     Print String ("Test the Modulus Operator");  New Line
  260     Print String ("-------------------------");  New Line
  261     
  262     K = 0
  263     M = -3
  264     P = 3
  265  
  266     J = |-3|
  267     Q = |3|
  268     %if J = 3 %then pass %else fail
  269     %if Q = 3 %then pass %else fail
  270     
  271     J = |CInt4|
  272     %if J = 3 %then pass %else fail
  273  
  274     J = |K|
  275     %if J = 0 %then pass %else fail
  276  
  277     J = |M|
  278     %if J = 3 %then pass %else fail
  279  
  280     J = |P|
  281     %if J = 3 %then pass %else fail
  282  
  283     P = |P|
  284     %if P = 3 %then pass %else fail
  285  
  286     J = |F|
  287     %if J = 3 %then pass %else fail
  288  
  289     J = |(|M|)|
  290     %if J = 3 %then pass %else fail
  291  
  292     J = |(-P) + K - (|F * M|)|
  293     %if J = 12 %then pass %else fail
  294  
  295     
  296     
  297  
  298     New Lines (2)
  299  
  300     Print String ("Test the REM Function.");   New Line
  301     Print String ("----------------------");   New Line
  302  
  303     %If REM (0, 1) = REM (0, -1) = 0  %then pass %else fail
  304     %If REM (100, 10) = 0  %then pass %else fail
  305     %If REM (-100, 10) = 0 %then pass %else fail
  306     %If REM (5, 3) = 2 %then pass %else fail
  307     %If REM (-5, 3) = -2 %then pass %else fail
  308     %If REM (-5, -3) = -2 %then pass %else fail
  309  
  310  
  311  select output(1)
  312  write(failures,1);  printstring(" failure(s)");  newline
  313  
  314  %End %of %Program

  180 Statements compiled
