lib/Weathermap/Tests/MapScaleTest.php
<?php
// require_once 'PHPUnit/Framework.php';
namespace Weathermap\Tests;
//require_once dirname(__FILE__) . '/../lib/all.php';
use Weathermap\Core\Map;
use Weathermap\Core\MapScale;
use Weathermap\Core\Colour;
/**
* Test class for WeatherMapScale.
* Generated by PHPUnit on 2010-04-06 at 13:31:52.
*/
class MapScaleTest extends \PHPUnit_Framework_TestCase
{
/**
* @var MapScale
*/
protected $object;
protected $wmap;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
$this->wmap = new Map();
$this->object = new MapScale("testscale", $this->wmap);
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
}
public function testConstruction()
{
$this->assertInstanceOf("Weathermap\\Core\\MapScale", $this->object);
$this->assertEquals(0, $this->object->spanCount());
}
public function testScaleManagement()
{
$this->object->populateDefaultsIfNecessary();
$this->assertEquals(9, $this->object->spanCount());
list($min, $max) = $this->object->FindScaleExtent();
$this->assertEquals(0, $min);
$this->assertEquals(100, $max);
list($c, $key, $tag) = $this->object->ColourFromValue(0);
$this->assertInstanceOf("Weathermap\\Core\\Colour", $c);
$this->assertTrue($c->equals(new Colour(192, 192, 192)));
list($c, $key, $tag) = $this->object->ColourFromValue(0.1);
$this->assertInstanceOf("Weathermap\\Core\\Colour", $c);
$this->assertTrue($c->equals(new Colour(255, 255, 255)));
list($c, $key, $tag) = $this->object->ColourFromValue(2);
$this->assertInstanceOf("Weathermap\\Core\\Colour", $c);
$this->assertTrue($c->equals(new Colour(140, 0, 255)));
list($c, $key, $tag) = $this->object->ColourFromValue(200);
$this->assertInstanceOf("Weathermap\\Core\\Colour", $c);
$this->assertTrue($c->equals(new Colour(255, 0, 0)));
$this->object->addSpan(-10, 0, new Colour(0, 255, 0));
list($min, $max) = $this->object->FindScaleExtent();
$this->assertEquals(-10, $min);
$this->assertEquals(100, $max);
$this->object->sort();
$this->assertEquals(-10, $this->object->entries[0]->bottom);
$this->assertEquals(0, $this->object->entries[0]->top);
$this->assertEquals(10, $this->object->spanCount());
$this->object->addSpan(-10, -5, new Colour(128, 255, 0));
list($min, $max) = $this->object->FindScaleExtent();
$this->assertEquals(-10, $min);
$this->assertEquals(100, $max);
$this->object->sort();
$this->assertEquals(-10, $this->object->entries[0]->bottom);
$this->assertEquals(-5, $this->object->entries[0]->top);
$this->assertEquals(11, $this->object->spanCount());
}
}