ea-Geiertest
[ class tree: ea-Geier ] [ index: ea-Geier ] [ all elements ]

Source for file numbers.inc.php

Documentation is available at numbers.inc.php

  1. <?php
  2. /**
  3.  * test case for number functions
  4.  *
  5.  * LICENSE:
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * (at your option) any later version.
  10.  * This program is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.     See the
  13.  * GNU General Public License for more details.
  14.  * You should have received a copy of the GNU General Public License along
  15.  * with this program; if not, write to the Free Software Foundation, Inc.,
  16.  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17.  *
  18.  * @package       ea-Geier
  19.  * @subpackage test
  20.  * @author       m2mtech <tech@m2m.at>
  21.  * @copyright  2007 m2m server software gmbh
  22.  * @license       http://www.gnu.org/licenses/gpl.html GNU General Public License Version 2
  23.  * @version       $Id: numbers.inc.php 133 2007-08-24 13:59:14Z m2mtech $
  24.  * @link       http://www.ea-geier.at/
  25.  */
  26.  
  27. /**
  28.  * functions to be tested
  29.  */
  30. require_once('code/numbers.inc.php');
  31.  
  32. /**
  33.  * test case for number functions
  34.  *
  35.  * @package       ea-Geier
  36.  */
  37. class TestNumbers extends UnitTestCase {
  38.     
  39.     /**
  40.      * constructor
  41.      */
  42.     function TestNumbers({
  43.         $this->UnitTestCase('Test Number Functions');
  44.     }
  45.  
  46.     /**
  47.      * tests makeDot function
  48.      *
  49.      * checks
  50.      * - numbers with comma and dot separator
  51.      * - different decimal precession
  52.      * - for rounding errors
  53.      */
  54.     function testMakeDot({
  55.         // check komma
  56.         $number '12,345';
  57.         $this->assertEqual(makeDot($number)12.35);
  58.         
  59.         // check dot
  60.         $number '12.345';
  61.         $this->assertEqual(makeDot($number)12.35);
  62.  
  63.         // check decimals - komma
  64.         $number '12,345';
  65.         $this->assertEqual(makeDot($number1)12.3);
  66.         
  67.         // check decimals - dot
  68.         $number '12.345';
  69.         $this->assertEqual(makeDot($number1)12.3);
  70.         
  71.         // check for rounding error
  72.         $number '162.295';
  73.         $this->assertEqual(makeDot($number)162.3);        
  74.     }
  75.  
  76.     /**
  77.      * tests makeDotOnly function
  78.      *
  79.      * checks
  80.      * - numbers with comma and dot separator
  81.      * - different decimal precession
  82.      * - for rounding errors
  83.      */
  84.     function testMakeDotOnly({
  85.         // check komma
  86.         $number '12,345';
  87.         $this->assertEqual(makeDotOnly($number)12.345);
  88.         
  89.         // check dot
  90.         $number '12.345';
  91.         $this->assertEqual(makeDotOnly($number)12.345);
  92.  
  93.         // check komma
  94.         $number ',345';
  95.         $this->assertEqual(makeDotOnly($number)0.345);
  96.         
  97.         // check dot
  98.         $number '.345';
  99.         $this->assertEqual(makeDotOnly($number)0.345);
  100.  
  101.         // check komma
  102.         $number '12,';
  103.         $this->assertEqual(makeDotOnly($number)12);
  104.         
  105.         // check dot
  106.         $number '12.';
  107.         $this->assertEqual(makeDotOnly($number)12);
  108.  
  109.         // check negative
  110.         $number '-12';
  111.         $this->assertEqual(makeDotOnly($number)-12);
  112.         
  113.         // check for rounding error
  114.         $number '162.295';
  115.         $this->assertEqual(makeDotOnly($number)162.295);        
  116.     }
  117.  
  118.     /**
  119.      * tests makeNum function
  120.      *
  121.      * checks
  122.      * - numbers with comma and dot separator
  123.      * - different decimal precession
  124.      * - for rounding errors
  125.      */
  126.     function testMakeNum({
  127.         // check komma
  128.         $number '12,345';
  129.         $this->assertEqual(makeNum($number)'12,35');
  130.         
  131.         // check dot
  132.         $number '12.345';
  133.         $this->assertEqual(makeNum($number)'12,35');
  134.  
  135.         // check komma
  136.         $number '12,345';
  137.         $this->assertEqual(makeNum($number',')'12,35');
  138.         
  139.         // check dot
  140.         $number '12.345';
  141.         $this->assertEqual(makeNum($number',')'12,35');
  142.  
  143.         // check komma
  144.         $number '12,345';
  145.         $this->assertEqual(makeNum($number'.')12.35);
  146.         
  147.         // check dot
  148.         $number '12.345';
  149.         $this->assertEqual(makeNum($number'.')12.35);
  150.  
  151.         // check decimals - komma
  152.         $number '12,345';
  153.         $this->assertEqual(makeNum($number','1)'12,3');
  154.         
  155.         // check decimals - dot
  156.         $number '12.345';
  157.         $this->assertEqual(makeNum($number','1)'12,3');
  158.         
  159.         // check decimals - komma
  160.         $number '12,345';
  161.         $this->assertEqual(makeNum($number'.'1)12.3);
  162.         
  163.         // check decimals - dot
  164.         $number '12.345';
  165.         $this->assertEqual(makeNum($number'.'1)12.3);
  166.         
  167.         // check for rounding error
  168.         $number '162.295';
  169.         $this->assertEqual(makeNum($number)'162,30');        
  170.  
  171.         // check for rounding error
  172.         $number '162,295';
  173.         $this->assertEqual(makeNum($number)'162,30');        
  174.  
  175.         // check for rounding error
  176.         $number '162.295';
  177.         $this->assertEqual(makeNum($number'.')162.3);        
  178.         $this->assertEqual(makeNum($number'.')'162.30');        
  179.  
  180.         // check for rounding error
  181.         $number '162,295';
  182.         $this->assertEqual(makeNum($number'.')162.3);        
  183.         $this->assertEqual(makeNum($number'.')'162.30');        
  184.     }
  185.  
  186.     /**
  187.      * tests makeNum function
  188.      *
  189.      * checks
  190.      * - numbers with comma and dot separator
  191.      * - for rounding errors
  192.      */
  193.     function testmakeNumOnly({
  194.         // check komma
  195.         $number '12,345';
  196.         $this->assertEqual(makeNumOnly($number)'12,345');
  197.         
  198.         // check dot
  199.         $number '12.345';
  200.         $this->assertEqual(makeNumOnly($number)'12,345');
  201.  
  202.         // check komma
  203.         $number '12,345';
  204.         $this->assertEqual(makeNumOnly($number',')'12,345');
  205.         
  206.         // check dot
  207.         $number '12.345';
  208.         $this->assertEqual(makeNumOnly($number',')'12,345');
  209.  
  210.         // check komma
  211.         $number '12,345';
  212.         $this->assertEqual(makeNumOnly($number'.')12.345);
  213.  
  214.         // check dot
  215.         $number '12.345';
  216.         $this->assertEqual(makeNumOnly($number'.')12.345);
  217.  
  218.         // check without decimals - komma
  219.         $number '12,';
  220.         $this->assertEqual(makeNumOnly($number',')'12');
  221.         
  222.         // check without decimals - dot
  223.         $number '12.';
  224.         $this->assertEqual(makeNumOnly($number',')'12');
  225.         
  226.         // check without decimals - none
  227.         $number '12';
  228.         $this->assertEqual(makeNumOnly($number',')'12');
  229.         
  230.         // check without decimals - komma
  231.         $number '12,';
  232.         $this->assertEqual(makeNumOnly($number'.')12);
  233.         
  234.         // check without decimals - dot
  235.         $number '12.';
  236.         $this->assertEqual(makeNumOnly($number'.')12);
  237.         
  238.         // check without decimals - none
  239.         $number '12';
  240.         $this->assertEqual(makeNumOnly($number'.')12);
  241.  
  242.         // check only decimals - komma
  243.         $number ',345';
  244.         $this->assertEqual(makeNumOnly($number',')'0,345');
  245.         
  246.         // check only decimals - dot
  247.         $number '.345';
  248.         $this->assertEqual(makeNumOnly($number',')'0,345');
  249.         
  250.         // check only decimals - komma
  251.         $number ',345';
  252.         $this->assertEqual(makeNumOnly($number'.')0.345);
  253.         
  254.         // check only decimals - dot
  255.         $number '.345';
  256.         $this->assertEqual(makeNumOnly($number'.')0.345);
  257.         
  258.         // check for rounding error
  259.         $number '162.295';
  260.         $this->assertEqual(makeNumOnly($number)'162,295');        
  261.  
  262.         // check for rounding error
  263.         $number '162,295';
  264.         $this->assertEqual(makeNumOnly($number)'162,295');        
  265.  
  266.         // check for rounding error
  267.         $number '162.295';
  268.         $this->assertEqual(makeNumOnly($number'.')162.295);        
  269.  
  270.         // check for rounding error
  271.         $number '162,295';
  272.         $this->assertEqual(makeNumOnly($number'.')162.295);        
  273.     }
  274.  
  275. }
  276. ?>

Documentation generated on Sun, 09 Sep 2007 17:09:14 +0200 by phpDocumentor 1.3.1