forked from HackYourFuture/JavaScript2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstep2-3.test.js
More file actions
71 lines (59 loc) · 1.75 KB
/
step2-3.test.js
File metadata and controls
71 lines (59 loc) · 1.75 KB
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
const {
repeatStringNumTimesWithFor,
repeatStringNumTimesWithWhile,
repeatStringNumTimesWithDoWhile,
} = require('../homework/step2-3');
describe('step2-3 with for-loop', () => {
test('num = 3', () => {
const result = repeatStringNumTimesWithFor('abc', 3);
expect(result).toBe('abcabcabc');
});
test('num = 1', () => {
const result = repeatStringNumTimesWithFor('abc', 1);
expect(result).toBe('abc');
});
test('num = -2', () => {
const result = repeatStringNumTimesWithFor('abc', -2);
expect(result).toBe('');
});
test('num = 0', () => {
const result = repeatStringNumTimesWithFor('abc', 0);
expect(result).toBe('');
});
});
describe('step2-3 with while-loop', () => {
test('num = 3', () => {
const result = repeatStringNumTimesWithWhile('abc', 3);
expect(result).toBe('abcabcabc');
});
test('num = 1', () => {
const result = repeatStringNumTimesWithWhile('abc', 1);
expect(result).toBe('abc');
});
test('num = 0', () => {
const result = repeatStringNumTimesWithWhile('abc', 0);
expect(result).toBe('');
});
test('num = -2', () => {
const result = repeatStringNumTimesWithWhile('abc', -2);
expect(result).toBe('');
});
});
describe('step2-3 with do-while-loop', () => {
test('num = 3', () => {
const result = repeatStringNumTimesWithDoWhile('abc', 3);
expect(result).toBe('abcabcabc');
});
test('num = 1', () => {
const result = repeatStringNumTimesWithDoWhile('abc', 1);
expect(result).toBe('abc');
});
test('num = 0', () => {
const result = repeatStringNumTimesWithDoWhile('abc', 0);
expect(result).toBe('');
});
test('num = -2', () => {
const result = repeatStringNumTimesWithDoWhile('abc', -2);
expect(result).toBe('');
});
});