|
1 |
| -/* global describe, it */ |
2 | 1 | 'use strict';
|
3 | 2 |
|
4 | 3 | var ndarray = require('ndarray');
|
5 | 4 | var ndt = require('ndarray-tests');
|
6 | 5 | var linspace = require('../');
|
7 |
| -var assert = require('chai').assert; |
8 |
| -// var show = require('ndarray-show'); |
| 6 | +var test = require('tape'); |
9 | 7 |
|
10 |
| -describe('linspace', function () { |
11 |
| - describe('failure modes', function () { |
12 |
| - it('fails if the first argument is not a ndarray', function () { |
13 |
| - assert.throws(function () { |
14 |
| - linspace(0, 10); |
15 |
| - }, Error, /must be a ndarray/); |
16 |
| - }); |
| 8 | +test('fails if the first argument is not a ndarray', function (t) { |
| 9 | + t.throws(function () { |
| 10 | + linspace(0, 10); |
| 11 | + }, Error, /must be a ndarray/); |
| 12 | + t.end(); |
| 13 | +}); |
17 | 14 |
|
18 |
| - it('throws an error if the axis not a number', function () { |
19 |
| - assert.throws(function () { |
20 |
| - linspace(ndarray([], [2, 2]), 0, 1, {axis: '4'}); |
21 |
| - }, Error, 'Axis must be a nonegative integer'); |
22 |
| - }); |
| 15 | +test('throws an error if the axis not a number', function (t) { |
| 16 | + t.throws(function () { |
| 17 | + linspace(ndarray([], [2, 2]), 0, 1, {axis: '4'}); |
| 18 | + }, Error, 'Axis must be a nonegative integer'); |
| 19 | + t.end(); |
| 20 | +}); |
23 | 21 |
|
24 |
| - it('throws an error if the axis is greater than the dimension', function () { |
25 |
| - assert.throws(function () { |
26 |
| - linspace(ndarray([], [2, 2]), 0, 1, {axis: 4}); |
27 |
| - }, Error, 'must be <= dimension'); |
28 |
| - }); |
| 22 | +test('throws an error if the axis is greater than the dimension', function (t) { |
| 23 | + t.throws(function () { |
| 24 | + linspace(ndarray([], [2, 2]), 0, 1, {axis: 4}); |
| 25 | + }, Error, 'must be <= dimension'); |
| 26 | + t.end(); |
| 27 | +}); |
29 | 28 |
|
30 |
| - it('fails if the endpoint is not a boolean', function () { |
31 |
| - assert.throws(function () { |
32 |
| - linspace(ndarray([], [1]), 0, 10, {endpoint: 7}); |
33 |
| - }, Error, /must be a boolean/); |
34 |
| - }); |
35 |
| - }); |
| 29 | +test('fails if the endpoint is not a boolean', function (t) { |
| 30 | + t.throws(function () { |
| 31 | + linspace(ndarray([], [1]), 0, 10, {endpoint: 7}); |
| 32 | + }, Error, /must be a boolean/); |
| 33 | + t.end(); |
| 34 | +}); |
36 | 35 |
|
37 |
| - it('create a new linspace with an endpoint', function () { |
38 |
| - var x = linspace(ndarray([], [11]), 0, 10); |
39 |
| - var y = ndarray([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); |
40 |
| - assert(ndt.equal(x, y, 1e-8)); |
41 |
| - }); |
| 36 | +test('create a new linspace with an endpoint', function (t) { |
| 37 | + var x = linspace(ndarray([], [11]), 0, 10); |
| 38 | + var y = ndarray([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); |
| 39 | + t.assert(ndt.equal(x, y, 1e-8)); |
| 40 | + t.end(); |
| 41 | +}); |
42 | 42 |
|
43 |
| - it('create a new linspace without an endpoint', function () { |
44 |
| - var x = linspace(ndarray([], [10]), 0, 10, {endpoint: false}); |
45 |
| - var y = ndarray([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); |
46 |
| - assert(ndt.equal(x, y, 1e-8)); |
47 |
| - }); |
| 43 | +test('create a new linspace without an endpoint', function (t) { |
| 44 | + var x = linspace(ndarray([], [10]), 0, 10, {endpoint: false}); |
| 45 | + var y = ndarray([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); |
| 46 | + t.assert(ndt.equal(x, y, 1e-8)); |
| 47 | + t.end(); |
| 48 | +}); |
48 | 49 |
|
49 |
| - it('fills in more than one dimension', function () { |
50 |
| - var x = linspace(ndarray([], [2, 2]), 0, 1); |
51 |
| - var y = ndarray([0, 0, 1, 1], [2, 2]); |
52 |
| - assert(ndt.equal(x, y, 1e-8)); |
53 |
| - }); |
| 50 | +test('fills in more than one dimension', function (t) { |
| 51 | + var x = linspace(ndarray([], [2, 2]), 0, 1); |
| 52 | + var y = ndarray([0, 0, 1, 1], [2, 2]); |
| 53 | + t.assert(ndt.equal(x, y, 1e-8)); |
| 54 | + t.end(); |
| 55 | +}); |
54 | 56 |
|
55 |
| - it('accepts a different axis', function () { |
56 |
| - var x = linspace(ndarray([], [2, 2]), 0, 1, {axis: 1}); |
57 |
| - var y = ndarray([0, 1, 0, 1], [2, 2]); |
58 |
| - assert(ndt.equal(x, y, 1e-8)); |
59 |
| - }); |
| 57 | +test('accepts a different axis', function (t) { |
| 58 | + var x = linspace(ndarray([], [2, 2]), 0, 1, {axis: 1}); |
| 59 | + var y = ndarray([0, 1, 0, 1], [2, 2]); |
| 60 | + t.assert(ndt.equal(x, y, 1e-8)); |
| 61 | + t.end(); |
| 62 | +}); |
60 | 63 |
|
61 |
| - it('uses the first point if only one point requested and endpoint = true', function () { |
62 |
| - var x = linspace(ndarray([], [1]), 1, 2, {endpoint: true}); |
63 |
| - var y = ndarray([1], [1]); |
64 |
| - assert(ndt.equal(x, y)); |
65 |
| - }); |
| 64 | +test('uses the first point if only one point requested an endpoint = true', function (t) { |
| 65 | + var x = linspace(ndarray([], [1]), 1, 2, {endpoint: true}); |
| 66 | + var y = ndarray([1], [1]); |
| 67 | + t.assert(ndt.equal(x, y)); |
| 68 | + t.end(); |
| 69 | +}); |
66 | 70 |
|
67 |
| - it('uses the first point if only one point requested and endpoint = false', function () { |
68 |
| - var x = linspace(ndarray([], [1]), 1, 2, {endpoint: false}); |
69 |
| - var y = ndarray([1], [1]); |
70 |
| - assert(ndt.equal(x, y)); |
71 |
| - }); |
| 71 | +test('uses the first point if only one point requested an endpoint = false', function (t) { |
| 72 | + var x = linspace(ndarray([], [1]), 1, 2, {endpoint: false}); |
| 73 | + var y = ndarray([1], [1]); |
| 74 | + t.assert(ndt.equal(x, y)); |
| 75 | + t.end(); |
72 | 76 | });
|
73 | 77 |
|
0 commit comments