-
Notifications
You must be signed in to change notification settings - Fork 82
finished testing #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
finished testing #30
Changes from 1 commit
993239d
31b4be4
4fc875b
f401746
551ac19
de0972b
8166895
14ac495
32904c3
ba3afd8
633ce47
839272f
b65ff9d
9db7da1
acf4726
fe30029
380ef76
fb38d6d
05e9cce
15056d5
f4d98df
ed8a7e3
fd0df58
c70ee42
854a393
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| function replaceWith(str, target, replacement){ | ||
| return str | ||
| .split('') | ||
| .map(function(v,i,a){ | ||
| if(v === target) return replacement; | ||
| else return v; | ||
| }).join(''); | ||
| } | ||
|
|
||
| function expand(arr, num) { | ||
| var a = []; | ||
|
|
||
| for(let i = 0; i < num; i++){ | ||
| a = a.concat(arr); | ||
| } | ||
|
|
||
| return a; | ||
| } | ||
|
|
||
| function acceptNumbersOnly(...args) { | ||
| for(let a of args){ | ||
| if(typeof a !== 'number' || isNaN(a)){ | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| function mergeArrays(arr1, arr2) { | ||
| return arr1.concat(arr2).sort(); | ||
|
||
| } | ||
|
|
||
| function mergeObjects(...args) { | ||
| return args.reduce(function(t,v,i,a){ | ||
| Object.keys(v).forEach(function(sv, si, sa){ | ||
|
||
| t[sv] = v[sv]; | ||
| }); | ||
| return t; | ||
| },{}); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,97 @@ | ||
| var expect = chai.expect; | ||
|
|
||
| // WRITE YOUR TESTS HERE! | ||
| describe('This will test the replaceWith function', function(){ | ||
|
|
||
| it('replaceWith should be a function', function() { | ||
| expect(typeof replaceWith).to.equal('function'); | ||
| }); | ||
| it('replaceWith should return correct values', function () { | ||
| expect(replaceWith("awesome", "e", "z")).to.equal("awzsomz"); | ||
| expect(replaceWith("Foo", "F", "B")).to.equal("Boo"); | ||
| }); | ||
| it('replaceWith should be case sensitive', function () { | ||
| expect(replaceWith("awesomE", "e", "z")).to.equal("awzsomE"); | ||
| expect(replaceWith("Foo", "f", "B")).to.equal("Foo"); | ||
| expect(replaceWith("ffFFfFB", "f", "B")).to.equal("BBFFBFB"); | ||
| }); | ||
|
|
||
| }); | ||
|
|
||
| describe('This will test the expand function', function(){ | ||
|
|
||
| it('expand should be a function', function() { | ||
| expect(typeof expand).to.equal('function'); | ||
| }); | ||
| it('expand should return correct values', function () { | ||
| expect(expand([1,2,3],3)).to.deep.equal([1,2,3,1,2,3,1,2,3]); | ||
| expect(expand(["foo", "test"],1)).to.deep.equal(["foo","test"]); | ||
| expect(expand(["foo", "test"],0)).to.deep.equal([]); | ||
| }); | ||
|
|
||
| }); | ||
|
|
||
| describe('This will test the acceptNumbersOnly function', function(){ | ||
|
|
||
| it('expand should be a function', function() { | ||
| expect(typeof acceptNumbersOnly).to.equal('function'); | ||
| }); | ||
|
|
||
| it('acceptNumbersOnly should return correct values', function () { | ||
| expect(acceptNumbersOnly(1,"foo")).to.equal(false); | ||
| expect(acceptNumbersOnly(1,2,3,4,5,6,7)).to.equal(true); | ||
| expect(acceptNumbersOnly(1)).to.equal(true); | ||
| }); | ||
|
|
||
| it('acceptNumbersOnly should deal with objects input', function () { | ||
| expect(acceptNumbersOnly([])).to.equal(false); | ||
| expect(acceptNumbersOnly({})).to.equal(false); | ||
| }); | ||
|
|
||
| it('acceptNumbersOnly should deal with strings input', function () { | ||
| expect(acceptNumbersOnly('')).to.equal(false); | ||
| expect(acceptNumbersOnly('5')).to.equal(false); | ||
| }); | ||
|
|
||
| it('acceptNumbersOnly should deal with null input', function () { | ||
| expect(acceptNumbersOnly(null)).to.equal(false); | ||
| }); | ||
|
|
||
| it('acceptNumbersOnly should deal with NaN input', function () { | ||
| expect(acceptNumbersOnly(NaN)).to.equal(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('This will test the mergeArrays function', function(){ | ||
|
|
||
| it('mergeArrays should be a function', function() { | ||
| expect(typeof mergeArrays).to.equal('function'); | ||
| }); | ||
| it('mergeArrays should return correct values', function () { | ||
| expect(mergeArrays([2,1],[3,4])).to.deep.equal([1,2,3,4]); | ||
| }); | ||
|
|
||
| }); | ||
|
|
||
| describe('This will test the mergeObjects function', function(){ | ||
| var obj1= { | ||
| name: "Foo", | ||
| num: 33 | ||
| } | ||
| var obj2 = { | ||
| test: "thing", | ||
| num: 55 | ||
| } | ||
| var obj12 = { | ||
| name: "Foo", | ||
| test: "thing", | ||
| num: 55 | ||
| } | ||
|
|
||
| it('mergeObjects should be a function', function() { | ||
| expect(typeof mergeObjects).to.equal('function'); | ||
| }); | ||
| it('mergeObjects should return correct values', function () { | ||
| expect(mergeObjects(obj1, obj2)).to.deep.equal(obj12); | ||
| }); | ||
|
|
||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small thing, but if you're not using the other arguments
ianda, you don't need to include them in the callback. your callback can just be a function of a single parameter.