trackler 2.2.1.29 → 2.2.1.30

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,25 +1,25 @@
1
1
  {
2
+ "docs_url": "https://github.com/exercism/docs/blob/master/maintaining-a-track/maintainer-configuration.md",
2
3
  "maintainers": [
3
4
  {
4
- "github_username": "kotp",
5
- "show_on_website": false,
6
5
  "alumnus": false,
7
- "name": null,
6
+ "avatar_url": null,
8
7
  "bio": null,
8
+ "github_username": "kotp",
9
9
  "link_text": null,
10
10
  "link_url": null,
11
- "avatar_url": null
11
+ "name": null,
12
+ "show_on_website": false
12
13
  },
13
14
  {
14
- "github_username": "rpottsoh",
15
- "show_on_website": true,
16
15
  "alumnus": false,
17
- "name": "Ryan Potts",
16
+ "avatar_url": null,
18
17
  "bio": "I have been using Delphi professionally since 1996. At my day job I develop software used in the control of various types of test machines used by the auto industry. Exercism is my first real push into Open Source and I'm happy to have this opportunity to teach and share the virtures of Delphi with others.",
18
+ "github_username": "rpottsoh",
19
19
  "link_text": null,
20
20
  "link_url": null,
21
- "avatar_url": null
21
+ "name": "Ryan Potts",
22
+ "show_on_website": true
22
23
  }
23
- ],
24
- "docs_url": "https://github.com/exercism/docs/blob/master/maintaining-a-track/maintainer-configuration.md"
25
- }
24
+ ]
25
+ }
@@ -31,18 +31,25 @@ If the buffer has 7 elements then it is completely full:
31
31
  When the buffer is full an error will be raised, alerting the client
32
32
  that further writes are blocked until a slot becomes free.
33
33
 
34
- The client can opt to overwrite the oldest data with a forced write. In
35
- this case, two more elements — A & B — are added and they overwrite the
36
- 3 & 4:
34
+ When the buffer is full, the client can opt to overwrite the oldest
35
+ data with a forced write. In this case, two more elements — A & B —
36
+ are added and they overwrite the 3 & 4:
37
37
 
38
38
  [6][7][8][9][A][B][5]
39
39
 
40
- Finally, if two elements are now removed then what would be returned is
41
- not 3 & 4 but 5 & 6 because A & B overwrote the 3 & the 4 yielding the
42
- buffer with:
40
+ 3 & 4 have been replaced by A & B making 5 now the oldest data in the
41
+ buffer. Finally, if two elements are removed then what would be
42
+ returned is 5 & 6 yielding the buffer:
43
43
 
44
44
  [ ][7][8][9][A][B][ ]
45
45
 
46
+ Because there is space available, if the client again uses overwrite
47
+ to store C & D then the space where 5 & 6 were stored previously will
48
+ be used not the location of 7 & 8. 7 is still the oldest element and
49
+ the buffer is once again full.
50
+
51
+ [D][7][8][9][A][B][C]
52
+
46
53
  ## Testing
47
54
 
48
55
  In order to run the tests for this track, you will need to install
@@ -1003,6 +1003,18 @@
1003
1003
  "Algorithms"
1004
1004
  ]
1005
1005
  },
1006
+ {
1007
+ "uuid": "a1591026-2f02-45f9-b189-24b2359eb43f",
1008
+ "slug": "simple-linked-list",
1009
+ "core": false,
1010
+ "unlocked_by": "linked-list",
1011
+ "difficulty": 8,
1012
+ "topics": [
1013
+ "Arrays",
1014
+ "Data structures",
1015
+ "Lists"
1016
+ ]
1017
+ },
1006
1018
  {
1007
1019
  "uuid": "2fa2c262-77ae-409b-bfd8-1d643faae772",
1008
1020
  "slug": "connect",
@@ -1,115 +1,222 @@
1
1
  import CustomSet from './custom-set';
2
2
 
3
3
  describe('CustomSet', () => {
4
- test('can delete elements', () => {
5
- const expected = new CustomSet([1, 3]);
6
- const actual = new CustomSet([3, 2, 1]).delete(2);
7
- expect(actual.eql(expected)).toBe(true);
8
-
9
- const expected2 = new CustomSet([1, 2, 3]);
10
- const actual2 = new CustomSet([3, 2, 1]).delete(4);
11
- expect(actual2.eql(expected2)).toBe(true);
12
- });
4
+ describe('empty: returns true if the set contains no elements', () => {
5
+ xtest('sets with no elements are empty', () => {
6
+ const actual = new CustomSet().empty();
7
+ expect(actual).toBe(true);
8
+ });
13
9
 
14
- xtest('can check for difference', () => {
15
- const expected = new CustomSet([1, 3]);
16
- const actual = new CustomSet([3, 2, 1]).difference(new CustomSet([2, 4]));
17
- expect(actual.eql(expected)).toBe(true);
18
- const expected2 = new CustomSet([1, 2, 3]);
19
- const actual2 = new CustomSet([1, 2, 3]).difference(new CustomSet([4]));
20
- expect(actual2.eql(expected2)).toBe(true);
10
+ xtest('sets with elements are not empty', () => {
11
+ const actual = new CustomSet([1]).empty();
12
+ expect(actual).toBe(false);
13
+ });
21
14
  });
22
15
 
23
- xtest('can test disjoint', () => {
24
- const actual = new CustomSet([1, 2]).disjoint(new CustomSet([3, 4]));
25
- expect(actual).toBe(true);
26
- const actual2 = new CustomSet([1, 2]).disjoint(new CustomSet([2, 3]));
27
- expect(actual2).toBe(false);
28
- const actual3 = new CustomSet().disjoint(new CustomSet());
29
- expect(actual3).toBe(true);
30
- });
16
+ describe('contains: sets can report if they contain an element', () => {
17
+ xtest('nothing is contained in an empty set', () => {
18
+ const actual = new CustomSet().contains(1);
19
+ expect(actual).toBe(false);
20
+ });
31
21
 
32
- xtest('can be emptied', () => {
33
- const actual = new CustomSet([1, 2]).empty();
34
- const expected = new CustomSet();
35
- expect(actual.eql(expected)).toBe(true);
36
- const actual2 = new CustomSet().empty();
37
- const expected2 = new CustomSet();
38
- expect(actual2.eql(expected2)).toBe(true);
22
+ xtest('when the element is in the set', () => {
23
+ const actual = new CustomSet([1, 2, 3]).contains(1);
24
+ expect(actual).toBe(true);
25
+ });
26
+
27
+ xtest('when the element is not in the set', () => {
28
+ const actual = new CustomSet([1, 2, 3]).contains(4);
29
+ expect(actual).toBe(false);
30
+ });
39
31
  });
40
32
 
41
- xtest('can check for intersection', () => {
42
- const actual = new CustomSet(['a', 'b', 'c']).intersection(new CustomSet(['a', 'c', 'd']));
43
- const expected = new CustomSet(['a', 'c']);
44
- expect(actual.eql(expected)).toBe(true);
33
+ describe('subset: a set is a subset if all of its elements are contained in the other set', () => {
34
+ xtest('empty set is a subset of another empty set', () => {
35
+ const actual = new CustomSet().subset(new CustomSet());
36
+ expect(actual).toBe(true);
37
+ });
38
+
39
+ xtest('empty set is a subset of non-empty set', () => {
40
+ const actual = new CustomSet().subset(new CustomSet([1]));
41
+ expect(actual).toBe(true);
42
+ });
43
+
44
+ xtest('non-empty set is not a subset of empty set', () => {
45
+ const actual = new CustomSet([1]).subset(new CustomSet());
46
+ expect(actual).toBe(false);
47
+ });
48
+
49
+ xtest('set is a subset of set with exact same elements', () => {
50
+ const actual = new CustomSet([1, 2, 3]).subset(new CustomSet([1, 2, 3]));
51
+ expect(actual).toBe(true);
52
+ });
53
+
54
+ xtest('set is a subset of larger set with same elements', () => {
55
+ const actual = new CustomSet([1, 2, 3]).subset(new CustomSet([4, 1, 2, 3]));
56
+ expect(actual).toBe(true);
57
+ });
45
58
 
46
- const actual2 = new CustomSet([1, 2, 3]).intersection(new CustomSet([3, 5, 4]));
47
- const expected2 = new CustomSet([3]);
48
- expect(actual2.eql(expected2)).toBe(true);
59
+ xtest('set is not a subset of set that does not contain its elements', () => {
60
+ const actual = new CustomSet([1, 2, 3]).subset(new CustomSet([4, 1, 3]));
61
+ expect(actual).toBe(false);
62
+ });
49
63
  });
50
64
 
51
- xtest('can test for a member', () => {
52
- const actual = new CustomSet([1, 2, 3]).member(2);
53
- expect(actual).toBe(true);
54
- const actual2 = new CustomSet([1, 2, 3]).member(4);
55
- expect(actual2).toBe(false);
65
+ describe('disjoint: sets are disjoint if they share no elements', () => {
66
+ xtest('the empty set is disjoint with itself', () => {
67
+ const actual = new CustomSet().disjoint(new CustomSet([]));
68
+ expect(actual).toBe(true);
69
+ });
70
+
71
+ xtest('empty set is disjoint with non-empty set', () => {
72
+ const actual = new CustomSet().disjoint(new CustomSet([1]));
73
+ expect(actual).toBe(true);
74
+ });
75
+
76
+ xtest('non-empty set is disjoint with empty set', () => {
77
+ const actual = new CustomSet([1]).disjoint(new CustomSet([]));
78
+ expect(actual).toBe(true);
79
+ });
80
+
81
+ xtest('sets are not disjoint if they share an element', () => {
82
+ const actual = new CustomSet([1, 2]).disjoint(new CustomSet([2, 3]));
83
+ expect(actual).toBe(false);
84
+ });
85
+
86
+ xtest('sets are disjoint if they share no elements', () => {
87
+ const actual = new CustomSet([1, 2]).disjoint(new CustomSet([3, 4]));
88
+ expect(actual).toBe(true);
89
+ });
56
90
  });
57
91
 
58
- xtest('can add a member with put', () => {
59
- const actual = new CustomSet([1, 2, 4]).put(3);
60
- const expected = new CustomSet([1, 2, 3, 4]);
61
- expect(actual.eql(expected)).toBe(true);
62
- const actual2 = new CustomSet([1, 2, 3]).put(3);
63
- const expected2 = new CustomSet([1, 2, 3]);
64
- expect(actual2.eql(expected2)).toBe(true);
92
+ describe('eql: sets with the same elements are equal', () => {
93
+ xtest('empty sets are equal', () => {
94
+ const actual = new CustomSet().eql(new CustomSet());
95
+ expect(actual).toBe(true);
96
+ });
97
+
98
+ xtest('empty set is not equal to non-empty set', () => {
99
+ const actual = new CustomSet().eql(new CustomSet([1, 2, 3]));
100
+ expect(actual).toBe(false);
101
+ });
102
+
103
+ xtest('non-empty set is not equal to empty set', () => {
104
+ const actual = new CustomSet([1, 2, 3]).eql(new CustomSet());
105
+ expect(actual).toBe(false);
106
+ });
107
+
108
+ xtest('sets with the same elements are equal', () => {
109
+ const actual = new CustomSet([1, 2]).eql(new CustomSet([2, 1]));
110
+ expect(actual).toBe(true);
111
+ });
112
+
113
+ xtest('sets with different elements are not equal', () => {
114
+ const actual = new CustomSet([1, 2, 3]).eql(new CustomSet([1, 2, 4]));
115
+ expect(actual).toBe(false);
116
+ });
65
117
  });
66
118
 
67
- xtest('knows its size', () => {
68
- const actual = new CustomSet().size();
69
- expect(actual).toBe(0);
70
- const actual2 = new CustomSet([1, 2, 3]).size();
71
- expect(actual2).toBe(3);
72
- const actual3 = new CustomSet([1, 2, 3, 2]).size();
73
- expect(actual3).toBe(3);
119
+ describe('add: unique elements can be added to a set', () => {
120
+ xtest('add to empty set', () => {
121
+ const actual = new CustomSet().add(3);
122
+ const expected = new CustomSet([3]);
123
+ expect(actual.eql(expected)).toBe(true);
124
+ });
125
+
126
+ xtest('add to non-empty set', () => {
127
+ const actual = new CustomSet([1, 2, 4]).add(3);
128
+ const expected = new CustomSet([1, 2, 3, 4]);
129
+ expect(actual.eql(expected)).toBe(true);
130
+ });
131
+
132
+ xtest('adding an existing element does not change the set', () => {
133
+ const actual = new CustomSet([1, 2, 3]).add(3);
134
+ const expected = new CustomSet([1, 2, 3]);
135
+ expect(actual.eql(expected)).toBe(true);
136
+ });
74
137
  });
75
138
 
76
- xtest('can test for subsets', () => {
77
- const actual = new CustomSet([1, 2, 3]).subset(new CustomSet([1, 2, 3]));
78
- expect(actual).toBe(true);
79
- const actual2 = new CustomSet([4, 1, 2, 3]).subset(new CustomSet([1, 2, 3]));
80
- expect(actual2).toBe(true);
81
- const actual3 = new CustomSet([4, 1, 3]).subset(new CustomSet([1, 2, 3]));
82
- expect(actual3).toBe(false);
83
- const actual4 = new CustomSet([4, 1, 3]).subset(new CustomSet());
84
- expect(actual4).toBe(true);
85
- const actual5 = new CustomSet().subset(new CustomSet());
86
- expect(actual5).toBe(true);
139
+ describe('intersection: returns a set of all shared elements', () => {
140
+ xtest('intersection of two empty sets is an empty set', () => {
141
+ const actual = new CustomSet().intersection(new CustomSet());
142
+ const expected = new CustomSet();
143
+ expect(actual.eql(expected)).toBe(true);
144
+ });
145
+
146
+ xtest('intersection of an empty set and non-empty set is an empty set', () => {
147
+ const actual = new CustomSet().intersection(new CustomSet([3, 2, 5]));
148
+ const expected = new CustomSet([]);
149
+ expect(actual.eql(expected)).toBe(true);
150
+ });
151
+
152
+ xtest('intersection of a non-empty set and an empty set is an empty set', () => {
153
+ const actual = new CustomSet([1, 2, 3, 4]).intersection(new CustomSet([]));
154
+ const expected = new CustomSet([]);
155
+ expect(actual.eql(expected)).toBe(true);
156
+ });
157
+
158
+ xtest('intersection of two sets with no shared elements is an empty set', () => {
159
+ const actual = new CustomSet([1, 2, 3]).intersection(new CustomSet([4, 5, 6]));
160
+ const expected = new CustomSet([]);
161
+ expect(actual.eql(expected)).toBe(true);
162
+ });
163
+
164
+ xtest('intersection of two sets with shared elements is a set of the shared elements', () => {
165
+ const actual = new CustomSet([1, 2, 3, 4]).intersection(new CustomSet([3, 2, 5]));
166
+ const expected = new CustomSet([2, 3]);
167
+ expect(actual.eql(expected)).toBe(true);
168
+ });
87
169
  });
88
170
 
89
- xtest('can give back a list', () => {
90
- const actual = new CustomSet().toList();
91
- const expected = [];
92
- expect(actual.sort()).toEqual(expected);
93
- const actual2 = new CustomSet([3, 1, 2]).toList();
94
- const expected2 = [1, 2, 3];
95
- expect(actual2.sort()).toEqual(expected2);
96
- const actual3 = new CustomSet([3, 1, 2, 1]).toList();
97
- const expected3 = [1, 2, 3];
98
- expect(actual3.sort()).toEqual(expected3);
171
+ describe('difference of a set is a set of all elements that are only in the first set', () => {
172
+ xtest('difference of two empty sets is an empty set', () => {
173
+ const actual = new CustomSet().difference(new CustomSet());
174
+ const expected = new CustomSet();
175
+ expect(actual.eql(expected)).toBe(true);
176
+ });
177
+
178
+ xtest('difference of empty set and non-empty set is an empty set', () => {
179
+ const actual = new CustomSet().difference(new CustomSet([3, 2, 5]));
180
+ const expected = new CustomSet();
181
+ expect(actual.eql(expected)).toBe(true);
182
+ });
183
+
184
+ xtest('difference of a non-empty set and an empty set is the non-empty set', () => {
185
+ const actual = new CustomSet([1, 2, 3, 4]).difference(new CustomSet());
186
+ const expected = new CustomSet([1, 2, 3, 4]);
187
+ expect(actual.eql(expected)).toBe(true);
188
+ });
189
+
190
+ xtest('difference of two non-empty sets is a set of elements that are only in the first set', () => {
191
+ const actual = new CustomSet([3, 2, 1]).difference(new CustomSet([2, 4]));
192
+ const expected = new CustomSet([1, 3]);
193
+ expect(actual.eql(expected)).toBe(true);
194
+ });
99
195
  });
100
196
 
101
- xtest('can test for union', () => {
102
- const actual = new CustomSet([1, 3]).union(new CustomSet([2]));
103
- const expected = new CustomSet([3, 2, 1]);
104
- expect(actual.eql(expected)).toBe(true);
105
- const actual2 = new CustomSet([1, 3]).union(new CustomSet([2, 3]));
106
- const expected2 = new CustomSet([3, 2, 1]);
107
- expect(actual2.eql(expected2)).toBe(true);
108
- const actual3 = new CustomSet([1, 3]).union(new CustomSet());
109
- const expected3 = new CustomSet([3, 1]);
110
- expect(actual3.eql(expected3)).toBe(true);
111
- const actual4 = new CustomSet().union(new CustomSet());
112
- const expected4 = new CustomSet();
113
- expect(actual4.eql(expected4)).toBe(true);
197
+ describe('union: returns a set of all elements in either set', () => {
198
+ xtest('union of empty sets is an empty set', () => {
199
+ const actual = new CustomSet().union(new CustomSet());
200
+ const expected = new CustomSet();
201
+ expect(actual.eql(expected)).toBe(true);
202
+ });
203
+
204
+ xtest('union of an empty set and non-empty set is the non-empty set', () => {
205
+ const actual = new CustomSet().union(new CustomSet([2]));
206
+ const expected = new CustomSet([2]);
207
+ expect(actual.eql(expected)).toBe(true);
208
+ });
209
+
210
+ xtest('union of a non-empty set and empty set is the non-empty set', () => {
211
+ const actual = new CustomSet([1, 3]).union(new CustomSet());
212
+ const expected = new CustomSet([1, 3]);
213
+ expect(actual.eql(expected)).toBe(true);
214
+ });
215
+
216
+ xtest('union of non-empty sets contains all unique elements', () => {
217
+ const actual = new CustomSet([1, 3]).union(new CustomSet([2, 3]));
218
+ const expected = new CustomSet([1, 2, 3]);
219
+ expect(actual.eql(expected)).toBe(true);
220
+ });
114
221
  });
115
222
  });
@@ -1,11 +1,12 @@
1
1
  export default class CustomSet {
2
2
  constructor(data = []) {
3
3
  this.data = {};
4
- data.forEach(el => this.put(el));
5
- this.comparator = typeof data[0] === 'number' ?
6
- (a, b) => a - b
7
- : (a, b) => b <= a
8
- ? 1 : -1;
4
+ data.forEach(el => this.add(el));
5
+ }
6
+
7
+ add(el) {
8
+ this.data[el] = el;
9
+ return this;
9
10
  }
10
11
 
11
12
  delete(el) {
@@ -13,8 +14,20 @@ export default class CustomSet {
13
14
  return this;
14
15
  }
15
16
 
17
+ size() {
18
+ return Object.keys(this.data).length;
19
+ }
20
+
21
+ empty() {
22
+ return this.size() === 0;
23
+ }
24
+
25
+ contains(el) {
26
+ return this.data[el] !== undefined;
27
+ }
28
+
16
29
  eql(other) {
17
- return this.difference(other).size() === 0;
30
+ return this.size() === other.size() && this.difference(other).size() === 0;
18
31
  }
19
32
 
20
33
  difference(other) {
@@ -30,36 +43,14 @@ export default class CustomSet {
30
43
  }
31
44
 
32
45
  union(other) {
33
- return new CustomSet(this.toList().concat(this.difference(other).toList()));
46
+ return new CustomSet(this.toList().concat(other.toList()));
34
47
  }
35
48
 
36
49
  subset(other) {
37
- return other.eql(this.intersection(other));
50
+ return this.eql(this.intersection(other));
38
51
  }
39
52
 
40
53
  toList() {
41
- return Object.keys(this.data).map(el => +el);
42
- }
43
-
44
- member(el) {
45
- return this.data[el] !== undefined;
46
- }
47
-
48
- put(value) {
49
- this.data[value] = value;
50
- return this;
51
- }
52
-
53
- sort() {
54
- this.data.sort(this.comparator);
55
- }
56
-
57
- size() {
58
- return Object.keys(this.data).length;
59
- }
60
-
61
- empty() {
62
- this.data = {};
63
- return this;
54
+ return Object.values(this.data);
64
55
  }
65
56
  }