Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added final tests

  • Loading branch information...
commit c1f3743d3e11188774717c3f50b4033724ef8af4 1 parent 4a5bc5b
@captainAnderman captainAnderman authored
View
18 geolib.js
@@ -654,7 +654,7 @@
};
var elevationService = new google.maps.ElevationService();
elevationService.getElevationAlongPath(positionalRequest,function (results, status){
- this.geolib.elevationHandler(results,status,cb)
+ geolib.elevationHandler(results,status,cb);
});
},
@@ -675,19 +675,19 @@
path.push(geolib.useDecimal(coords[i][latitude]) + ',' +
geolib.useDecimal(coords[i][longitude]));
}
- gm.elevationFromPath(path.join('|'), path.length, function(results, status) {
- geolib.elevationHandler(results, status, cb)
+ gm.elevationFromPath(path.join('|'), path.length, function(err, results) {
+ geolib.elevationHandler(results.results, results.status, cb)
});
},
- elevationHandler: function(err, elevationResult, cb){
+ elevationHandler: function(results, status, cb){
var latsLngsElevs = [];
- if (elevationResult.status == "OK" ) {
- for (var i = 0; i < elevationResult.results.length; i++) {
+ if (status == "OK" ) {
+ for (var i = 0; i < results.length; i++) {
latsLngsElevs.push({
- "lat":elevationResult.results[i].location.lat,
- "lng":elevationResult.results[i].location.lng,
- "elev":elevationResult.results[i].elevation
+ "lat":results[i].location.lat,
+ "lng":results[i].location.lng,
+ "elev":results[i].elevation
});
}
cb(null, latsLngsElevs);
View
3  package.json
@@ -15,6 +15,9 @@
"dependencies": {
"googlemaps": ">= 0.1.6"
},
+ "devDependencies": {
+ "mocha": "*"
+ },
"files": ["geolib.js"],
"description": "Growing library to perform geo specific tasks",
"keywords": ["geolocation", "geo", "distance"],
View
73 tests/geolib.test.html
@@ -5,6 +5,8 @@
<meta charset="utf-8">
<script src="http://code.jquery.com/jquery-latest.js"></script>
+ <!-- script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=AIzaSyDxikL7zFrgea3gBya8OECSsOgvKuuFLb8&sensor=true"></script-->
+ <script type="text/javascript" src='http://maps.googleapis.com/maps/api/js?sensor=true'></script>
<script type="text/javascript" src="http://code.jquery.com/qunit/git/qunit.js"></script>
<script type="text/javascript" src="../geolib.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/qunit/git/qunit.css" type="text/css" media="screen" />
@@ -105,6 +107,77 @@
equal(box.minElev, 521.12, "minElev should be 521.12");
});
+ asyncTest("Testing elevation: getElevation()", function() {
+ expect(4);
+
+ var latsLngsElevs;
+ var coords1 = [{"lat":33.76346,"lng":-84.43430000000001},
+ {"lat":33.76418,"lng":-84.42999999999995}];
+ var coords2 = [{"lat":41.73549,"lng":-111.85842000000002},
+ {"lat":41.73600999999999,"lng":-111.85572000000002}];
+
+ var doneCount = 0;
+ var done = function (){
+ ++doneCount;
+ if (doneCount === 2) {
+ start();
+ }
+ };
+
+ geolib.getElevation(coords1,function(err, results){
+ if (err) {
+ throw err;
+ }
+ latsLngsElevs = results;
+ equal(latsLngsElevs[0].elev, 297.8508605957031, "1st elev should be 297.8508605957031");
+ equal(latsLngsElevs[1].elev, 281.1884155273438, "2nd elev should be 281.1884155273438");
+ done();
+ });
+
+ geolib.getElevation(coords2,function(err, results){
+ if (err) {
+ throw err;
+ }
+ latsLngsElevs = results;
+ equal(latsLngsElevs[0].elev, 1358.223999023438, "1st elev should be 1358.223999023438");
+ equal(latsLngsElevs[1].elev, 1360.70654296875, "2nd elev should be 1360.70654296875");
+ done();
+ });
+
+ });
+
+ test("Testing grade: getGrade()", function() {
+ expect(2);
+ var coords1 = [{"lat":41.72977,"lng":-111.77621999999997,"elev":1702.72412109375},
+ {"lat":41.73198,"lng":-111.77636999999999,"elev":1849.7333984375}];
+ var coords2 = [{"lat":40.75402,"lng":-111.75475,"elev":2209.137451171875},
+ {"lat":40.76481,"lng":-111.76778999999999,"elev":1660.49609375}];
+
+ var grade = geolib.getGrade(coords1);
+ equal(grade, 51, "grade should be 51");
+
+ grade = geolib.getGrade(coords2);
+ equal(grade, 31, "grade should be 31");
+ });
+
+ test("Testing elevation gain and loss: getTotalElevationGainAndLoss()", function() {
+ expect(4);
+ var coords1 = [{"lat":41.72975,"lng":-111.77580999999998,"elev":1707.123046875},
+ {"lat":41.73298475750587,"lng":-111.77603699785413,"elev":1922.056396484375},
+ {"lat":41.73517,"lng":-111.77881000000002,"elev":1893.9931640625}];
+ var coords2 = [{"lat":40.79162,"lng":-111.76560999999998,"elev":2211.202880859375},
+ {"lat":40.79938945887229,"lng":-111.76680525603354,"elev":1995.89990234375},
+ {"lat":40.80354,"lng":-111.77384999999998,"elev":1978.573120117188}];
+
+ var gainAndLoss = geolib.getTotalElevationGainAndLoss(coords1);
+ equal(gainAndLoss.gain, 214.933349609375, "gain should be 214.933349609375");
+ equal(gainAndLoss.loss, 28.063232421875, "loss should be 28.063232421875");
+
+ gainAndLoss = geolib.getTotalElevationGainAndLoss(coords2);
+ equal(gainAndLoss.gain, 0, "gain should be 0");
+ equal(gainAndLoss.loss, 232.62976074218705, "loss should be 232.62976074218705");
+ });
+
test("Testing conversion: sexagesimal2decimal()", function() {
expect(7);
View
24 tests/getElevationServer.js
@@ -0,0 +1,24 @@
+var util = require('util')
+ , http = require('http')
+ , geolib = require('geolib');
+
+describe('Geolib', function() {
+ describe('getElevationServer', function() {
+ it('should getElevation for three points', function(done) {
+ var coords = [
+ {"lat":40.79162,"lng":-111.76560999999998},
+ {"lat":40.79938945887229,"lng":-111.76680525603354},
+ {"lat":40.80354,"lng":-111.77384999999998}
+ ];
+ geolib.getElevation(coords, function (err, result){
+ if (err){
+ throw new Error("Could not getelevation");
+ } else {
+ Math.floor(results[0].elev).should.be.equal(2211);
+ Math.floor(results[1].elev).should.be.equal(1995);
+ Math.floor(results[2].elev).should.be.equal(1978);
+ }
+ });
+ });
+ });
+});
Please sign in to comment.
Something went wrong with that request. Please try again.