Login   Register  
PHP Classes
elePHPant
Icontem

File: tests/bvt1.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of CPK Smithies  >  bitvec  >  tests/bvt1.php  >  Download  
File: tests/bvt1.php
Role: Unit test script
Content type: text/plain
Description: Unit tests on bitvec, demo prime generation
Class: bitvec
Manipulate arrays of bits with SplFixedArray class
Author: By
Last change: Moved from incorrect directory
Date: 2012-12-25 05:37
Size: 1,539 bytes
 

Contents

Class file image Download
<?php
/**
 * Unit tests for bitvec
 * @author cpks
 */
require 'bitvec.php';
require 
'tests/prime.php';

class 
bitvecTest extends PHPUnit_Framework_TestCase {
  static private 
$vec;

  public static function 
setUpBeforeClass() {
    
self::$vec = new bitvec;
  }

  public function 
testcounts() {
    
$this->assertEquals(0count(self::$vec));
    
self::$vec->setSize(33);
    
$this->assertGreaterThan(32self::$vec->getSize());
  }

  public function 
testSetAll() {
    
self::$vec->setSize(32);
    
self::$vec->setall();
    
$lim self::$vec->count();
    
$overtop $lim 1;
    
self::$vec->setSize(1024);
    
$this->assertEquals(1self::$vec[0]);
    
$this->assertEquals(1self::$vec[1]);
    
$this->assertEquals(1self::$vec[$lim 1]);
    
$this->assertEquals(0self::$vec[$overtop]);
    
self::$vec->setSize(32);
    
$this->assertEquals(1self::$vec[0]);
    
$this->assertEquals(1self::$vec[1]);
    
$this->assertEquals(1self::$vec[$lim 1]);
  }
  
/**
   * @expectedException RuntimeException
   */
  
public function testNegIndex() {
    
self::$vec[-1] = 1;
  }

  
/**
   * @expectedException RuntimeException
   */
  
public function testBigIndex() {
    
self::$vec[10000] = 1;
  }

  public function 
testPrimeGeneration() {
    
$e = new erato_prime(50); // use bitvec to generate primes using 3 sieve techniques
    
$a = new atkin_prime(50);
    
$s = new sundaram_prime(50);
    
$this->assertTrue($e->same_as($a));
    
$this->assertTrue($e->same_as($s));
  }
}