This repository was archived by the owner on Oct 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrange.js
71 lines (59 loc) · 1.98 KB
/
range.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
describe('range', function() {
describe('when not given any arguments', function() {
it('should return a lazy sequence of all natural numbers', function() {
var r = range()
expect(r.length).to.equal(Infinity)
expect(vec(take(5, r))).to.eql([0, 1, 2, 3, 4])
})
})
describe('when given one argument: `end`', function() {
it('should return a lazy sequence of numbers from 0 to `end` (exclusive)', function() {
var r = range(5)
expect(r.length).to.equal(5)
expect(vec(r)).to.eql([0, 1, 2, 3, 4])
})
})
describe('when given two arguments: `start` and `end`', function() {
it('should return a lazy sequence of numbers from `start` (inclusive) to `end` (exclusive)', function() {
var r = range(-5, 0)
expect(r.length).to.equal(5)
expect(vec(r)).to.eql([-5, -4, -3, -2, -1])
})
})
describe('when given three arguments: `start`, `end`, and `step`', function() {
it('should return use `step` as the increment', function() {
var r = range(0, 5, 0.5)
expect(r.length).to.equal(10)
expect(vec(r)).to.eql([0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5])
})
})
describe('when given an invalid `start` value', function() {
it('should throw a TypeError', function() {
expect(function() {
range(false, 5)
}).to.throw(TypeError)
})
})
describe('when given an invalid `end` value', function() {
it('should throw a TypeError', function() {
expect(function() {
range(false)
}).to.throw(TypeError)
expect(function() {
range(5, false)
}).to.throw(TypeError)
})
})
describe('when given an invalid `step` value', function() {
it('should throw a TypeError', function() {
expect(function() {
range(0, 5, null)
}).to.throw(TypeError)
})
})
})
var expect = require('must')
, range = require('../lib/range')
, each = require('../lib/each')
, take = require('../lib/take')
, vec = require('../lib/vec')