-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
113 lines (104 loc) · 4.07 KB
/
test.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
console.log('********************************************************************************************************************************************')
console.log('')
console.log('Test Results Below')
console.log('__________________')
var chai = require('chai'),
expect = chai.expect
should = chai.should
assert = chai.assert
function checkFuncBasics(name,argNum) {
try {
var func = eval(name)
}
catch(e) {
assert.equal(undefined,name,'Make sure your function is called ' + name + ', case-sensitive.')
}
if (argNum) assert.equal(func.length,argNum,'Your function should take ' + argNum + ' argument(s) (that means inputs). Does it?')
}
describe('squareDance()', function(){
it('should have length equal to that of the original array', function(){
checkFuncBasics('squareDance',1)
expect(squareDance([2,4,6])).to.have.lengthOf(3)
})
it('should return a new array where each element in the original array has been squared.', function(){
var newArr = squareDance([2,4,6])
expect(newArr[1]).to.equal(16)
})
})
describe('nicer()', function(){
it('should return a string .', function() {
checkFuncBasics('nicer',1)
expect(nicer("test string")).to.be.a('string')
})
it('should return a copy of the input sentence with the words heck, darn, dang, and crappy omitted.', function(){
expect(nicer("mom get the heck in here and bring me a darn sandwich."))
.to.equal("mom get the in here and bring me a sandwich.")
expect(nicer("here son, your crappy sandwich is on the dang plate."))
.to.equal("here son, your sandwich is on the plate.")
})
})
describe('capitalizeAll()', function(){
it('should return a string.', function(){
checkFuncBasics('capitalizeAll',1)
expect(capitalizeAll('test sentence')).to.be.a('string')
})
it('should return a copy of the first string, with the first letter of each word capitalized.', function(){
expect(capitalizeAll('every day is like sunday')).to.equal('Every Day Is Like Sunday')
expect(capitalizeAll('hello world')).to.equal('Hello World')
})
})
describe('properSentences()', function(){
it('should return a copy of the first string, with the first letter of each *sentence* capitalized.', function(){
checkFuncBasics('properSentences',1)
var testParagraph = 'it was a fine morning. the wine was good. light slanted in through the cafe window.'
var properParagraph = 'It was a fine morning. The wine was good. Light slanted in through the cafe window.'
expect(properSentences(testParagraph)).to.equal(properParagraph)
})
})
describe('iPutTheFunIn()', function(){
it('should return a copy of the first string, with the word "fun" inserted into the middle.', function(){
checkFuncBasics('iPutTheFunIn',1)
expect(iPutTheFunIn('funerary')).to.equal('funefunrary')
expect(iPutTheFunIn('reds')).to.equal('refunds')
})
})
describe('split()', function(){
it('should return an array', function(){
checkFuncBasics('split',2)
expect(split('a b c',' ')).to.be.a('array')
})
it('should contain elements from the input string, separated by the input delimiter', function() {
var fruits = "pear,apple,plum",
fruitsArr = split(fruits,',')
expect(fruitsArr[1]).to.equal('apple')
expect(split('a b c',' ')[0]).to.equal('a')
})
})
describe('pipeline()', function() {
it('should take three inputs, a value and two functions. it should process the value through each function in succession and return the final result', function() {
// test 1
var paragraph = 'mom bring your crappy self in here. i want a dang sandwich.'
var result = pipeline(paragraph,nicer,properSentences)
expect(result).to.equal("Mom bring your self in here. I want a sandwich.")
// test 2
var squareNum = function(n){
return n * n
}
var addOne = function(n) {
return n + 1
}
var result = pipeline(7,squareNum,addOne)
expect(result).to.equal(50)
// test 3
var exclaimAll = function(arr) {
var newArr = []
for (var i = 0; i < arr.length; i ++) {
newArr.push(arr[i] + '!')
}
return newArr
}
var result = pipeline([10,20,30],squareDance,exclaimAll)
expect(result[1]).to.equal("400!")
expect(result[2]).to.equal("900!")
})
})