3
<script src="../../lib/OpenLayers.js"></script>
4
<script type="text/javascript">
7
function test_Pixel_constructor (t) {
9
pixel = new OpenLayers.Pixel(5,6);
10
t.ok( pixel instanceof OpenLayers.Pixel, "new OpenLayers.Pixel returns Pixel object" );
11
t.eq( pixel.CLASS_NAME, "OpenLayers.Pixel", "pixel.CLASS_NAME is set correctly");
12
t.eq( pixel.x, 5, "pixel.x is set correctly");
13
t.eq( pixel.y, 6, "pixel.y is set correctly");
16
function test_Pixel_constructorFromString (t) {
18
pixel = new OpenLayers.Pixel("5","6");
19
t.ok( pixel instanceof OpenLayers.Pixel, "new OpenLayers.Pixel returns Pixel object" );
20
t.eq( pixel.CLASS_NAME, "OpenLayers.Pixel", "pixel.CLASS_NAME is set correctly");
21
t.eq( pixel.x, 5, "pixel.x is set correctly");
22
t.eq( pixel.y, 6, "pixel.y is set correctly");
25
function test_Pixel_toString(t) {
27
pixel = new OpenLayers.Pixel(5,6);
28
t.eq( pixel.toString(), "x=5,y=6", "pixel.toString() returns correctly");
31
function test_Pixel_clone(t) {
33
oldPixel = new OpenLayers.Pixel(5,6);
34
pixel = oldPixel.clone();
35
t.ok( pixel instanceof OpenLayers.Pixel, "clone returns new OpenLayers.Pixel object" );
36
t.eq( pixel.x, 5, "pixel.x is set correctly");
37
t.eq( pixel.y, 6, "pixel.y is set correctly");
40
t.eq( pixel.x, 5, "changing oldPixel.x doesn't change pixel.x");
43
function test_Pixel_equals(t) {
45
pixel = new OpenLayers.Pixel(5,6);
47
px = new OpenLayers.Pixel(5,6);
48
t.eq( pixel.equals(px), true, "(5,6) equals (5,6)");
50
px = new OpenLayers.Pixel(1,6);
51
t.eq( pixel.equals(px), false, "(5,6) does not equal (1,6)");
53
px = new OpenLayers.Pixel(5,2);
54
t.eq( pixel.equals(px), false, "(5,6) does not equal (5,2)");
56
px = new OpenLayers.Pixel(1,2);
57
t.eq( pixel.equals(px), false, "(5,6) does not equal (1,2)");
59
t.ok( !pixel.equals(null), "equals() returns false on comparison to null");
63
function test_Pixel_add(t) {
66
var origPX = new OpenLayers.Pixel(5,6);
67
var oldPixel = origPX.clone();
69
var pixel = oldPixel.add(10,20);
71
t.ok( oldPixel.equals(origPX), "oldPixel not modified by add operation");
73
var px = new OpenLayers.Pixel(15,26);
74
t.ok( pixel.equals(px), "returned pixel is correct");
77
var desiredMsg = "You must pass both x and y values to the add function.";
78
OpenLayers.Console.error = function(msg) {
79
t.eq(msg, desiredMsg, "error correctly reported");
82
pixel = oldPixel.add(null, 50);
83
t.ok( oldPixel.equals(origPX), "oldPixel is not modified by erroneous add operation (null x)");
84
t.ok(pixel == null, "returns null on erroneous add operation (null x)");
86
addpx = oldPixel.add(5, null);
87
t.ok( oldPixel.equals(origPX), "oldPixel is not modified by erroneous add operation (null y)");
88
t.ok(pixel == null, "returns null on erroneous add operation (null y)");
91
function test_Pixel_offset(t) {
94
var oldPixel = new OpenLayers.Pixel(5,6);
95
var offset = new OpenLayers.Pixel(10,20);
97
pixel = oldPixel.offset(offset);
99
t.eq( oldPixel.x, 5, "oldPixel.x not modified by offset operation");
100
t.eq( oldPixel.y, 6, "oldPixel.y not modified by offset operation");
102
t.eq( pixel.x, 15, "pixel.x is set correctly");
103
t.eq( pixel.y, 26, "pixel.y is set correctly");