PHP Classes
elePHPant
Icontem

File: IntegerTest.class.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Brian Takita  >  Integer  >  IntegerTest.class.php  >  Download  
File: IntegerTest.class.php
Role: Unit test script
Content type: text/plain
Description: The phpUnit test class. Also provides examples on how to use the Integer class.
Class: Integer
Integer type class that supports large numbers
Author: By
Last change: Added PHPUnit constant definition.
Date: 11 years ago
Size: 4,288 bytes
 

Contents

Class file image Download
<?
// You can get PHPUnit at http://sourceforge.net/projects/phpunit/
/*
if (!defined('PHPUnit')) {
    define('PHPUnit', 'Path to PHPUnit');
}
*/

require_once(PHPUnit . 'PHPUnit.php');
require_once(
'Integer.class.php');

class
IntegerTest extends PHPUnit_TestCase {
    var
$integer;
   
   
/**
    * The constructor.
    * @param $name String The name of the Unit Test.
    * @param &$object Compiler The Compiler, or its derivative, object.
    */
   
function IntegerTest($name) {
       
$this->PHPUnit_TestCase($name);
    }
   
    function
setUp() {
       
$this->integer = new Integer(200);
    }
   
    function
tearDown() {}
   
    function
testSet() {
       
$this->integer->set(500);
       
$this->assertEquals('500', $this->integer->get());
    }
   
    function
testGet() {
       
$this->assertEquals('200', $this->integer->get());
    }
   
    function
testGetBase() {
       
$this->assertEquals(10, $this->integer->getBase());
    }
   
    function
testToBin() {
       
$this->assertEquals('11001000', $this->integer->toBin());
       
$this->assertEquals('0011001000', $this->integer->toBin(10));
    }
   
    function
testToOct() {
       
$this->assertEquals('310', $this->integer->toOct());
       
$this->assertEquals('00310', $this->integer->toOct(5));
    }
   
    function
testToDec() {
       
$this->assertEquals('200', $this->integer->toDec());
       
$this->assertEquals('00200', $this->integer->toDec(5));
    }
   
    function
testToHex() {
       
$this->assertEquals('C8', $this->integer->toHex());
       
$this->assertEquals('000C8', $this->integer->toHex(5));
    }
   
    function
testConvert() {
       
$this->assertEquals('5', Integer::convert('5', 10, 16));
       
$this->assertEquals('21', Integer::convert('15', 16, 10));
       
$this->assertEquals('10101', Integer::convert('15', 16, 2));
    }
   
    function
testAdd() {
       
//$this->assertEquals('18', $this->integer->add('10', '8'));
       
$this->assertEquals('18', Integer::add('10', '8'));
       
$this->assertEquals('2349823480206097', Integer::add('382348', '2349823479823749'));
       
$this->assertEquals('-2', Integer::add('-10', '8'));
       
$this->assertEquals('-348', Integer::add('-10', '-338'));
       
$this->assertEquals('1B', Integer::add('13', '8', 16));
       
$this->assertEquals('4BC1800', Integer::add('3bcdd33', 'ff3acd', 16));
       
$this->assertEquals('-2BDA266', Integer::add('-3BCDD33', 'FF3ACD', 16));
    }
   
    function
testSub() {
       
$this->assertEquals('2', Integer::sub('9', '7'));
       
$this->assertEquals('2', Integer::sub('10', '8'));
       
$this->assertEquals('-2349823479441401', Integer::sub('382348', '2349823479823749'));
       
$this->assertEquals('18', Integer::sub('10', '-8'));
       
$this->assertEquals('-2', Integer::sub('-10', '-8'));
       
    }
   
    function
testMul() {
       
$this->assertEquals('63', Integer::mul('9', '7'));
       
$this->assertEquals('-80', Integer::mul('10', '-8'));
       
$this->assertEquals('80', Integer::mul('-10', '-8'));
       
$this->assertEquals('64', Integer::mul('A', 'A', 16));
       
$this->assertEquals('3C98FD57F18', Integer::mul('3cc3c', 'ff4bdA', 16));
       
//$this->assertEquals('-2', $this->integer->sub('-10', '-8'));
   
}
   
    function
testDiv() {
       
$this->assertEquals('1', Integer::div('9', '7'));
       
$this->assertEquals('10', Integer::div('100', '10'));
       
$this->assertEquals('20', Integer::div('100', '5'));
       
$this->assertEquals('-10', Integer::div('-100', '10'));
       
$this->assertEquals('440FA', Integer::div('FF3acd', '3c', 16));
       
$this->assertEquals('440FAE317A0BA6F', Integer::div('FF3acd3989abb239', '3c', 16));
    }
   
    function
testMod() {
       
$this->assertEquals('2', Integer::mod('9', '7'));
       
$this->assertEquals('0', Integer::mod('100', '10'));
       
$this->assertEquals('0', Integer::mod('100', '5'));
       
$this->assertEquals('0', Integer::mod('-100', '10'));
       
$this->assertEquals('35', Integer::mod('FF3acd', '3c', 16));
       
$this->assertEquals('35', Integer::mod('FF3acd3989abb239', '3c', 16));
    }
}
?>