Sha256: 7ee63a8cdc2141253f65b6f56fc4d56249ae434174f01f85930af8a26c13960b

Contents?: true

Size: 1.71 KB

Versions: 41

Compression:

Stored size: 1.71 KB

Contents

// ==========================================================================
// Project:   SproutCore - JavaScript Application Framework
// Copyright: ©2006-2011 Apple Inc. and contributors.
// License:   Licensed under MIT license (see license.js)
// ==========================================================================
/*global module test equals context ok same */

module('SC.Math');

test("0.12 rounded default decimal place", function() {
  equals(SC.Math.round(0.12), 0);
});

test("1.23456789 rounded into decimals", function() {
  equals(SC.Math.round(1.23456789), 1, "0 decimal places");
  equals(SC.Math.round(1.23456789, 1), 1.2, "1 decimal place");
  equals(SC.Math.round(1.23456789, 2), 1.23, "2 decimal places");
  equals(SC.Math.round(1.23456789, 3), 1.235, "3 decimal places");
  equals(SC.Math.round(1.23456789, 4), 1.2346, "4 decimal places");
  equals(SC.Math.round(1.23456789, 7), 1.2345679, "7 decimal places");
});

test("123456.7890 rounded into wholes", function() {
  equals(SC.Math.round(123456.7890), 123457, "0 places");
  equals(SC.Math.round(123456.7890, -1), 123460, "1 place");
  equals(SC.Math.round(123456.7890, -2), 123500, "2 places");
  equals(SC.Math.round(123456.7890, -3), 123000, "3 places");
  equals(SC.Math.round(123456.7890, -4), 120000, "4 places");
});

test("near", function() {
  ok(SC.Math.near(1, 1), "Equal numbers should be considered near -- obviously");
  ok(!SC.Math.near(2, 1), "Unequal whole numbers should not be near");
  ok(SC.Math.near(1.00000001, 1), "Numbers inside lambda range should be considered near");
});

test("near - custom lambda", function() {
  ok(SC.Math.near(2, 1, 1), "Lambda should define an inclusive range -- ie. 2 with lambda 1 is considered near 1");
});

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
sproutcore-1.11.0 lib/frameworks/sproutcore/frameworks/foundation/tests/system/math.js
sproutcore-1.11.0.rc3 lib/frameworks/sproutcore/frameworks/foundation/tests/system/math.js
sproutcore-1.11.0.rc2 lib/frameworks/sproutcore/frameworks/foundation/tests/system/math.js
sproutcore-1.11.0.rc1 lib/frameworks/sproutcore/frameworks/foundation/tests/system/math.js
sproutcore-1.10.3.1 lib/frameworks/sproutcore/frameworks/foundation/tests/system/math.js
sproutcore-1.10.2 lib/frameworks/sproutcore/frameworks/foundation/tests/system/math.js
sproutcore-1.10.1 lib/frameworks/sproutcore/frameworks/foundation/tests/system/math.js
sproutcore-1.10.0 lib/frameworks/sproutcore/frameworks/foundation/tests/system/math.js
sproutcore-1.10.0.rc.3 lib/frameworks/sproutcore/frameworks/foundation/tests/system/math.js
sproutcore-1.10.0.rc.2 lib/frameworks/sproutcore/frameworks/foundation/tests/system/math.js
sproutcore-1.10.0.rc.1 lib/frameworks/sproutcore/frameworks/foundation/tests/system/math.js
sproutcore-1.9.2 lib/frameworks/sproutcore/frameworks/foundation/tests/system/math.js
sproutcore-1.9.1 lib/frameworks/sproutcore/frameworks/foundation/tests/system/math.js
sproutcore-1.9.0 lib/frameworks/sproutcore/frameworks/foundation/tests/system/math.js
sproutcore-1.8.2.1 lib/frameworks/sproutcore/frameworks/foundation/tests/system/math.js
sproutcore-1.8.1 lib/frameworks/sproutcore/frameworks/foundation/tests/system/math.js
sproutcore-1.8.0 lib/frameworks/sproutcore/frameworks/foundation/tests/system/math.js
sproutcore-1.7.1.beta-java lib/frameworks/sproutcore/frameworks/foundation/tests/system/math.js
sproutcore-1.7.1.beta lib/frameworks/sproutcore/frameworks/foundation/tests/system/math.js
sproutcore-1.6.0.1-java lib/frameworks/sproutcore/frameworks/foundation/tests/system/math.js