From ea6bb033eb233385fbe1ea44f65b72087ad009ee Mon Sep 17 00:00:00 2001 From: Devan Patel Date: Mon, 27 Apr 2015 12:06:12 -0400 Subject: [PATCH] Renaming stirlingSecondKind to stirlingS2 + changing LaTeX to "\\mathrm{S}\\left(%0%,%1%\\right)" --- .../{stirlingSecondKind.js => stirlingS2.js} | 20 ++++----- lib/math.js | 2 +- lib/util/latex.js | 2 +- .../function/combinatorics/stirlingS2.test.js | 45 +++++++++++++++++++ .../combinatorics/stirlingSecondKind.js | 45 ------------------- 5 files changed, 57 insertions(+), 57 deletions(-) rename lib/function/combinatorics/{stirlingSecondKind.js => stirlingS2.js} (84%) create mode 100644 test/function/combinatorics/stirlingS2.test.js delete mode 100644 test/function/combinatorics/stirlingSecondKind.js diff --git a/lib/function/combinatorics/stirlingSecondKind.js b/lib/function/combinatorics/stirlingS2.js similarity index 84% rename from lib/function/combinatorics/stirlingSecondKind.js rename to lib/function/combinatorics/stirlingS2.js index e0bfc234e..d7c5c5619 100644 --- a/lib/function/combinatorics/stirlingSecondKind.js +++ b/lib/function/combinatorics/stirlingS2.js @@ -12,16 +12,16 @@ module.exports = function (math) { /** * The Stirling numbers of the second kind, counts the number of ways to partition a set of n labelled objects into k nonempty unlabelled subsets. - * stirlingSecondKind only take integer arguments. + * stirlingS2 only take integer arguments. * The following condition must be enforced: k <= n. * * Syntax: * - * math.stirlingSecondKind(n, k) + * math.stirlingS2(n, k) * * Examples: * - * math.stirlingSecondKind(5, 3); //returns 25 + * math.stirlingS2(5, 3); //returns 25 * * If n = k or k = 1, then s(n,k) = 1 * @@ -30,16 +30,16 @@ module.exports = function (math) { * @return {Number | BigNumber} S(n,k) */ - math.stirlingSecondKind = function stirlingSecondKind (n, k) { + math.stirlingS2 = function stirlingS2 (n, k) { var result = 0; var arity = arguments.length; if (arity != 2) { - throw new math.error.ArgumentsError('stirlingSecondKind', arguments.length, 2); + throw new math.error.ArgumentsError('stirlingS2', arguments.length, 2); } if (isNumber(n) && isNumber(k)) { if (!isInteger(n) || n < 0 || !isInteger(k) || k < 0) { - throw new TypeError('Positive integer value expected in function stirlingSecondKind'); + throw new TypeError('Positive integer value expected in function stirlingS2'); } if (k > n) { throw new TypeError('k must be less than or equal to n'); @@ -58,7 +58,7 @@ module.exports = function (math) { console.log("result: ", result) return result; } else { - throw new TypeError('Integer values are expected in stirlingSecondKind') + throw new TypeError('Integer values are expected in stirlingS2') } // if (n instanceof BigNumber) { @@ -67,10 +67,10 @@ module.exports = function (math) { // k = BigNumber.convert(k); // if (!(k instanceof BigNumber) || !isPositiveInteger(k)) { - // throw new TypeError('Positive integer value expected in function stirlingSecondKind'); + // throw new TypeError('Positive integer value expected in function stirlingS2'); // } // if (k.gt(n)) { - // throw new TypeError('k must be less than n in function stirlingSecondKind'); + // throw new TypeError('k must be less than n in function stirlingS2'); // } // result = new BigNumber(1); @@ -83,7 +83,7 @@ module.exports = function (math) { // } // return result; // } - // throw new math.error.UnsupportedTypeError('stirlingSecondKindg', math['typeof'](n)); + // throw new math.error.UnsupportedTypeError('stirlingS2g', math['typeof'](n)); }; diff --git a/lib/math.js b/lib/math.js index 336976212..b1c3f3934 100644 --- a/lib/math.js +++ b/lib/math.js @@ -269,7 +269,7 @@ function create (config) { require('./function/bitwise/rightLogShift')(math, _config); //functions - combinatorics - require('./function/combinatorics/stirlingSecondKind')(math, _config); + require('./function/combinatorics/stirlingS2')(math, _config); // functions - complex require('./function/complex/arg')(math, _config); diff --git a/lib/util/latex.js b/lib/util/latex.js index 42a732d5d..98bc967ac 100644 --- a/lib/util/latex.js +++ b/lib/util/latex.js @@ -168,7 +168,7 @@ var functions = { 're': '\\Re\\left\\lbrace%0%\\right\\rbrace', //combinatorics - 'stirlingSecondKind': '\S{%0%}{%1%}', + 'stirlingS2': '\\mathrm{S}\\left(%0%,%1%\\right)', //construction 'bignumber': { diff --git a/test/function/combinatorics/stirlingS2.test.js b/test/function/combinatorics/stirlingS2.test.js new file mode 100644 index 000000000..6472f15de --- /dev/null +++ b/test/function/combinatorics/stirlingS2.test.js @@ -0,0 +1,45 @@ +var assert = require('assert'), +error = require('../../../lib/error/index'), +math = require('../../../index'), +stirlingS2 = math.stirlingS2; + +describe('stirlingS2', function() { + + it('should calculate the number of ways to partition a set of n objects into k non-empty subsets', function() { + assert.equal(stirlingS2(5,3), 25); + assert.equal(stirlingS2(0,0), 1); + assert.equal(stirlingS2(8,7), 28); + }); + + // it('should calculate the stirlingS2 of n items taken k at a time with BigNumbers', function(){ + // assert.deepEqual(stirlingS2(math.bignumber(7), math.bignumber(5)),math.bignumber(140)); + // assert.deepEqual(stirlingS2(math.bignumber(10), math.bignumber(4)),math.bignumber(34105)); + // assert.deepEqual(stirlingS2(math.bignumber(8), math.bignumber(6)),math.bignumber(266)); + // }); + + // it('should calculate the combinations of n items taken k at a time with BigNumbers', function() { + // assert.deepEqual(combinations(math.bignumber(7), math.bignumber(5)), math.bignumber(21)); + // assert.deepEqual(combinations(math.bignumber(20), math.bignumber(15)), math.bignumber(15504)); + // assert.deepEqual(combinations(math.bignumber(63), math.bignumber(7)), math.bignumber(553270671)); + // assert.deepEqual(combinations(math.bignumber(25), math.bignumber(6)), math.bignumber(177100)); + // }); + +it('should not work with non-integer and negative input', function() { + assert.throws(function() {stirlingS2(0.5, 3)}, TypeError); + assert.throws(function() {stirlingS2(3, 5)}, TypeError); + // assert.throws(function() {stirlingS2(math.bignumber(3), math.bignumber(5))}, TypeError); + // assert.throws(function() {stirlingS2(math.bignumber(3.5), math.bignumber(-3))}, TypeError); + // assert.throws(function() {stirlingS2(math.bignumber(3.5), 1/3)}, TypeError); + }); + +it('should not work with the wrong number or type of arguments', function() { + assert.throws(function() {stirlingS2(5, 3, 2)}); + assert.throws(function() {stirlingS2(true, "hello world")}); +}); + +it('should LaTeX stirlingS2', function () { + var expression = math.parse('stirlingS2(3,2)'); + assert.equal(expression.toTex(), '\S{3}{2}'); +}); + +}); diff --git a/test/function/combinatorics/stirlingSecondKind.js b/test/function/combinatorics/stirlingSecondKind.js deleted file mode 100644 index c8f457ce6..000000000 --- a/test/function/combinatorics/stirlingSecondKind.js +++ /dev/null @@ -1,45 +0,0 @@ -var assert = require('assert'), -error = require('../../../lib/error/index'), -math = require('../../../index'), -stirlingSecondKind = math.stirlingSecondKind; - -describe('stirlingSecondKind', function() { - - it('should calculate the number of ways to partition a set of n objects into k non-empty subsets', function() { - assert.equal(stirlingSecondKind(5,3), 25); - assert.equal(stirlingSecondKind(0,0), 1); - assert.equal(stirlingSecondKind(8,7), 28); - }); - - // it('should calculate the stirlingSecondKind of n items taken k at a time with BigNumbers', function(){ - // assert.deepEqual(stirlingSecondKind(math.bignumber(7), math.bignumber(5)),math.bignumber(140)); - // assert.deepEqual(stirlingSecondKind(math.bignumber(10), math.bignumber(4)),math.bignumber(34105)); - // assert.deepEqual(stirlingSecondKind(math.bignumber(8), math.bignumber(6)),math.bignumber(266)); - // }); - - // it('should calculate the combinations of n items taken k at a time with BigNumbers', function() { - // assert.deepEqual(combinations(math.bignumber(7), math.bignumber(5)), math.bignumber(21)); - // assert.deepEqual(combinations(math.bignumber(20), math.bignumber(15)), math.bignumber(15504)); - // assert.deepEqual(combinations(math.bignumber(63), math.bignumber(7)), math.bignumber(553270671)); - // assert.deepEqual(combinations(math.bignumber(25), math.bignumber(6)), math.bignumber(177100)); - // }); - -it('should not work with non-integer and negative input', function() { - assert.throws(function() {stirlingSecondKind(0.5, 3)}, TypeError); - assert.throws(function() {stirlingSecondKind(3, 5)}, TypeError); - // assert.throws(function() {stirlingSecondKind(math.bignumber(3), math.bignumber(5))}, TypeError); - // assert.throws(function() {stirlingSecondKind(math.bignumber(3.5), math.bignumber(-3))}, TypeError); - // assert.throws(function() {stirlingSecondKind(math.bignumber(3.5), 1/3)}, TypeError); - }); - -it('should not work with the wrong number or type of arguments', function() { - assert.throws(function() {stirlingSecondKind(5, 3, 2)}); - assert.throws(function() {stirlingSecondKind(true, "hello world")}); -}); - -it('should LaTeX stirlingSecondKind', function () { - var expression = math.parse('stirlingSecondKind(3,2)'); - assert.equal(expression.toTex(), '\S{3}{2}'); -}); - -});