Skip to content

Commit f35852b

Browse files
committed
fix: repository...
- add travis-ci and coverage - some refactoring - added missing tests closes #1.
1 parent 7b7abe7 commit f35852b

File tree

7 files changed

+39
-9
lines changed

7 files changed

+39
-9
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ lib/*
22
node_modules/**
33
yarn.lock
44
package-lock.json
5+
builder/**
6+
coverage/**
7+
.nyc_output/**

.travis.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
language: node_js
2+
node_js:
3+
- "7"
4+
cache:
5+
yarn: true
6+
7+
install:
8+
- yarn install
9+
10+
script:
11+
- REPORT=lcov make test
12+
13+
after_success:
14+
- cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage

Makefile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ dist-all: pre-build dist/range.js dist/range.min.js lib/range.js
1717

1818
all: test dist-all lib/range.js
1919

20-
test:
21-
$(MOCHA) $(TEST_CFLAGS) tests/*.js
22-
2320
clean:
2421
rm -rf lib dist
2522

builder

Submodule builder updated 1 file

package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@
1616
"babel-preset-es2015": "^6.24.1",
1717
"babel-preset-stage-0": "^6.24.1",
1818
"babel-register": "^6.26.0",
19+
"coveralls": "^2.13.1",
20+
"istanbul": "^0.4.5",
1921
"mocha": "^3.5.0",
22+
"nyc": "^11.2.1",
2023
"should": "^12.0.0"
24+
},
25+
"nyc": {
26+
"exclude": [
27+
"tests/*.js"
28+
]
2129
}
2230
}

src/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ export const rangeIn = (start, end, range) =>
1111

1212
export const rangeImpl = (start, end, step, f) => {
1313
const length = end - start;
14-
const elements = step > 1 ?
15-
(length - (step == 1 ? 0 : Math.round(length / step))) :
16-
Math.round(length / step);
14+
if (length == 0 || step == 0) { return []; }
15+
const steps = Math.round(length / step);
16+
const elements = step > 1 ? (length - steps) : steps;
1717
const ls = new Array(elements);
1818
for (let i = 0; i < length && i <= elements; i++) {
1919
ls[i] = f((i * step) + start);
@@ -27,7 +27,7 @@ export const rangeChar = (start, end) => {
2727
let ok = rangeIn(x, y, charLowerRange) ||
2828
rangeIn(x, y, charUpperRange) ||
2929
rangeIn(x, y, charNumberRange);
30-
return ok ? rangeImpl( x, y + 1, 1, String.fromCharCode) : [];
30+
return ok ? rangeImpl(x, y + 1, 1, String.fromCharCode) : [];
3131
};
3232

3333
export const rangeStep = (start, end, step) =>

tests/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as R from '../src/index.js';
44

55
describe("range", () => {
66
context("numeric", () => {
7-
it("empty range.", () => {
7+
it("zero range.", () => {
88
R.range(0, 0).should.be.eql([]);
99
});
1010

@@ -34,6 +34,14 @@ describe("range", () => {
3434
it("[1..10), 2", () => {
3535
R.rangeStep(1, 10, 2).length.should.be.eql(5);
3636
});
37+
38+
it("[1..10]", () => {
39+
R.rangeInclStep(1, 10, 2).length.should.be.eql(6);
40+
});
41+
42+
it("zero step should return empty list.", () => {
43+
R.rangeImpl(1, 1, 0).should.be.eql([]);
44+
});
3745
});
3846
});
3947

0 commit comments

Comments
 (0)