Comparing version 1.0.0 to 1.0.1
14
index.js
@@ -7,3 +7,10 @@ /** | ||
function check(x) { | ||
if (typeof x !== 'number') { | ||
throw 'not a number!'; | ||
} | ||
} | ||
function sqr(x) { | ||
check(x); | ||
return x * x; | ||
@@ -13,2 +20,3 @@ } | ||
sqr.isSquare = function(y) { | ||
check(y); | ||
var x = Math.sqrt(y); | ||
@@ -19,6 +27,6 @@ return x === (x|0); | ||
sqr.nearest = function(y) { | ||
check(y); | ||
var x = Math.sqrt(y)|0, | ||
x0 = x|0, | ||
y1 = x0 * x0, | ||
y2 = (1 + x0)*(1 + x0); | ||
y1 = x * x, | ||
y2 = (1 + x) * (1 + x); | ||
return y - y1 > y2 - y ? y2 : y1; | ||
@@ -25,0 +33,0 @@ }; |
{ | ||
"name": "sqr", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Calculates the square of numbers, and checks if they're square numbers", | ||
@@ -18,3 +18,12 @@ "main": "index.js", | ||
"tape": "^4.2.2" | ||
} | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/claudiopro/sqr.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/claudiopro/sqr/issues" | ||
}, | ||
"homepage": "https://github.com/claudiopro/sqr#readme", | ||
"tonicExampleFilename": "tonicExample.js" | ||
} |
36
test.js
@@ -12,3 +12,3 @@ /** | ||
test('squares of integers', function (t) { | ||
test('sqr calculates squares of integers', function (t) { | ||
t.is(0, sqr(0)); | ||
@@ -21,3 +21,3 @@ t.is(4, sqr(2)); | ||
test('check squares of integers', function (t) { | ||
test('isSquare detects squares of integers', function (t) { | ||
t.true(isSquare(49)); | ||
@@ -42,3 +42,3 @@ t.true(isSquare(36)); | ||
test('nearest squares of integers', function (t) { | ||
test('nearest finds nearest squares of integers', function (t) { | ||
t.is(49, nearest(52)); | ||
@@ -68,1 +68,31 @@ t.is(36, nearest(39)); | ||
}); | ||
test('sqr throws if passed non numeric arguments', function (t) { | ||
t.throws(sqr.bind(null, 'a')); | ||
t.throws(sqr.bind(null, null)); | ||
t.throws(sqr.bind(null, undefined)); | ||
t.throws(sqr.bind(null, [])); | ||
t.throws(sqr.bind(null, {})); | ||
t.end(); | ||
}); | ||
test('isSquare throws if passed non numeric arguments', function (t) { | ||
t.throws(isSquare.bind(null, 'a')); | ||
t.throws(isSquare.bind(null, null)); | ||
t.throws(isSquare.bind(null, undefined)); | ||
t.throws(isSquare.bind(null, [])); | ||
t.throws(isSquare.bind(null, {})); | ||
t.end(); | ||
}); | ||
test('nearest throws if passed non numeric arguments', function (t) { | ||
t.throws(nearest.bind(null, 'a')); | ||
t.throws(nearest.bind(null, null)); | ||
t.throws(nearest.bind(null, undefined)); | ||
t.throws(nearest.bind(null, [])); | ||
t.throws(nearest.bind(null, {})); | ||
t.end(); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
5567
8
109
1
0
29
0