From 280fa2c9ca1659dc7a247251e2223eb2131de764 Mon Sep 17 00:00:00 2001 From: Muthu Kumar Date: Tue, 15 May 2018 11:44:15 +0530 Subject: [PATCH] [tests] Added spec --- spec/spec.js | 38 ++++++++++++++++++++++++++++++++++++++ spec/support/jasmine.json | 11 +++++++++++ 2 files changed, 49 insertions(+) create mode 100644 spec/spec.js create mode 100644 spec/support/jasmine.json diff --git a/spec/spec.js b/spec/spec.js new file mode 100644 index 0000000..ec68752 --- /dev/null +++ b/spec/spec.js @@ -0,0 +1,38 @@ +'use strict'; + +const infiniteList = require('../index'); + +/* global describe it expect */ +describe("InfiniteList", () => { + + it("Should be 0", () => { + const infinite = infiniteList.create(0, x => x + 2); + expect(infinite.first().value).toBe(0); + }) + + it("Should be 22", () => { + const infinite = infiniteList.create(0, x => x + 2); + expect(infinite.get(11).value).toBe(22); + }) + + it("Should be [ 0, 2, 4, 6, 8 ]", () => { + const infinite = infiniteList.create(0, x => x + 2); + expect(infinite.take(5).map(x => x.value)).toEqual([ 0, 2, 4, 6, 8 ]); + }) + + it("Should be [ 16, 18, 20 ]", () => { + const infinite = infiniteList.create(0, x => x + 2); + expect(infinite.take(8, 10).map(x => x.value)).toEqual([ 16, 18, 20 ]); + }) + + it("Should be [ 0, 2, 4, 6, 8 ]", () => { + const infinite = infiniteList.create(0, x => x + 2); + const acc = []; + for(let i of infinite) { + if(i.index >= 5) break; + acc.push(i.value) + } + expect(acc).toEqual([ 0, 2, 4, 6, 8 ]); + }) + +}) \ No newline at end of file diff --git a/spec/support/jasmine.json b/spec/support/jasmine.json new file mode 100644 index 0000000..370fc44 --- /dev/null +++ b/spec/support/jasmine.json @@ -0,0 +1,11 @@ +{ + "spec_dir": "spec", + "spec_files": [ + "**/*[sS]pec.js" + ], + "helpers": [ + "helpers/**/*.js" + ], + "stopSpecOnExpectationFailure": false, + "random": true +}