Files
openlayers/tests/test_LonLat.html

88 lines
2.8 KiB
HTML

<html>
<head>
<script src="../lib/OpenLayers.js"></script>
<script type="text/javascript"><!--
var lonlat;
function test_01_LonLat_constructor (t) {
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_clone(t) {
t.plan( 3 );
oldLonLat = new OpenLayers.LonLat(5,6);
lonlat = oldLonLat.clone();
t.ok( lonlat instanceof OpenLayers.LonLat, "clone returns new OpenLayers.LonLat object" );
t.ok( lonlat.equals(oldLonLat), "lonlat is set correctly");
oldLonLat.lon = 100;
t.eq( lonlat.lon, 5, "changing oldLonLat.lon doesn't change lonlat.lon");
}
function test_04_LonLat_add(t) {
t.plan( 2 );
lonlatA = new OpenLayers.LonLat(10,100);
addpx = lonlatA.add(5, 50);
var ll = new OpenLayers.LonLat(10,100);
t.ok( lonlatA.equals(ll), "lonlatA is not modified by add operation");
var ll = new OpenLayers.LonLat(15,150);
t.ok( addpx.equals(ll), "addpx is set correctly");
}
function test_06_LonLat_equals(t) {
t.plan( 5 );
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)");
t.ok( !lonlat.equals(null), "equals() returns false on comparison to null");
}
function test_07_LonLat_fromString(t) {
t.plan( 2 );
lonlat = OpenLayers.LonLat.fromString("6,5");
t.ok( lonlat instanceof OpenLayers.LonLat, "new OpenLayers.LonLat returns LonLat object" );
var ll = new OpenLayers.LonLat(6, 5);
t.ok( lonlat.equals(ll), "lonlat is set correctly");
}
// -->
</script>
</head>
<body>
</body>
</html>