udpated tests for completed util classes

git-svn-id: http://svn.openlayers.org/trunk/openlayers@122 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
euzuro
2006-05-18 04:22:23 +00:00
parent ac03c894dd
commit 50d4546af4
5 changed files with 271 additions and 9 deletions

View File

@@ -1,5 +1,7 @@
<ul id="testlist">
<li>test_Pixel.html</li>
<li>test_Size.html</li>
<li>test_LonLat.html</li>
<li>test_Icon.html</li>
<li>test_Marker.html</li>
<li>test_Bounds.html</li>

View File

@@ -4,20 +4,78 @@
<script type="text/javascript"><!--
var bounds;
function test_01_Bounds_constructor (t) {
t.plan( 5 );
bounds = new OpenLayers.Bounds(1,2,3,4);
t.plan( 8 );
bounds = new OpenLayers.Bounds(0,2,10,4);
t.ok( bounds instanceof OpenLayers.Bounds, "new OpenLayers.Bounds returns Bounds object" );
t.eq( bounds.CLASS_NAME, "OpenLayers.Bounds", "bounds.CLASS_NAME is set correctly" );
t.eq( bounds.minlon, 0, "bounds.minlon is set correctly" );
t.eq( bounds.minlat, 2, "bounds.minlat is set correctly" );
t.eq( bounds.maxlon, 10, "bounds.maxlon is set correctly" );
t.eq( bounds.maxlat, 4, "bounds.maxlat is set correctly" );
t.eq( bounds.width, 10, "bounds.width is set correctly" );
t.eq( bounds.height, 2, "bounds.height is set correctly" );
}
function test_02_Bounds_toBBOX(t) {
t.plan( 1 );
bounds = new OpenLayers.Bounds(1,2,3,4);
t.eq( bounds.toBBOX(), "1,2,3,4", "toBBOX() returns correct value." );
}
function test_03_Bounds_toString(t) {
t.plan( 1 );
bounds = new OpenLayers.Bounds(1,2,3,4);
t.eq( bounds.toString(), "Min lon/lat=1/2 Max lon/lat=3/4 width=2 height=2", "toString() returns correct value." );
}
function test_04_Bounds_contains(t) {
t.plan( 3 );
bounds = new OpenLayers.Bounds(10,10,40,40);
ll = new OpenLayers.LonLat(20,20);
t.eq( bounds.contains(ll), true, "bounds(10,10,40,40) correctly contains LonLat(20,20)" );
ll = new OpenLayers.LonLat(0,0);
t.eq( bounds.contains(ll), false, "bounds(10,10,40,40) correctly does not contain LonLat(0,0)" );
ll = new OpenLayers.LonLat(40,40);
t.eq( bounds.contains(ll), true, "bounds(10,10,40,40) correctly contains LonLat(40,40)" );
}
function test_05_Bounds_fromString_int(t) {
t.plan( 5 );
bounds = OpenLayers.Bounds.fromString("1,2,3,4");
t.ok( bounds instanceof OpenLayers.Bounds, "new OpenLayers.Bounds returns Bounds object" );
t.eq( bounds.minlon, 1, "bounds.minlon is set correctly" );
t.eq( bounds.minlat, 2, "bounds.minlat is set correctly" );
t.eq( bounds.maxlon, 3, "bounds.maxlon is set correctly" );
t.eq( bounds.maxlat, 4, "bounds.maxlat is set correctly" );
}
function test_02_Bounds_toBBOX(t) {
t.plan( 1 );
bounds = new OpenLayers.Bounds(1,2,3,4);
t.eq( bounds.toBBOX(), "1,2,3,4", "toBBOX() returns correct value." )
function test_06_Bounds_fromString_float(t) {
t.plan( 5 );
bounds = OpenLayers.Bounds.fromString("1.1,2.2,3.3,4.4");
t.ok( bounds instanceof OpenLayers.Bounds, "new OpenLayers.Bounds returns Bounds object" );
t.eq( bounds.minlon, 1.1, "bounds.minlon is set correctly" );
t.eq( bounds.minlat, 2.2, "bounds.minlat is set correctly" );
t.eq( bounds.maxlon, 3.3, "bounds.maxlon is set correctly" );
t.eq( bounds.maxlat, 4.4, "bounds.maxlat is set correctly" );
}
function test_07_Bounds_copyOf(t) {
t.plan( 6 );
var oldBounds = new OpenLayers.Bounds(1,2,3,4);
var bounds = oldBounds.copyOf();
t.ok( bounds instanceof OpenLayers.Bounds, "copyOf returns new OpenLayers.Bounds object" );
t.eq( bounds.minlon, 1, "bounds.minlon is set correctly" );
t.eq( bounds.minlat, 2, "bounds.minlat is set correctly" );
t.eq( bounds.maxlon, 3, "bounds.maxlon is set correctly" );
t.eq( bounds.maxlat, 4, "bounds.maxlat is set correctly" );
//change minlon of oldBounds - if bounds is a
// real copyOf, bounds.minlon should not change
oldBounds.minlon = 100;
t.eq( bounds.minlon, 1, "changing olBounds.minlon does not change bounds.minlon" );
}
// -->
</script>
</head>

View File

@@ -2,14 +2,81 @@
<head>
<script src="../lib/OpenLayers.js"></script>
<script type="text/javascript"><!--
var lonlat;
function test_01_LonLat_constructor (t) {
t.plan( 3 );
t.plan( 4 );
lonlat = new OpenLayers.LonLat(6, 5);
t.ok( lonlat instanceof OpenLayers.LonLat, "new OpenLayers.LonLat returns LonLat object" );
t.eq( lonlat.CLASS_NAME, "OpenLayers.LonLat", "lonlat.CLASS_NAME is set correctly");
t.eq( lonlat.lon, 6, "lonlat.lon is set correctly");
t.eq( lonlat.lat, 5, "lonlat.lat is set correctly");
}
function test_02_LonLat_toString(t) {
t.plan( 1 );
lonlat = new OpenLayers.LonLat(5,6);
t.eq( lonlat.toString(), "lon=5,lat=6", "lonlat.toString() returns correctly");
}
function test_02A_LonLat_toShortString(t) {
t.plan( 1 );
lonlat = new OpenLayers.LonLat(5,6);
t.eq( lonlat.toShortString(), "5, 6", "lonlat.toShortString() returns correctly");
}
function test_03_LonLat_copyOf(t) {
t.plan( 4 );
oldLonLat = new OpenLayers.LonLat(5,6);
lonlat = oldLonLat.copyOf();
t.ok( lonlat instanceof OpenLayers.LonLat, "copyOf returns new OpenLayers.LonLat object" );
t.eq( lonlat.lon, 5, "lonlat.lon is set correctly");
t.eq( lonlat.lat, 6, "lonlat.lat is set correctly");
oldLonLat.lon = 100;
t.eq( lonlat.lon, 5, "changing oldLonLat.lon doesn't change lonlat.lon");
}
function test_04_LonLat_diff(t) {
t.plan( 4 );
lonlatA = new OpenLayers.LonLat(10,100);
lonlatB = new OpenLayers.LonLat(15,150);
diffpx = lonlatA.diff(lonlatB);
t.eq( lonlatA.lon, 10, "lonlatA.lon is not modified by diff operation");
t.eq( lonlatA.lat, 100, "lonlatA.lat is not modified by diff operation");
t.eq( diffpx.lon, -5, "diffpx.lon is set correctly");
t.eq( diffpx.lat, -50, "diffpx.lat is set correctly");
}
function test_06_LonLat_equals(t) {
t.plan( 4 );
lonlat = new OpenLayers.LonLat(5,6);
ll = new OpenLayers.LonLat(5,6);
t.eq( lonlat.equals(ll), true, "(5,6) equals (5,6)");
ll = new OpenLayers.LonLat(1,6);
t.eq( lonlat.equals(ll), false, "(5,6) does not equal (1,6)");
ll = new OpenLayers.LonLat(5,2);
t.eq( lonlat.equals(ll), false, "(5,6) does not equal (5,2)");
ll = new OpenLayers.LonLat(1,2);
t.eq( lonlat.equals(ll), false, "(5,6) does not equal (1,2)");
}
function test_07_LonLat_fromString(t) {
t.plan( 3 );
lonlat = OpenLayers.LonLat.fromString("6,5");
t.ok( lonlat instanceof OpenLayers.LonLat, "new OpenLayers.LonLat returns LonLat object" );
t.eq( lonlat.lon, 6, "lonlat.lon is set correctly");
t.eq( lonlat.lat, 5, "lonlat.lat is set correctly");
}
// -->
</script>
</head>

View File

@@ -5,13 +5,91 @@
var pixel;
function test_01_Pixel_constructor (t) {
t.plan( 3 );
t.plan( 4 );
pixel = new OpenLayers.Pixel(5,6);
t.ok( pixel instanceof OpenLayers.Pixel, "new OpenLayers.Pixel returns Pixel object" );
t.eq( pixel.CLASS_NAME, "OpenLayers.Pixel", "pixel.CLASS_NAME is set correctly");
t.eq( pixel.x, 5, "pixel.x is set correctly");
t.eq( pixel.y, 6, "pixel.y is set correctly");
}
function test_02_Pixel_toString(t) {
t.plan( 1 );
pixel = new OpenLayers.Pixel(5,6);
t.eq( pixel.toString(), "x=5,y=6", "pixel.toString() returns correctly");
}
function test_03_Pixel_copyOf(t) {
t.plan( 4 );
oldPixel = new OpenLayers.Pixel(5,6);
pixel = oldPixel.copyOf();
t.ok( pixel instanceof OpenLayers.Pixel, "copyOf returns new OpenLayers.Pixel object" );
t.eq( pixel.x, 5, "pixel.x is set correctly");
t.eq( pixel.y, 6, "pixel.y is set correctly");
oldPixel.x = 100;
t.eq( pixel.x, 5, "changing oldPixel.x doesn't change pixel.x");
}
function test_04_Pixel_diff(t) {
t.plan( 4 );
pixelA = new OpenLayers.Pixel(10,100);
pixelB = new OpenLayers.Pixel(15,150);
diffpx = pixelA.diff(pixelB);
t.eq( pixelA.x, 10, "pixelA.x is not modified by diff operation");
t.eq( pixelA.y, 100, "pixelA.y is not modified by diff operation");
t.eq( diffpx.x, -5, "diffpx.x is set correctly");
t.eq( diffpx.y, -50, "diffpx.y is set correctly");
}
function test_05_Pixel_diffABS(t) {
t.plan( 4 );
pixelA = new OpenLayers.Pixel(10,100);
pixelB = new OpenLayers.Pixel(15,150);
diffABSpx = pixelA.diffABS(pixelB);
t.eq( pixelA.x, 10, "pixelA.x is not modified by diffABS operation");
t.eq( pixelA.y, 100, "pixelA.y is not modified by diffABS operation");
t.eq( diffABSpx.x, 5, "diffABSpx.x is set correctly");
t.eq( diffABSpx.y, 50, "diffABSpx.y is set correctly");
}
function test_06_Pixel_equals(t) {
t.plan( 4 );
pixel = new OpenLayers.Pixel(5,6);
px = new OpenLayers.Pixel(5,6);
t.eq( pixel.equals(px), true, "(5,6) equals (5,6)");
px = new OpenLayers.Pixel(1,6);
t.eq( pixel.equals(px), false, "(5,6) does not equal (1,6)");
px = new OpenLayers.Pixel(5,2);
t.eq( pixel.equals(px), false, "(5,6) does not equal (5,2)");
px = new OpenLayers.Pixel(1,2);
t.eq( pixel.equals(px), false, "(5,6) does not equal (1,2)");
}
function test_07_Pixel_add(t) {
t.plan( 4 );
oldPixel = new OpenLayers.Pixel(5,6);
pixel = oldPixel.add(10,20);
t.eq( oldPixel.x, 5, "oldPixel.x not modified by add operation");
t.eq( oldPixel.y, 6, "oldPixel.y not modified by add operation");
t.eq( pixel.x, 15, "pixel.x is set correctly");
t.eq( pixel.y, 26, "pixel.y is set correctly");
}
// -->
</script>

57
tests/test_Size.html Normal file
View File

@@ -0,0 +1,57 @@
<html>
<head>
<script src="../lib/OpenLayers.js"></script>
<script type="text/javascript"><!--
var Size;
function test_01_Size_constructor (t) {
t.plan( 4 );
size = new OpenLayers.Size(5,6);
t.ok( size instanceof OpenLayers.Size, "new OpenLayers.Size returns size object" );
t.eq( size.CLASS_NAME, "OpenLayers.Size", "size.CLASS_NAME is set correctly");
t.eq( size.w, 5, "size.w is set correctly");
t.eq( size.h, 6, "size.h is set correctly");
}
function test_02_Size_toString(t) {
t.plan( 1 );
size = new OpenLayers.Size(5,6);
t.eq( size.toString(), "w=5,h=6", "size.toString() returns correctly");
}
function test_03_Size_copyOf(t) {
t.plan( 4 );
oldSize = new OpenLayers.Size(5,6);
size = oldSize.copyOf();
t.ok( size instanceof OpenLayers.Size, "copyOf returns new OpenLayers.Size object" );
t.eq( size.w, 5, "Size.w is set correctly");
t.eq( size.h, 6, "Size.h is set correctly");
oldSize.w = 100;
t.eq( size.w, 5, "changing oldSize.w doesn't change size.w");
}
function test_04_Size_equals(t) {
t.plan( 4 );
size = new OpenLayers.Size(5,6);
sz = new OpenLayers.Size(5,6);
t.eq( size.equals(sz), true, "(5,6) equals (5,6)");
sz = new OpenLayers.Size(1,6);
t.eq( size.equals(sz), false, "(5,6) does not equal (1,6)");
sz = new OpenLayers.Size(5,2);
t.eq( size.equals(sz), false, "(5,6) does not equal (5,2)");
sz = new OpenLayers.Size(1,2);
t.eq( size.equals(sz), false, "(5,6) does not equal (1,2)");
}
// -->
</script>
</head>
<body>
</body>
</html>