Skip to content

Commit 98c70d6

Browse files
committed
completed challenge copilot-workshops#2: add tests for power function
1 parent da930ad commit 98c70d6

File tree

1 file changed

+165
-1
lines changed

1 file changed

+165
-1
lines changed

test/arithmetic.test.js

Lines changed: 165 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,171 @@ describe('Arithmetic', function () {
145145
});
146146
});
147147
});
148-
148+
149+
// add tests for power
150+
describe('Power', function () {
151+
it('raises a positive integer to a positive integer power', function (done) {
152+
request.get('/arithmetic?operation=power&operand1=2&operand2=3')
153+
.expect(200)
154+
.end(function (err, res) {
155+
expect(res.body).to.eql({ result: 8 });
156+
done();
157+
});
158+
});
159+
it('raises a positive integer to a zero power', function (done) {
160+
request.get('/arithmetic?operation=power&operand1=2&operand2=0')
161+
.expect(200)
162+
.end(function (err, res) {
163+
expect(res.body).to.eql({ result: 1 });
164+
done();
165+
});
166+
});
167+
it('raises a positive integer to a negative integer power', function (done) {
168+
request.get('/arithmetic?operation=power&operand1=2&operand2=-3')
169+
.expect(200)
170+
.end(function (err, res) {
171+
expect(res.body).to.eql({ result: 0.125 });
172+
done();
173+
});
174+
});
175+
it('raises a negative integer to a positive integer power', function (done) {
176+
request.get('/arithmetic?operation=power&operand1=-2&operand2=3')
177+
.expect(200)
178+
.end(function (err, res) {
179+
expect(res.body).to.eql({ result: -8 });
180+
done();
181+
});
182+
});
183+
it('raises a negative integer to a zero power', function (done) {
184+
request.get('/arithmetic?operation=power&operand1=-2&operand2=0')
185+
.expect(200)
186+
.end(function (err, res) {
187+
expect(res.body).to.eql({ result: 1 });
188+
done();
189+
});
190+
});
191+
it('raises a negative integer to a negative integer power', function (done) {
192+
request.get('/arithmetic?operation=power&operand1=-2&operand2=-3')
193+
.expect(200)
194+
.end(function (err, res) {
195+
expect(res.body).to.eql({ result: -0.125 });
196+
done();
197+
});
198+
});
199+
it('raises a floating point number to a positive integer power', function (done) {
200+
request.get('/arithmetic?operation=power&operand1=2.5&operand2=2')
201+
.expect(200)
202+
.end(function (err, res) {
203+
expect(res.body).to.eql({ result: 6.25 });
204+
done();
205+
});
206+
});
207+
it('raises a floating point number to a zero power', function (done) {
208+
request.get('/arithmetic?operation=power&operand1=2.5&operand2=0')
209+
.expect(200)
210+
.end(function (err, res) {
211+
expect(res.body).to.eql({ result: 1 });
212+
done();
213+
});
214+
});
215+
it('raises a floating point number to a negative integer power', function (done) {
216+
request.get('/arithmetic?operation=power&operand1=2.5&operand2=-2')
217+
.expect(200)
218+
.end(function (err, res) {
219+
expect(res.body).to.eql({ result: 0.16 });
220+
done();
221+
});
222+
});
223+
it('raises a negative floating point number to a positive integer power', function (done) {
224+
request.get('/arithmetic?operation=power&operand1=-2.5&operand2=2')
225+
.expect(200)
226+
.end(function (err, res) {
227+
expect(res.body).to.eql({ result: 6.25 });
228+
done();
229+
});
230+
});
231+
it('raises a negative floating point number to a zero power', function (done) {
232+
request.get('/arithmetic?operation=power&operand1=-2.5&operand2=0')
233+
.expect(200)
234+
.end(function (err, res) {
235+
expect(res.body).to.eql({ result: 1 });
236+
done();
237+
});
238+
});
239+
it('raises a negative floating point number to a negative integer power', function (done) {
240+
request.get('/arithmetic?operation=power&operand1=-2.5&operand2=-2')
241+
.expect(200)
242+
.end(function (err, res) {
243+
expect(res.body).to.eql({ result: 0.16 });
244+
done();
245+
});
246+
});
247+
it('raises a positive integer to a floating point number power', function (done) {
248+
request.get('/arithmetic?operation=power&operand1=2&operand2=0.5')
249+
.expect(200)
250+
.end(function (err, res) {
251+
expect(res.body).to.eql({ result: 1.4142135623730951 });
252+
done();
253+
});
254+
});
255+
it('raises a positive integer to a negative floating point number power', function (done) {
256+
request.get('/arithmetic?operation=power&operand1=2&operand2=-0.5')
257+
.expect(200)
258+
.end(function (err, res) {
259+
expect(res.body).to.eql({ result: 0.7071067811865475 });
260+
done();
261+
});
262+
});
263+
it('raises a negative integer to a floating point number power', function (done) {
264+
request.get('/arithmetic?operation=power&operand1=-2&operand2=0.5')
265+
.expect(200)
266+
.end(function (err, res) {
267+
expect(res.body).to.eql({ result: null });
268+
done();
269+
});
270+
});
271+
it('raises a negative integer to a negative floating point number power', function (done) {
272+
request.get('/arithmetic?operation=power&operand1=-2&operand2=-0.5')
273+
.expect(200)
274+
.end(function (err, res) {
275+
expect(res.body).to.eql({ result: null });
276+
done();
277+
});
278+
});
279+
it('raises a floating point number to a floating point number power', function (done) {
280+
request.get('/arithmetic?operation=power&operand1=2.5&operand2=0.5')
281+
.expect(200)
282+
.end(function (err, res) {
283+
expect(res.body).to.eql({ result: 1.5811388300841898 });
284+
done();
285+
});
286+
});
287+
it('raises a floating point number to a negative floating point number power', function (done) {
288+
request.get('/arithmetic?operation=power&operand1=2.5&operand2=-0.5')
289+
.expect(200)
290+
.end(function (err, res) {
291+
expect(res.body).to.eql({ result: 0.6324555320336759 });
292+
done();
293+
});
294+
});
295+
it('raises a negative floating point number to a floating point number power', function (done) {
296+
request.get('/arithmetic?operation=power&operand1=-2.5&operand2=0.5')
297+
.expect(200)
298+
.end(function (err, res) {
299+
expect(res.body).to.eql({ result: null });
300+
done();
301+
});
302+
});
303+
it('raises a negative floating point number to a negative floating point number power', function (done) {
304+
request.get('/arithmetic?operation=power&operand1=-2.5&operand2=-0.5')
305+
.expect(200)
306+
.end(function (err, res) {
307+
expect(res.body).to.eql({ result: null });
308+
done();
309+
});
310+
});
311+
});
312+
149313
describe('Multiplication', function () {
150314
it('multiplies two positive integers', function (done) {
151315
request.get('/arithmetic?operation=multiply&operand1=21&operand2=2')

0 commit comments

Comments
 (0)