forked from thinkb4/a-walk-in-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iteration.test.js
85 lines (60 loc) · 1.93 KB
/
iteration.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
describe('DAY 5: Test Iteration - While', () => {
it(`(while loop)
condition: should loop until a is less than 5
body: post increment a on each iteration`, () => {
let a = 0;
expect(a).toBe(5);
});
it(`(while loop)
condition: pre increment a
body: should break if a is greater than 4`, () => {
let a = 0;
expect(a).toBe(5);
});
});
describe('DAY 5: Test Iteration - for', () => {
it(`(for loop)
initialization: declare a to 0
condition: keep looping whilst a is less than 5
final-expression: post increment a
body: operate with a and b to make b be 11 as final result`, () => {
let a;
let b = 1;
expect(a).toBe(5);
expect(b).toBe(11);
});
it(`(for loop)
initialization: set a to 0
condition: keep looping whilst a is less than 5
final-expression: post increment a
body: operate with a and b to make b a string equals to 01234`, () => {
let b = '';
expect(b).toBe('01234');
});
});
describe('DAY 5: Test Iteration - for...in', () => {
it(`(for..in loop)
for every property in object
multiply the property value per 2`, () => {
let object = { prop1: 1, prop2: 2, prop3: 3 };
expect(object.prop1).toBe(2);
expect(object.prop2).toBe(4);
expect(object.prop3).toBe(6);
});
it(`(for..in loop)
for every property in object
add the property name to the array`, () => {
let array = [];
let object = { prop1: 1, prop2: 2, prop3: 3 };
expect(array.indexOf('prop1')).toBe(0);
});
});
describe('DAY 5: Test Iteration - for...of', () => {
it(`(for..of loop)
for every char of string
add its uppercase version to string2`, () => {
let string = 'hello';
let string2 = '';
expect(string2).toBe('HELLO');
});
});