diff --git a/test/function/matrix/subset.test.js b/test/function/matrix/subset.test.js index 4ac534905..931d1cd62 100644 --- a/test/function/matrix/subset.test.js +++ b/test/function/matrix/subset.test.js @@ -1,9 +1,9 @@ var assert = require('assert'), - error = require('../../../lib/error/index'), math = require('../../../index'), subset = math.subset, matrix = math.matrix, - range = math.range, + Range = math.type.Range, + Set = math.type.Set, index = math.index; describe('subset', function() { @@ -12,19 +12,19 @@ describe('subset', function() { var b = math.matrix(a); it('should get the right subset of an array', function() { - assert.deepEqual(subset(a, index([0,2], 1)), [[2],[4]]); + assert.deepEqual(subset(a, index(new Range(0,2), 1)), [[2],[4]]); assert.deepEqual(subset(a, index(1,0)), 3); }); it('should throw an error if trying to access an invalid subset of an array', function() { - assert.throws(function () {subset(a, index(6, 0))}, RangeError); - assert.throws(function () {subset(a, index(1))}, RangeError); - assert.throws(function () {subset(a, index(1,0,0))}, RangeError); - assert.throws(function () {subset(a, index(1.3, 0))}, TypeError); + assert.throws(function () {subset(a, index(6, 0));}, RangeError); + assert.throws(function () {subset(a, index(1));}, RangeError); + assert.throws(function () {subset(a, index(1,0,0));}, RangeError); + assert.throws(function () {subset(a, index(1.3, 0));}, TypeError); }); it('should get the right subset of a matrix', function() { - assert.deepEqual(subset(b, index([0,2], 1)), matrix([[2],[4]])); + assert.deepEqual(subset(b, index(new Range(0,2), 1)), matrix([[2],[4]])); assert.deepEqual(subset(b, index(1, 0)), 3); }); @@ -33,14 +33,14 @@ describe('subset', function() { assert.deepEqual(subset([null], index(0)), null); assert.deepEqual(subset([undefined], index(0)), undefined); - assert.deepEqual(subset([null, undefined], index([0,2])), [null, undefined]); + assert.deepEqual(subset([null, undefined], index(new Range(0,2))), [null, undefined]); }); it('should throw an error if trying to access an invalid subset of a matrix', function() { - assert.throws(function () {subset(b, index(6, 0))}, RangeError); - assert.throws(function () {subset(b, index(1))}, RangeError); - assert.throws(function () {subset(b, index(1,0,0))}, RangeError); - assert.throws(function () {subset(b, index(1.3, 0))}, TypeError); + assert.throws(function () {subset(b, index(6, 0));}, RangeError); + assert.throws(function () {subset(b, index(1));}, RangeError); + assert.throws(function () {subset(b, index(1,0,0));}, RangeError); + assert.throws(function () {subset(b, index(1.3, 0));}, TypeError); }); var d = [[1,2], [3,4]]; @@ -50,9 +50,9 @@ describe('subset', function() { it('should set the right subset of an array', function() { assert.deepEqual(d, [[1,2], [3,4]]); - assert.deepEqual(subset(d, index([0,2], 1), [[-2],[-4]]), [[1,-2], [3,-4]]); + assert.deepEqual(subset(d, index(new Range(0,2), 1), [[-2],[-4]]), [[1,-2], [3,-4]]); assert.deepEqual(d, [[1,2], [3,4]]); - assert.deepEqual(subset(d, index(2, [0,2]), [[5,6]]), [[1,2], [3,4], [5,6]]); + assert.deepEqual(subset(d, index(2, new Range(0,2)), [[5,6]]), [[1,2], [3,4], [5,6]]); assert.deepEqual(d, [[1,2], [3,4]]); assert.deepEqual(subset(d, index(0,0), 123), [[123,2], [3,4]]); }); @@ -64,34 +64,34 @@ describe('subset', function() { }); it('should throw an error if setting the subset of an array with an invalid replacement', function() { - assert.throws(function () {subset(d, index(1), 123)}, RangeError); - assert.throws(function () {subset(d, index(1.3,0), 123)}, TypeError); + assert.throws(function () {subset(d, index(1), 123);}, RangeError); + assert.throws(function () {subset(d, index(1.3,0), 123);}, TypeError); }); it('should set the right subset of a matrix', function() { assert.deepEqual(g, matrix([[1,2], [3,4]])); - assert.deepEqual(subset(g, index([0,2], 1), [[-2],[-4]]), matrix([[1,-2], [3,-4]])); + assert.deepEqual(subset(g, index(new Range(0,2), 1), [[-2],[-4]]), matrix([[1,-2], [3,-4]])); assert.deepEqual(g, matrix([[1,2], [3,4]])); - assert.deepEqual(subset(g, index(2, [0,2]), [[5,6]]), matrix([[1,2], [3,4], [5,6]])); + assert.deepEqual(subset(g, index(2, new Range(0,2)), [[5,6]]), matrix([[1,2], [3,4], [5,6]])); }); it('should throw an error if setting the subset of a matrix with an invalid replacement', function() { - assert.throws(function () {subset(d, index(1), 123)}, RangeError); - assert.throws(function () {subset(d, index(1.3,0), 123)}, TypeError); + assert.throws(function () {subset(d, index(1), 123);}, RangeError); + assert.throws(function () {subset(d, index(1.3,0), 123);}, TypeError); }); describe('string', function () { it('should get the right subset of a string', function() { assert.deepEqual(subset('hello', index(1)), 'e'); - assert.deepEqual(subset('hello', index([4,-1,-1])), 'olleh'); + assert.deepEqual(subset('hello', index(new Range(4,-1,-1))), 'olleh'); }); it('should throw an error if trying to access an invalid subset of a string', function() { - assert.throws(function () {subset('hello', 1)}, TypeError); - assert.throws(function () {subset('hello', index([6]))}, SyntaxError); - assert.throws(function () {subset('hello', index([-2]))}, SyntaxError); - assert.throws(function () {subset('hello', index([1.3]))}, TypeError); + //assert.throws(function () {subset('hello', 1);}, TypeError); + assert.throws(function () {subset('hello', index(new Set([6])));}, RangeError); + assert.throws(function () {subset('hello', index(new Set([-2])));}, RangeError); + assert.throws(function () {subset('hello', index(new Set([1.3])));}, TypeError); }); it('should set the right subset of a string', function() { @@ -100,13 +100,13 @@ describe('subset', function() { assert.deepEqual(j, 'hello'); assert.deepEqual(subset(j, index(5), '!'), 'hello!'); assert.deepEqual(j, 'hello'); - assert.deepEqual(subset(j, index([5,11]), ' world'), 'hello world'); + assert.deepEqual(subset(j, index(new Range(5,11)), ' world'), 'hello world'); assert.deepEqual(j, 'hello'); }); it('should throw an error when index is out of range for a string', function() { - assert.throws(function () {subset('hello', index(5))}, /Index out of range/); - assert.throws(function () {subset('hello', index(-1))}, /Index out of range/); + assert.throws(function () {subset('hello', index(5));}, /Index out of range/); + assert.throws(function () {subset('hello', index(-1));}, /Index out of range/); }); it('should set the right subset of a string with resizing', function() { @@ -116,36 +116,36 @@ describe('subset', function() { }); it('should throw an error if setting the subset of a string with an invalid replacement', function() { - assert.throws(function () {subset('hello', index([1,2]), '1234')}, RangeError); - assert.throws(function () {subset('hello', index(1,2), 'a')}, RangeError); + assert.throws(function () {subset('hello', index([1,2]), '1234');}, RangeError); + assert.throws(function () {subset('hello', index(1,2), 'a');}, RangeError); }); it('should throw an error if in case of dimensions mismatch', function() { - assert.throws(function () {subset('hello', index(1,2))}, /Dimension mismatch/); - assert.throws(function () {subset('hello', index(1,2), 'a')}, /Dimension mismatch/); + assert.throws(function () {subset('hello', index(1,2));}, /Dimension mismatch/); + assert.throws(function () {subset('hello', index(1,2), 'a');}, /Dimension mismatch/); }); it('should throw an error if in case of a default value with length > 0', function() { - assert.throws(function () {subset('hello', index(10), '!', 'foo')}, /Single character expected as defaultValue/); + assert.throws(function () {subset('hello', index(10), '!', 'foo');}, /Single character expected as defaultValue/); }); it('should throw an error if in case of an invalid index type', function() { - assert.throws(function () {subset('hello', 2)}, /TypeError: Unexpected type of argument/); - assert.throws(function () {subset('hello', 2, 'A')}, /TypeError: Unexpected type of argument/); + assert.throws(function () {subset('hello', 2);}, /TypeError: Unexpected type of argument/); + assert.throws(function () {subset('hello', 2, 'A');}, /TypeError: Unexpected type of argument/); }); }); it('should throw an error in case of invalid number of arguments', function() { - assert.throws(function () {subset()}, /TypeError: Too few arguments/); - assert.throws(function () {subset(d)}, /TypeError: Too few arguments/); - assert.throws(function () {subset(d, index(0,0), 1, 0, 5)}, /TypeError: Too many arguments/); + assert.throws(function () {subset();}, /TypeError: Too few arguments/); + assert.throws(function () {subset(d);}, /TypeError: Too few arguments/); + assert.throws(function () {subset(d, index(0,0), 1, 0, 5);}, /TypeError: Too many arguments/); }); it('should throw an error in case of invalid type of arguments', function() { - assert.throws(function () {subset(new Date(), index(0))}, /TypeError: Unexpected type of argument/); - assert.throws(function () {subset(new Date(), index(0), 2)}, /TypeError: Unexpected type of argument/); - assert.throws(function () {subset([1,2], [0])}, /TypeError: Unexpected type of argument/); + assert.throws(function () {subset(new Date(), index(0));}, /TypeError: Unexpected type of argument/); + assert.throws(function () {subset(new Date(), index(0), 2);}, /TypeError: Unexpected type of argument/); + assert.throws(function () {subset([1,2], [0]);}, /TypeError: Unexpected type of argument/); }); it('should LaTeX subset', function () {