Skip to content
Browse files

Added more tests

  • Loading branch information...
1 parent 3d2d0ff commit 4c560cbc7c1f1293dc7736204c85f121ea14a262 @manuelbieh committed
Showing with 98 additions and 5 deletions.
  1. +98 −5 tests/geolib.test.html
View
103 tests/geolib.test.html
@@ -12,7 +12,43 @@
<script>
$(function(){
- test("Calculating distance using getDistance()", function() {
+ var cities = {
+ "Berlin": {latitude: 52.518611, longitude: 13.408056},
+ "Boston": {latitude: 42.357778, longitude: "71° 3' 34\" W"},
+ "Dortmund": {latitude: "51° 31' 10.11\" N", longitude: "7° 28' 01\" E"},
+ "London": {latitude: "51° 31' N", longitude: "0° 7' W"},
+ "Manchester": {latitude: "53° 29' N", longitude: "2° 14' W"},
+ "New York City": {latitude: 40.715517, longitude: -73.9991},
+ "San Francisco": {latitude: 37.774514, longitude: -122.418079},
+ "Moscow": {latitude: 55.751667, longitude: 37.617778}
+ }
+
+ var polygon = [{"latitude": 51.513357512, "longitude": 7.45574331},
+ {"latitude": 51.515400598, "longitude": 7.45518541},
+ {"latitude": 51.516241842, "longitude": 7.456494328},
+ {"latitude": 51.516722545, "longitude": 7.459863183},
+ {"latitude": 51.517443592, "longitude": 7.463232037},
+ {"latitude": 51.5177507, "longitude": 7.464755532},
+ {"latitude": 51.517657233, "longitude": 7.466622349},
+ {"latitude": 51.51722995, "longitude": 7.468317505},
+ {"latitude": 51.516816015, "longitude": 7.47011995},
+ {"latitude": 51.516308606, "longitude": 7.471793648},
+ {"latitude": 51.515974782, "longitude": 7.472437378},
+ {"latitude": 51.515413951, "longitude": 7.472845074},
+ {"latitude": 51.514559338, "longitude": 7.472909447},
+ {"latitude": 51.512195717, "longitude": 7.472651955},
+ {"latitude": 51.511127373, "longitude": 7.47140741},
+ {"latitude": 51.51029939, "longitude": 7.469948288},
+ {"latitude": 51.509831973, "longitude": 7.468446251},
+ {"latitude": 51.509978876, "longitude": 7.462481019},
+ {"latitude": 51.510913701, "longitude": 7.460678574},
+ {"latitude": 51.511594777, "longitude": 7.459434029},
+ {"latitude": 51.512396029, "longitude": 7.457695958},
+ {"latitude": 51.513317451, "longitude": 7.45574331}
+ ];
+
+
+ test("Testing distance calculation: getDistance()", function() {
expect(3);
@@ -26,7 +62,7 @@
});
- test("Calculating distance using getDistanceSimple()", function() {
+ test("Testing distance calculation: getDistanceSimple()", function() {
expect(3);
@@ -40,7 +76,7 @@
});
- test("Conversion from sexagesimal to decimal", function() {
+ test("Testing conversion: sexagesimal2decimal()", function() {
expect(7);
@@ -62,7 +98,7 @@
});
- test("Conversion from decimal to sexagesimal", function() {
+ test("Testing conversion: decimal2sexagesimal()", function() {
expect(2);
var sexa1 = geolib.decimal2sexagesimal(51.519475);
@@ -73,7 +109,7 @@
});
- test("Testing compass direction", function() {
+ test("Testing: getCompassDirection()", function() {
expect(2);
var dir1 = geolib.getCompassDirection({latitude: 52.518611, longitude: 13.408056}, {latitude: 51.519475, longitude: 7.46694444});
@@ -83,6 +119,63 @@
});
+
+ test("Testing: findNearest()", function() {
+
+ expect(4);
+ var near1 = geolib.findNearest({latitude: 36.1168, longitude: -115.173798}, cities);
+
+ equal(near1.key, 'San Francisco', 'Nearest city to Las Vegas from predefined set should be San Francisco');
+ equal(near1.distance, 670788, 'Distance should be 670788');
+ equal(near1.latitude, 37.774514, 'Latitude should be 37.774514');
+ equal(near1.longitude, -122.418079, 'Latitude should be -122.418079');
+
+ });
+
+ test("Testing: getPathLength()", function() {
+
+ var pathLength = geolib.getPathLength(polygon);
+ equal(pathLength, 3377, 'Path length should be 3377');
+
+ });
+
+ test("Testing: isPointInside()", function() {
+
+ var isInside1 = geolib.isPointInside({latitude: 51.514252208, longitude: 7.464905736}, polygon); // Point is inside of the polygon
+ var isInside2 = geolib.isPointInside({latitude: 51.510539773, longitude: 7.454691884}, polygon); // Point is not inside polygon
+
+ ok(isInside1, "Point 1 is inside polygon");
+ ok(!isInside2, "Point 2 is not inside polygon");
+
+ });
+
+ test("Testing: convertUnit()", function() {
+
+ equal(geolib.convertUnit('km', 1000), 1, 'Conversion of 1000 m to km');
+ equal(geolib.convertUnit('m', 1000), 1000, 'Conversion of 1000 m to m (just to make sure)');
+ equal(geolib.convertUnit('cm', 1000), 100000, 'Conversion of 1000 m to cm');
+ equal(geolib.convertUnit('mm', 1000), 1000000, 'Conversion of 1000 m to mm');
+ equal(geolib.convertUnit('mi', 1000), 0.6214, 'Conversion of 1000 m to miles');
+ equal(geolib.convertUnit('sm', 1000), 0.5399, 'Conversion of 1000 m to seamiles');
+ equal(geolib.convertUnit('ft', 1000), 3280.8399, 'Conversion of 1000 m to ft');
+ equal(geolib.convertUnit('in', 1000), 39370.0787, 'Conversion of 1000 m to in');
+ equal(geolib.convertUnit('yd', 1000), 1093.6133, 'Conversion of 1000 m to yd');
+
+ });
+
+ test("Testing: isSexagesimal()", function() {
+
+ ok(geolib.isSexagesimal('51° 31\''), '51° 31\'');
+ ok(geolib.isSexagesimal('51° 31\' 12"'), '51° 31\' 12"');
+ ok(geolib.isSexagesimal('51° 31\' 12.27"'), '51° 31\' 12.27"');
+ ok(geolib.isSexagesimal('51° 31\' 12.27" N'), '51° 31\' 12.27" N');
+ ok(geolib.isSexagesimal('51° 31\' N'), '51° 31\' N');
+ //ok(geolib.isSexagesimal('51° N'), '51°'); // coming soon
+
+ });
+
+
+
});
</script>

0 comments on commit 4c560cb

Please sign in to comment.
Something went wrong with that request. Please try again.