Repository navigation
Expand file tree
/
Copy pathtest.js
More file actions
164 lines (139 loc) · 4.05 KB
/
Copy pathtest.js
File metadata and controls
164 lines (139 loc) · 4.05 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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
const test = require('brittle')
const BiMap = require('.')
function makeOne() {
return new BiMap({
john: 'mary',
bob: 'alice',
ptolemy: 'cleopatra'
})
}
test('it should create an empty Map', function (t) {
const empty = new BiMap()
t.is(empty instanceof BiMap, true)
t.is(empty.size, 0)
})
test('it should get the value by key', function (t) {
const monogamy = makeOne()
t.is(monogamy.get('bob'), 'alice')
})
test('it should get the key by value', function (t) {
const monogamy = makeOne()
t.is(monogamy.getKey('alice'), 'bob')
})
test('it should set change values of same key', function (t) {
const monogamy = new BiMap()
monogamy.set('a', 0)
monogamy.set('a', 1)
t.is(monogamy.get('a'), 1)
t.is(monogamy.getKey(1), 'a')
t.is(monogamy.hasValue(0), false)
t.is(monogamy.hasValue(1), true)
})
test('it should set change keys of same value', function (t) {
const monogamy = new BiMap()
monogamy.set('a', 0)
monogamy.set('b', 0)
t.is(monogamy.get('b'), 0)
t.is(monogamy.getKey(0), 'b')
t.is(monogamy.has('a'), false)
t.is(monogamy.has('b'), true)
})
test('it should set the same key-value', function (t) {
const monogamy = new BiMap()
monogamy.set('a', 0)
monogamy.set('a', 0)
t.is(monogamy.get('a'), 0)
t.is(monogamy.getKey(0), 'a')
t.is(monogamy.has('a'), true)
t.is(monogamy.hasValue(0), true)
})
test('it should chain calls to set', function (t) {
const monogamy = new BiMap()
const result = monogamy.set('a', 0).set('b', 1)
t.is(result, monogamy)
t.is(monogamy.get('a'), 0)
t.is(monogamy.get('b'), 1)
})
test('it should get the size', function (t) {
const monogamy = makeOne()
t.is(monogamy.size, 3)
})
test('it should clear', function (t) {
const monogamy = makeOne()
monogamy.clear()
t.is(monogamy.size, 0)
})
test('it should delete by key', function (t) {
const monogamy = makeOne()
t.is(monogamy.delete('john'), true)
t.is(monogamy.has('john'), false)
t.is(monogamy.hasValue('mary'), false)
})
test('it should not delete by a missing key', function (t) {
const monogamy = new BiMap()
t.is(monogamy.delete('missing'), false)
})
test('it should delete by value', function (t) {
const monogamy = makeOne()
t.is(monogamy.deleteValue('alice'), true)
t.is(monogamy.has('bob'), false)
t.is(monogamy.hasValue('alice'), false)
})
test('it should not delete by a missing value', function (t) {
const monogamy = new BiMap()
t.is(monogamy.deleteValue('missing'), false)
})
test('it should return the entries', function (t) {
const monogamy = makeOne()
const entriesIt = monogamy.entries()
t.is(entriesIt.next().value[0], 'john')
t.is(entriesIt.next().value[1], 'alice')
})
test('it should check if it has a key', function (t) {
const monogamy = makeOne()
t.is(monogamy.has('bob'), true)
t.is(monogamy.has('bill'), false)
})
test('it should check if it has a value', function (t) {
const monogamy = makeOne()
t.is(monogamy.hasValue('alice'), true)
t.is(monogamy.hasValue('laura'), false)
})
test('it should return the keys', function (t) {
const monogamy = makeOne()
const keysIt = monogamy.keys()
t.is(keysIt.next().value, 'john')
t.is(keysIt.next().value, 'bob')
})
test('it should return the values', function (t) {
const monogamy = makeOne()
const valuesIt = monogamy.values()
t.is(valuesIt.next().value, 'mary')
t.is(valuesIt.next().value, 'alice')
})
test('it should return the plain {}', function (t) {
const monogamy = makeOne()
const object = monogamy.getObject()
t.is(typeof object, 'object')
t.is(object['john'], 'mary')
t.is(object['bob'], 'alice')
})
test('it should return the reverse plain {}', function (t) {
const monogamy = makeOne()
const object = monogamy.getObjectReverse()
t.is(typeof object, 'object')
t.is(object['mary'], 'john')
t.is(object['alice'], 'bob')
})
test('it should be iterable', function (t) {
const monogamy = makeOne()
const entries = []
for (const [key, value] of monogamy) {
entries.push([key, value])
}
t.alike(entries, [
['john', 'mary'],
['bob', 'alice'],
['ptolemy', 'cleopatra']
])
})