jos 349e9845e8 Merge branch 'develop' into v2_merge
Conflicts:
	HISTORY.md
	bower.json
	component.json
	dist/math.js
	dist/math.map
	dist/math.min.js
	docs/reference/units.md
	lib/version.js
	package.json
	test/function/construction/chain.test.js
	test/function/matrix/det.test.js
	test/function/matrix/transpose.test.js
	test/function/utils/import.test.js
2015-04-13 21:42:43 +02:00

65 lines
2.1 KiB
JavaScript

// test cube
var assert = require('assert');
var math = require('../../../index');
var unit = math.unit;
var bignumber = math.bignumber;
var matrix = math.matrix;
var range = math.range;
var cube = math.cube;
describe('cube', function() {
it('should return the cube of a boolean', function () {
assert.equal(cube(true), 1);
assert.equal(cube(false), 0);
});
it('should return the cube of null', function () {
assert.equal(math.ceil(null), 0);
});
it('should return the cube of a number', function() {
assert.equal(cube(4), 64);
assert.equal(cube(-2), -8);
assert.equal(cube(0), 0);
});
it('should return the cube of a big number', function() {
assert.deepEqual(cube(bignumber(4)), bignumber(64));
assert.deepEqual(cube(bignumber(-2)), bignumber(-8));
assert.deepEqual(cube(bignumber(0)), bignumber(0));
});
it('should return the cube of a complex number', function() {
assert.deepEqual(cube(math.complex('2i')), math.complex('-8i'));
assert.deepEqual(cube(math.complex('2+3i')), math.complex('-46+9i'));
assert.deepEqual(cube(math.complex('2')), math.complex('8'));
});
it('should throw an error with strings', function() {
assert.throws(function () {cube('text')});
});
it('should throw an error with units', function() {
assert.throws(function () {cube(unit('5cm'))});
});
it('should throw an error if there\'s wrong number of args', function() {
assert.throws(function () {cube()}, /TypeError: Too few arguments/);
assert.throws(function () {cube(1, 2)}, /TypeError: Too many arguments/);
});
it('should cube each element in a matrix, array or range', function() {
// array, matrix, range
// arrays are evaluated element wise
assert.deepEqual(cube([2,3,4,5]), [8,27,64,125]);
assert.deepEqual(cube(matrix([2,3,4,5])), matrix([8,27,64,125]));
assert.deepEqual(cube(matrix([[1,2],[3,4]])), matrix([[1,8],[27,64]]));
});
it('should LaTeX cube', function () {
var expression = math.parse('cube(2)');
assert.equal(expression.toTex(), '\\left({2}\\right)^{3}');
});
});