-
Notifications
You must be signed in to change notification settings - Fork 58
/
lib.spec.js
87 lines (80 loc) · 2.09 KB
/
lib.spec.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
/* eslint-env mocha */
'use strict';
var assert = require('assert');
var lib = require('./lib');
var friends = [
{
name: 'Sam',
friends: ['Mat', 'Sharon'],
gender: 'male',
best: true
},
{
name: 'Sally',
friends: ['Brad', 'Emily'],
gender: 'female',
best: true
},
{
name: 'Mat',
friends: ['Sam', 'Sharon'],
gender: 'male'
},
{
name: 'Sharon',
friends: ['Sam', 'Itan', 'Mat'],
gender: 'female'
},
{
name: 'Brad',
friends: ['Sally', 'Emily', 'Julia'],
gender: 'male'
},
{
name: 'Emily',
friends: ['Sally', 'Brad'],
gender: 'female'
},
{
name: 'Itan',
friends: ['Sharon', 'Julia'],
gender: 'male'
},
{
name: 'Julia',
friends: ['Brad', 'Itan'],
gender: 'female'
}
];
describe('Итераторы', function () {
it('должны обойти в правильном порядке друзей и составить пары', function () {
var maleFilter = new lib.MaleFilter();
var femaleFilter = new lib.FemaleFilter();
var maleIterator = new lib.LimitedIterator(friends, maleFilter, 2);
var femaleIterator = new lib.Iterator(friends, femaleFilter);
var invitedFriends = [];
while (!maleIterator.done() && !femaleIterator.done()) {
invitedFriends.push([
maleIterator.next(),
femaleIterator.next()
]);
}
while (!femaleIterator.done()) {
invitedFriends.push(femaleIterator.next());
}
assert.deepStrictEqual(invitedFriends, [
[friend('Sam'), friend('Sally')],
[friend('Brad'), friend('Emily')],
[friend('Mat'), friend('Sharon')],
friend('Julia')
]);
});
function friend(name) {
var len = friends.length;
while (len--) {
if (friends[len].name === name) {
return friends[len];
}
}
}
});