<?php
// testRideSpeed.php        test script for rideSpeed() function
// P. Conrad for CISC103, sect 99, 11/20/2007


   require("rideSpeed.php");


  //=======================================
  // define the tolerance 
  //=======================================
  
  // tolerance is "how far away from the expected value" the result
  // is allowed to be.    We have to have some tolerance since the calcuated
  // value involves pi.   Our hand calcuated results are rounded off to the 
  // nearest 0.01, so we allow a tolerance of 0.02.


  $tolerance = 0.02;

  //===================
  //  Run the tests 
  //=================== 

  //  Test 1

  $expected = 42.84;
  $actual = rideSpeed(2);    // two seconds gives 42.84 mph
  $diff = abs($expected-$actual);

  if ($diff < $tolerance) 
    {
      print("test 1 passed\n");
    }
  else 
    {
      print("test 1 failed\n");
      print("expected=" . $expected . "\n");
      print("actual=" . $actual . "\n");
    }

  //  Test 2

  $expected = 21.42;
  $actual = rideSpeed(4); // 4 seconds gives 21.42 mph
  $diff = abs($expected-$actual);

  if ($diff < $tolerance) 
    {
      print("test 2 passed\n");
    }
  else 
    {
      print("test 2 failed\n");
      print("expected=" . $expected . "\n");
      print("actual=" . $actual . "\n");
    }

?>