Sha256: 42c3d48ce1a5752f09ae4d4a61afdf5f94582811dd0c696d1c4d6dbd4a12f66f

Contents?: true

Size: 1.71 KB

Versions: 18

Compression:

Stored size: 1.71 KB

Contents

// ==========================================================================
// Project:   SproutCore - JavaScript Application Framework
// Copyright: ©2006-2010 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

18 entries across 18 versions & 2 rubygems

Version Path
spade-0.0.1 sproutcore/frameworks/foundation/tests/system/math.js
sproutcore-1.5.0.pre.5 lib/frameworks/sproutcore/frameworks/foundation/tests/system/math.js
sproutcore-1.5.0.pre.4.1 lib/frameworks/sproutcore/frameworks/foundation/tests/system/math.js
sproutcore-1.5.0.pre.4 lib/frameworks/sproutcore/frameworks/foundation/tests/system/math.js
sproutcore-1.5.0.pre.3 lib/frameworks/sproutcore/frameworks/foundation/tests/system/math.js
sproutcore-1.4.5 lib/frameworks/sproutcore/frameworks/foundation/tests/system/math.js
sproutcore-1.4.5-java lib/frameworks/sproutcore/frameworks/foundation/tests/system/math.js
sproutcore-1.4.4-java lib/frameworks/sproutcore/frameworks/foundation/tests/system/math.js
sproutcore-1.4.4 lib/frameworks/sproutcore/frameworks/foundation/tests/system/math.js
sproutcore-1.4.3.1 lib/frameworks/sproutcore/frameworks/foundation/tests/system/math.js
sproutcore-1.4.3-java lib/frameworks/sproutcore/frameworks/foundation/tests/system/math.js
sproutcore-1.4.3 lib/frameworks/sproutcore/frameworks/foundation/tests/system/math.js
sproutcore-1.4.2-java lib/frameworks/sproutcore/frameworks/foundation/tests/system/math.js
sproutcore-1.4.2 lib/frameworks/sproutcore/frameworks/foundation/tests/system/math.js
sproutcore-1.4.1-java lib/frameworks/sproutcore/frameworks/foundation/tests/system/math.js
sproutcore-1.4.1 lib/frameworks/sproutcore/frameworks/foundation/tests/system/math.js
sproutcore-1.4.0-java lib/frameworks/sproutcore/frameworks/foundation/tests/system/math.js
sproutcore-1.4.0 lib/frameworks/sproutcore/frameworks/foundation/tests/system/math.js