Alpha Framework alpha--tests
[ class tree: alpha--tests ] [ index: alpha--tests ] [ all elements ]

Source for file Double_Test.php

Documentation is available at Double_Test.php

  1. <?php
  2.  
  3. /**
  4.  *
  5.  * Test case for the Double data type
  6.  * 
  7.  * @package alpha::tests
  8.  * @since 1.0
  9.  * @author John Collins <dev@alphaframework.org>
  10.  * @version $Id: Double_Test.php 1341 2011-03-17 15:02:02Z johnc $
  11.  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
  12.  * @copyright Copyright (c) 2011, John Collins (founder of Alpha Framework).
  13.  *  All rights reserved.
  14.  * 
  15.  *  <pre>
  16.  *  Redistribution and use in source and binary forms, with or
  17.  *  without modification, are permitted provided that the
  18.  *  following conditions are met:
  19.  * 
  20.  *  * Redistributions of source code must retain the above
  21.  *    copyright notice, this list of conditions and the
  22.  *    following disclaimer.
  23.  *  * Redistributions in binary form must reproduce the above
  24.  *    copyright notice, this list of conditions and the
  25.  *    following disclaimer in the documentation and/or other
  26.  *    materials provided with the distribution.
  27.  *  * Neither the name of the Alpha Framework nor the names
  28.  *    of its contributors may be used to endorse or promote
  29.  *    products derived from this software without specific
  30.  *    prior written permission.
  31.  *   
  32.  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  33.  *  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  34.  *  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  35.  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  36.  *  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  37.  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  38.  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  39.  *  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  40.  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  41.  *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  42.  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  43.  *  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  44.  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  45.  *  </pre>
  46.  *  
  47.  */
  48. class Double_Test extends PHPUnit_Framework_TestCase {
  49.     /**
  50.      * An Double for testing
  51.      * 
  52.      * @var Double 
  53.      * @since 1.0
  54.      */
  55.     private $dbl1;
  56.     
  57.     /**
  58.      * An Double for testing
  59.      * 
  60.      * @var Double 
  61.      * @since 1.0
  62.      */
  63.     private $dbl2;
  64.         
  65.     /**
  66.      * Called before the test functions will be executed
  67.      * this function is defined in PHPUnit_TestCase and overwritten
  68.      * here
  69.      * 
  70.      * @since 1.0
  71.      */
  72.     protected function setUp({        
  73.         $this->dbl1 new Double();
  74.         $this->dbl2 new Double();
  75.     }
  76.     
  77.     /** 
  78.      * Called after the test functions are executed
  79.      * this function is defined in PHPUnit_TestCase and overwritten
  80.      * here
  81.      * 
  82.      * @since 1.0
  83.      */    
  84.     protected function tearDown({        
  85.         unset($this->dbl1);
  86.         unset($this->dbl2);
  87.     }
  88.     
  89.     /**
  90.      * Testing the Double constructor for acceptance of correct data
  91.      * 
  92.      * @since 1.0
  93.      */
  94.     public function testConstructorPass({
  95.         $this->dbl1 new Double(5.77);
  96.         
  97.         $this->assertEquals(5.77$this->dbl1->getValue()"testing the Double constructor for pass");
  98.     }
  99.     
  100.     /**
  101.      * Testing passing invalid data to setValue
  102.      * 
  103.      * @since 1.0
  104.      */
  105.     public function testSetValueInvalid({
  106.         try {
  107.             $this->dbl1->setValue("blah");
  108.             $this->fail('testing passing invalid data to setValue');
  109.         }catch (AlphaException $e{
  110.             $this->assertEquals('Not a valid double value!'
  111.                 $e->getMessage()
  112.                 'testing passing invalid data to setValue');
  113.         }
  114.     }
  115.     
  116.     /**
  117.      * Testing passing valid data to setValue
  118.      * 
  119.      * @since 1.0
  120.      */
  121.     public function testSetValueValid({
  122.         $this->dbl1->setValue(0.25);
  123.         
  124.         $this->assertEquals(0.25$this->dbl1->getValue()'testing passing valid data to setValue');
  125.     }
  126.     
  127.     /**
  128.      * Testing the setSize method to see if validation fails
  129.      * 
  130.      * @since 1.0
  131.      */
  132.     public function testSetSizeInvalid({
  133.         $this->dbl1 new Double();
  134.         $this->dbl1->setSize(2);
  135.         
  136.         try {
  137.             $this->dbl1->setValue(200);
  138.             $this->fail('testing passing invalid data to setValue');
  139.         }catch (AlphaException $e{
  140.             $this->assertEquals('Not a valid double value!'
  141.                 $e->getMessage()
  142.                 'testing passing invalid data to setValue');
  143.         }
  144.     }
  145.     
  146.     /**
  147.      * Testing addition of two Double values
  148.      * 
  149.      * @since 1.0
  150.      */
  151.     public function testAddDoubles({
  152.         $this->dbl1 new Double(1.25);
  153.         $this->dbl2 new Double(3.50);
  154.         
  155.         $this->assertEquals(4.75($this->dbl1->getValue()+$this->dbl2->getValue())'testing addition of two Double values');
  156.     }    
  157.     
  158.     /**
  159.      * Testing the __toString method
  160.      * 
  161.      * @since 1.0
  162.      */
  163.     public function testToString({
  164.         $this->dbl1 new Double(5.5);
  165.         
  166.         $this->assertEquals('The price is $5.50''The price is $'.$this->dbl1'testing the __toString method');
  167.     }
  168. }
  169.  
  170. ?>

Documentation generated on Thu, 17 Mar 2011 16:44:07 +0000 by phpDocumentor 1.4.3