forked from educastellano/bidirectional-map
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
131 lines (113 loc) · 3.32 KB
/
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
var test = require('tape');
var BiMap = require('./dist/index').default
var makeOne = function() {
return new BiMap([
['john', 'mary'],
['bob', 'alice'],
['ptolemy','cleopatra']
])
}
test('it should create an empty Map', function (t) {
var empty = new BiMap()
t.equals(empty instanceof BiMap, true);
t.equals(empty.size, 0);
t.end();
});
test('it should get the value by key', function (t) {
var monogamy = makeOne()
t.equals(monogamy.get('bob'), 'alice');
t.end();
});
test('it should get the key by value', function (t) {
var monogamy = makeOne()
t.equals(monogamy.getKey('alice'), 'bob');
t.end();
});
test('it should set change values of same key', function (t) {
var monogamy = new BiMap()
monogamy.set('a', 0)
monogamy.set('a', 1)
t.equals(monogamy.get('a'), 1);
t.equals(monogamy.getKey(1), 'a');
t.equals(monogamy.hasValue(0), false);
t.equals(monogamy.hasValue(1), true);
t.end();
});
test('it should set change keys of same value', function (t) {
var monogamy = new BiMap()
monogamy.set('a', 0)
monogamy.set('b', 0)
t.equals(monogamy.get('b'), 0);
t.equals(monogamy.getKey(0), 'b');
t.equals(monogamy.has('a'), false);
t.equals(monogamy.has('b'), true);
t.end();
});
test('it should set the same key-value', function (t) {
var monogamy = new BiMap()
monogamy.set('a', 0)
monogamy.set('a', 0)
t.equals(monogamy.get('a'), 0);
t.equals(monogamy.getKey(0), 'a');
t.equals(monogamy.has('a'), true);
t.equals(monogamy.hasValue(0), true);
t.end();
});
test('it should get the size', function (t) {
var monogamy = makeOne()
t.equals(monogamy.size, 3);
t.end();
});
test('it should clear', function (t) {
var monogamy = makeOne()
monogamy.clear()
t.equals(monogamy.size, 0);
t.end();
});
test('it should delete by key', function (t) {
var monogamy = makeOne()
monogamy.delete('john')
t.equals(monogamy.has('john'), false);
t.equals(monogamy.hasValue('mary'), false);
t.end();
});
test('it should delete by value', function (t) {
var monogamy = makeOne()
monogamy.deleteValue('alice')
t.equals(monogamy.has('bob'), false);
t.equals(monogamy.hasValue('alice'), false);
t.end();
});
test('it should return the entries', function (t) {
var monogamy = makeOne()
var entriesIt = monogamy.entries()
t.equals(entriesIt.next().value[0], 'john');
t.equals(entriesIt.next().value[1], 'alice');
t.end();
});
test('it should check if it has a key', function (t) {
var monogamy = makeOne()
t.equals(monogamy.has('bob'), true);
t.equals(monogamy.has('bill'), false);
t.end();
});
test('it should check if it has a value', function (t) {
var monogamy = makeOne()
t.equals(monogamy.hasValue('alice'), true);
t.equals(monogamy.hasValue('laura'), false);
t.end();
});
test('it should return the keys', function (t) {
var monogamy = makeOne()
var keysIt = monogamy.keys()
t.equals(keysIt.next().value, 'john');
t.equals(keysIt.next().value, 'bob');
t.end();
});
test('it should return the values', function (t) {
var monogamy = makeOne()
var valuesIt = monogamy.values()
t.equals(valuesIt.next().value, 'mary');
t.equals(valuesIt.next().value, 'alice');
t.end();
});