1 module('measure tool') 2 3 test("unit conversions", 22, function(){ 4 measureTool = new madrona.measureTool() 5 6 // metric tests 7 measureTool.setUnits('metric'); 8 9 test_vals = measureTool.convertMetricValue( 'area', 1 ); 10 equals(test_vals[0], 1); 11 equals(test_vals[1], 'sq m'); 12 13 test_vals = measureTool.convertMetricValue( 'distance', 1 ); 14 equals(test_vals[0], 1); 15 equals(test_vals[1], 'm'); 16 17 test_vals = measureTool.convertMetricValue( 'area', 1000000 ); 18 equals(test_vals[0], 1); 19 equals(test_vals[1], 'sq km'); 20 21 test_vals = measureTool.convertMetricValue( 'distance', 1000 ); 22 equals(test_vals[0], 1); 23 equals(test_vals[1], 'km'); 24 25 // english tests 26 measureTool.setUnits('english'); 27 28 test_vals = measureTool.convertMetricValue( 'area', 1000 ); 29 equals(test_vals[0], 10763.9104 ); 30 equals(test_vals[1], 'sq ft' ); 31 32 test_vals = measureTool.convertMetricValue( 'area', 1000000 ); 33 equals(test_vals[0], 0.386102159 ); 34 equals(test_vals[1], 'sq mi' ); 35 36 test_vals = measureTool.convertMetricValue( 'distance', 0.5 ); 37 equals(test_vals[0], 1.64041995 ); 38 equals(test_vals[1], 'ft' ); 39 40 test_vals = measureTool.convertMetricValue( 'distance', 1000 ); 41 equals(test_vals[0], 0.621371192 ); 42 equals(test_vals[1], 'mi' ); 43 44 // nautical tests 45 measureTool.setUnits('nautical'); 46 47 test_vals = measureTool.convertMetricValue( 'area', 1000000 ); 48 equals(test_vals[0], 0.29155335 ); 49 equals(test_vals[1], 'sq naut mi' ); 50 51 test_vals = measureTool.convertMetricValue( 'distance', 500 ); 52 equals(test_vals[0], 0.2699784015 ); 53 equals(test_vals[1], 'naut mi' ); 54 55 // error test 56 measureTool.setUnits('bogus'); 57 test_vals = measureTool.convertMetricValue( 'area', 1000000 ); 58 equals(test_vals[0], 0 ); 59 equals(test_vals[1], 'invalid units set' ); 60 });