-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathAdaCat.test.js
242 lines (209 loc) · 6.84 KB
/
AdaCat.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
var chai = require('chai')
var expect = chai.expect
var AdaCat = require('./AdaCat')
describe('AdaCat', function() {
it('is a class', function() {
var myCat = new AdaCat('jeff', 'alex')
expect(myCat).to.be.an.instanceOf(AdaCat)
})
describe('#constructor', function() {
it('takes name and sets it as an attribute', function() {
var myCat = new AdaCat('taffy', 'alex')
expect(myCat.name).to.equal('taffy')
})
it('takes owner and sets it as an attribute', function() {
var myCat = new AdaCat('buttons', 'alex')
expect(myCat.owner).to.equal('alex')
})
it('sets the hunger attribute to 5', function() {
var myCat = new AdaCat('greg', 'alex')
expect(myCat.hunger).to.equal(5)
})
it('sets the isSleeping attribute to false', function() {
var myCat = new AdaCat('denim', 'alex')
expect(myCat.isSleeping).to.equal(false)
})
it('sets the size attribute to 30', function() {
var myCat = new AdaCat('toyota', 'alex')
expect(myCat.size).to.equal(30)
})
})
describe('#getDescription', function() {
it('includes the name and owner', function() {
var myCat = new AdaCat('decking', 'alex')
var result = myCat.getDescription()
var lines = result.split('\n')
expect(lines[0]).to.equal('decking is a cat. they belong to alex.')
})
it('includes the hunger level', function() {
var myCat = new AdaCat('socks', 'alex')
var result = myCat.getDescription()
var lines = result.split('\n')
expect(lines[1]).to.equal('their hunger level is 5/10.')
})
it('tells you if the cat is awake', function() {
var myCat = new AdaCat('marmite', 'alex')
var result = myCat.getDescription()
var lines = result.split('\n')
expect(lines[4]).to.equal('marmite is awake.')
})
it('tells you if the cat is asleep', function() {
var myCat = new AdaCat('mc splinters', 'alex')
myCat.nap()
var result = myCat.getDescription()
var lines = result.split('\n')
expect(lines[4]).to.equal('Shh! mc splinters is sleeping.')
})
it('includes the cat size', function() {
var myCat = new AdaCat('oak', 'alex')
var result = myCat.getDescription()
var lines = result.split('\n')
expect(lines[2]).to.equal('they weigh 30 tonnes.')
})
it('includes the health level', function() {
var myCat = new AdaCat('professor dangle', 'alex')
var result = myCat.getDescription()
var lines = result.split('\n')
expect(lines[3]).to.equal('their health is 25/30.')
})
})
describe('#feed', function() {
it('decreases the hunger attribute by 1', function() {
var myCat = new AdaCat('mittens', 'alex')
myCat.feed()
expect(myCat.hunger).to.equal(4)
})
it('does not decrease hunger below 0', function() {
var myCat = new AdaCat('leggy', 'alex')
myCat.hunger = 0
myCat.feed()
expect(myCat.hunger).to.equal(0)
})
it('increases size when hunger is less than three', function() {
var myCat = new AdaCat('pencil', 'alex')
myCat.hunger = 2
myCat.feed()
expect(myCat.size).to.equal(31)
})
})
describe('#nap', function() {
it('sets the isSleeping attribute to true', function() {
var myCat = new AdaCat('apple', 'alex')
myCat.nap()
expect(myCat.isSleeping).to.equal(true)
})
})
describe('#wakeUp', function() {
it('sets the isSleeping attribute to false', function() {
var myCat = new AdaCat('brick', 'alex')
myCat.isSleeping = true
myCat.wakeUp()
expect(myCat.isSleeping).to.equal(false)
})
})
describe('#play', function() {
it('increases hunger by 3', function() {
var myCat = new AdaCat('zebra', 'alex')
myCat.play()
expect(myCat.hunger).to.equal(8)
})
it('will not increase hunger above 10', function() {
var myCat = new AdaCat('jorts', 'alex')
myCat.hunger = 9
myCat.play()
expect(myCat.hunger).to.equal(10)
})
it('decreases size when hunger is above 7', function() {
var myCat = new AdaCat('ada', 'alex')
myCat.hunger = 8
myCat.play()
expect(myCat.size).to.equal(29)
})
})
describe('#getHealth', function() {
it('is 30 when size = 30, hunger = 0', function() {
var myCat = new AdaCat('bort', 'alex')
myCat.size = 30
myCat.hunger = 0
var result = myCat.getHealth()
expect(result).to.equal(30)
})
it('is 25 when size = 25, hunger = 0', function() {
var myCat = new AdaCat('bort', 'alex')
myCat.size = 25
myCat.hunger = 0
var result = myCat.getHealth()
expect(result).to.equal(25)
})
it('is 25 when size = 35, hunger = 0', function() {
var myCat = new AdaCat('bort', 'alex')
myCat.size = 35
myCat.hunger = 0
var result = myCat.getHealth()
expect(result).to.equal(25)
})
it('is 5 when size = 5, hunger = 0', function() {
var myCat = new AdaCat('bort', 'alex')
myCat.size = 5
myCat.hunger = 0
var result = myCat.getHealth()
expect(result).to.equal(5)
})
it('is 5 when size = 55, hunger = 0', function() {
var myCat = new AdaCat('bort', 'alex')
myCat.size = 55
myCat.hunger = 0
var result = myCat.getHealth()
expect(result).to.equal(5)
})
it('is 0 when size = 65, hunger = 0', function() {
var myCat = new AdaCat('bort', 'alex')
myCat.size = 65
myCat.hunger = 0
var result = myCat.getHealth()
expect(result).to.equal(0)
})
it('is 23 when size = 30, hunger = 7', function() {
var myCat = new AdaCat('bort', 'alex')
myCat.size = 30
myCat.hunger = 7
var result = myCat.getHealth()
expect(result).to.equal(23)
})
it('is 18 when size = 25, hunger = 7', function() {
var myCat = new AdaCat('bort', 'alex')
myCat.size = 25
myCat.hunger = 7
var result = myCat.getHealth()
expect(result).to.equal(18)
})
it('is 18 when size = 35, hunger = 7', function() {
var myCat = new AdaCat('bort', 'alex')
myCat.size = 35
myCat.hunger = 7
var result = myCat.getHealth()
expect(result).to.equal(18)
})
it('is 2 when size = 5, hunger = 3', function() {
var myCat = new AdaCat('bort', 'alex')
myCat.size = 5
myCat.hunger = 3
var result = myCat.getHealth()
expect(result).to.equal(2)
})
it('is 2 when size = 55, hunger = 3', function() {
var myCat = new AdaCat('bort', 'alex')
myCat.size = 55
myCat.hunger = 3
var result = myCat.getHealth()
expect(result).to.equal(2)
})
it('is 0 when size = 1, hunger = 3', function() {
var myCat = new AdaCat('bort', 'alex')
myCat.size = 1
myCat.hunger = 3
var result = myCat.getHealth()
expect(result).to.equal(0)
})
})
})