trackler 2.0.6.16 → 2.0.6.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 93c7f99da67e82bacb69b2baa1335f4fe2fcc2da
4
- data.tar.gz: 789b2e7a4936b344dcefb2dcf594d603889c762f
3
+ metadata.gz: 7c9fb8ec96523d44264d1bf0b40ac46df372476e
4
+ data.tar.gz: 1397df691f26c2341401fe216a78ab3bbe533eb2
5
5
  SHA512:
6
- metadata.gz: d558ac9c0cea44feb34714b50a7447eda5c3cc0ff7f3ac6c8e9e357f073117ea060ae7b3867d3be38d2f37903275c5b07196bc1c6870754956c7081bb5a33bb0
7
- data.tar.gz: d206b1b48daee6f9d5a178f4c50dadec5874bfbf42a0103671bdae92d5994c2c2d116ba6f0e119d538c2204a1b2ddd0c9f8e459c4d2bc0982bb5d5efb6b7bf0b
6
+ metadata.gz: dcda4af88a5631881d96e39a4c0f300fc92dc50d54f10a98d70bfeca546be73de9c4b7da0b86047affd413fc63145aa8ce0703ee7b0bcb434d3fc884f8746857
7
+ data.tar.gz: c049d690afb0c20c6c190df3d80a7b6568aa47afa54c46ea5286bb772b04c61ab4e209d112afd3f1368419d5970d806ab7e5240a33fb335a55c490ca451dfd84
@@ -1,3 +1,3 @@
1
1
  module Trackler
2
- VERSION = "2.0.6.16"
2
+ VERSION = "2.0.6.17"
3
3
  end
@@ -1,57 +1,34 @@
1
- export default class Luhn {
2
-
3
- constructor(number) {
4
- this.checkDigit = number % 10;
5
- this.addends = Luhn.calculateAddends(number);
6
- this.checksum = Luhn.calculateChecksum(this.addends);
7
- this.valid = Luhn.determineIfValid(this.checksum);
8
- }
9
-
10
- static calculateAddends(number) {
11
- const numberAsString = '' + number + '',
12
- numbers = [...numberAsString],
13
- addends = [];
14
-
15
- for (let i = 0; i < numbers.length; i++) {
16
- const index = numbers.length - 1 - i;
17
- let currentAddend = parseInt(numbers[index], 10);
18
-
19
- if ((i + 1) % 2 === 0) {
20
- currentAddend = currentAddend * 2;
21
- if (currentAddend > 10) {
22
- currentAddend = currentAddend - 9;
23
- }
1
+ function isValid(number) {
2
+ number = number.replace(/\s/g, '');
3
+ const digits = [...number];
4
+
5
+ const sum = digits
6
+ // convert to integers
7
+ .map(d => parseInt(d, 10))
8
+ // double even positions (odd indexes)
9
+ .map((d, i) => {
10
+ if (i % 2 !== 0) {
11
+ return d * 2;
24
12
  }
25
- addends.push(currentAddend);
26
- }
27
- return addends.reverse();
28
- }
29
-
30
- static calculateChecksum(numbers) {
31
- let sum = 0;
32
- for (let i = 0; i < numbers.length; i++) {
33
- sum += numbers[i];
34
- }
35
- return sum;
36
- }
13
+ return d;
14
+ })
15
+ // limit to digits less than 10
16
+ .map(d => {
17
+ if (d > 9) {
18
+ return d - 9;
19
+ }
20
+ return d;
21
+ })
22
+ // sum all digits
23
+ .reduce((d, acc) => d + acc, 0);
37
24
 
38
- static determineIfValid(sum) {
39
- return sum % 10 === 0;
40
- }
25
+ return sum > 0 && sum % 10 === 0;
26
+ }
41
27
 
42
- static create(number) {
43
- let finalNumber = number * 10,
44
- luhnNumber = new Luhn(finalNumber),
45
- index = 0;
28
+ export default class Luhn {
46
29
 
47
- while (!luhnNumber.valid) {
48
- finalNumber = number * 10 + index;
49
- luhnNumber = new Luhn(finalNumber);
50
- if (luhnNumber.valid) {
51
- break;
52
- }
53
- index += 1;
54
- }
55
- return finalNumber;
30
+ constructor(number) {
31
+ this.valid = isValid(number);
56
32
  }
33
+
57
34
  }
@@ -2,59 +2,34 @@ import Luhn from './luhn';
2
2
 
3
3
  describe('Luhn',() => {
4
4
 
5
- it('check digit',() => {
6
- const luhn = new Luhn(34567);
7
- expect(luhn.checkDigit).toEqual(7);
8
- });
9
-
10
- xit('check digit again',() => {
11
- const luhn = new Luhn(91370);
12
- expect(luhn.checkDigit).toEqual(0);
13
- });
14
-
15
- xit('addends',() => {
16
- const luhn = new Luhn(12121);
17
- expect(luhn.addends).toEqual([1, 4, 1, 4, 1]);
18
- });
19
-
20
- xit('too large added',() => {
21
- const luhn = new Luhn(8631);
22
- expect(luhn.addends).toEqual([7, 6, 6, 1]);
23
- });
24
-
25
- xit('checksum',() => {
26
- const luhn = new Luhn(4913);
27
- expect(luhn.checksum).toEqual(22);
28
- });
29
-
30
- xit('checksum again',() => {
31
- const luhn = new Luhn(201773);
32
- expect(luhn.checksum).toEqual(21);
5
+ it('single digit strings can not be valid', () => {
6
+ const luhn = new Luhn('1');
7
+ expect(luhn.valid).toEqual(false);
33
8
  });
34
9
 
35
- xit('invalid number',() => {
36
- const luhn = new Luhn(738);
10
+ xit('A single zero is invalid', () => {
11
+ const luhn = new Luhn('0');
37
12
  expect(luhn.valid).toEqual(false);
38
13
  });
39
14
 
40
- xit('invalid number',() => {
41
- const luhn = new Luhn(8739567);
15
+ xit('valid Canadian SIN', () => {
16
+ const luhn = new Luhn('046 454 286');
42
17
  expect(luhn.valid).toEqual(true);
43
18
  });
44
19
 
45
- xit('create valid number',() => {
46
- const number = Luhn.create(123);
47
- expect(number).toEqual(1230);
20
+ xit('invalid Canadian SIN', () => {
21
+ const luhn = new Luhn('046 454 287');
22
+ expect(luhn.valid).toEqual(false);
48
23
  });
49
24
 
50
- xit('create other valid number',() => {
51
- const number = Luhn.create(873956);
52
- expect(number).toEqual(8739567);
25
+ xit('invalid credit card', () => {
26
+ const luhn = new Luhn('8273 1232 7352 0569');
27
+ expect(luhn.valid).toEqual(false);
53
28
  });
54
29
 
55
- xit('create yet another valid number',() => {
56
- const number = Luhn.create(837263756);
57
- expect(number).toEqual(8372637564);
30
+ xit('valid strings with a non-digit added become invalid', () => {
31
+ const luhn = new Luhn('046a 454 286');
32
+ expect(luhn.valid).toEqual(false);
58
33
  });
59
34
 
60
35
  });
@@ -25,7 +25,7 @@ let ``Encode random uses randomly generated key`` () =
25
25
  let keys = List.init 100 (fun _ -> encodeRandom plainText |> fst)
26
26
  Assert.That(keys |> List.distinct, Is.EqualTo(keys))
27
27
 
28
- // Here we take advantage of the fact that plaintext of "aaa..." doesn't output
28
+ // Here we take advantage of the fact that plaintext of "aaa..." outputs
29
29
  // the key. This is a critical problem with shift ciphers, some characters
30
30
  // will always output the key verbatim.
31
31
  [<Test>]
@@ -62,6 +62,7 @@ let ``Cipher is reversible given key`` () =
62
62
  Assert.That(encode key plainText |> decode key, Is.EqualTo(plainText))
63
63
 
64
64
  [<Test>]
65
+ [<Ignore("Remove to run test")>]
65
66
  let ``Cipher can double shift encode`` () =
66
67
  let plainText = "iamapandabear"
67
68
  Assert.That(encode plainText plainText, Is.EqualTo("qayaeaagaciai"))
@@ -109,4 +110,4 @@ let ``Encode throws with any numeric key`` () =
109
110
  [<Ignore("Remove to run test")>]
110
111
  let ``Encode throws with empty key`` () =
111
112
  let key = ""
112
- Assert.That((fun () -> encode key plainText |> ignore), Throws.Exception)
113
+ Assert.That((fun () -> encode key plainText |> ignore), Throws.Exception)
@@ -1,368 +1,223 @@
1
1
  package stringset
2
2
 
3
3
  // Source: exercism/x-common
4
- // Commit: 269f498 Merge pull request #48 from soniakeys/custom-set-json
4
+ // Commit: cda8f98 Create new exercises structure
5
5
 
6
- // Test two sets for equality.
7
- var eqCases = []binBoolCase{
8
- { // order doesn't matter
9
- []string{"a", "c"},
10
- []string{"c", "a"},
11
- true,
12
- },
13
- { // dupicates don't matter
14
- []string{"a", "a"},
15
- []string{"a"},
16
- true,
17
- },
18
- { // empty sets are equal
19
- []string{},
20
- []string{},
21
- true,
22
- },
23
- { // set with single element is equal to itself
24
- []string{"a"},
25
- []string{"a"},
26
- true,
27
- },
28
- { // different sets are not equal
29
- []string{"a", "b", "c"},
30
- []string{"c", "d", "e"},
31
- false,
32
- },
33
- { // empty set is not equal to non-empty set
34
- []string{},
35
- []string{"a", "b", "c"},
36
- false,
37
- },
38
- { // non-empty set is not equal to empty set
39
- []string{"a", "b", "c"},
40
- []string{},
41
- false,
42
- },
43
- { // having most in common is not good enough
44
- []string{"a", "b", "c", "d"},
45
- []string{"b", "c", "d", "e"},
46
- false,
47
- },
48
- }
49
-
50
- // Add an element to a set.
51
- var addCases = []eleOpCase{
52
- { // add to empty set
53
- []string{},
54
- "c",
55
- []string{"c"},
56
- },
57
- { // add to non-empty set
58
- []string{"a", "b", "d"},
59
- "c",
60
- []string{"a", "b", "c", "d"},
61
- },
62
- { // add existing element
63
- []string{"a", "b", "c"},
64
- "c",
65
- []string{"a", "b", "c"},
66
- },
67
- }
68
-
69
- // Delete an element from a set.
70
- var delCases = []eleOpCase{
71
- { // delete an element
72
- []string{"c", "b", "a"},
73
- "b",
74
- []string{"a", "c"},
75
- },
76
- { // delete an element not in set
77
- []string{"c", "b", "a"},
78
- "d",
79
- []string{"a", "b", "c"},
80
- },
81
- }
82
-
83
- // Test if is a set is empty.
6
+ // Returns true if the set contains no elements
84
7
  var emptyCases = []unaryBoolCase{
85
- { // empty
8
+ { // sets with no elements are empty
86
9
  []string{},
87
10
  true,
88
11
  },
89
- { // single element
12
+ { // sets with elements are not empty
90
13
  []string{"a"},
91
14
  false,
92
15
  },
93
- { // a few elements
94
- []string{"a", "b", "c", "b"},
95
- false,
96
- },
97
- }
98
-
99
- // Return the cardinality of a set.
100
- var lenCases = []unaryIntCase{
101
- { // empty set
102
- []string{},
103
- 0,
104
- },
105
- { // non-empty set
106
- []string{"a", "b", "c"},
107
- 3,
108
- },
109
- { // duplicate element
110
- []string{"a", "b", "c", "b"},
111
- 3,
112
- },
113
16
  }
114
17
 
115
- // Test if a value is an element of a set.
18
+ // Sets can report if they contain an element
116
19
  var hasCases = []eleBoolCase{
117
- { // nothing is an element of the empty set
20
+ { // nothing is contained in an empty set
118
21
  []string{},
119
22
  "a",
120
23
  false,
121
24
  },
122
- { // 1 is in the set
123
- []string{"a", "b", "c", "b"},
25
+ { // when the element is in the set
26
+ []string{"a", "b", "c"},
124
27
  "a",
125
28
  true,
126
29
  },
127
- { // 2 is in the set
128
- []string{"a", "b", "c", "b"},
129
- "b",
130
- true,
131
- },
132
- { // 3 is in the set
133
- []string{"a", "b", "c", "b"},
134
- "c",
135
- true,
136
- },
137
- { // 4 not in the set
138
- []string{"a", "b", "c", "b"},
30
+ { // when the element is not in the set
31
+ []string{"a", "b", "c"},
139
32
  "d",
140
33
  false,
141
34
  },
142
35
  }
143
36
 
144
- // Test if set1 is a subset of set2.
37
+ // A set is a subset if all of its elements are contained in the other set
145
38
  var subsetCases = []binBoolCase{
146
- { // empty set is subset of itself
39
+ { // empty set is a subset of another empty set
147
40
  []string{},
148
41
  []string{},
149
42
  true,
150
43
  },
151
- { // empty set is subset of non-empty set
44
+ { // empty set is a subset of non-empty set
152
45
  []string{},
153
46
  []string{"a"},
154
47
  true,
155
48
  },
156
- { // non-empty set is not subset of empty set
49
+ { // non-empty set is not a subset of empty set
157
50
  []string{"a"},
158
51
  []string{},
159
52
  false,
160
53
  },
161
- { // non-empty set is subset of itself
54
+ { // set is a subset of set with exact same elements
162
55
  []string{"a", "b", "c"},
163
56
  []string{"a", "b", "c"},
164
57
  true,
165
58
  },
166
- { // proper subset
59
+ { // set is a subset of larger set with same elements
167
60
  []string{"a", "b", "c"},
168
61
  []string{"d", "a", "b", "c"},
169
62
  true,
170
63
  },
171
- { // same number of elements
64
+ { // set is not a subset of set that does not contain its elements
172
65
  []string{"a", "b", "c"},
173
66
  []string{"d", "a", "c"},
174
67
  false,
175
68
  },
176
- { // superset
177
- []string{"a", "b", "c", "d", "e"},
178
- []string{"b", "c", "d"},
179
- false,
180
- },
181
- { // fewer elements but not a subset
182
- []string{"a", "b", "c", "k"},
183
- []string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"},
184
- false,
185
- },
186
69
  }
187
70
 
188
- // Test if two sets are disjoint.
71
+ // Sets are disjoint if they share no elements
189
72
  var disjointCases = []binBoolCase{
190
73
  { // the empty set is disjoint with itself
191
74
  []string{},
192
75
  []string{},
193
76
  true,
194
77
  },
195
- { // empty set disjoint with non-empty set
78
+ { // empty set is disjoint with non-empty set
196
79
  []string{},
197
80
  []string{"a"},
198
81
  true,
199
82
  },
200
- { // non-empty set disjoint with empty set
83
+ { // non-empty set is disjoint with empty set
201
84
  []string{"a"},
202
85
  []string{},
203
86
  true,
204
87
  },
205
- { // one element in common
88
+ { // sets are not disjoint if they share an element
206
89
  []string{"a", "b"},
207
90
  []string{"b", "c"},
208
91
  false,
209
92
  },
210
- { // no elements in common
93
+ { // sets are disjoint if they share no elements
211
94
  []string{"a", "b"},
212
95
  []string{"c", "d"},
213
96
  true,
214
97
  },
215
98
  }
216
99
 
217
- // Produce the union of two sets.
218
- var unionCases = []binOpCase{
219
- { // union of empty sets
220
- []string{},
221
- []string{},
100
+ // Sets with the same elements are equal
101
+ var eqCases = []binBoolCase{
102
+ { // empty sets are equal
222
103
  []string{},
223
- },
224
- { // union of empty set with set of one element
225
104
  []string{},
226
- []string{"b"},
227
- []string{"b"},
105
+ true,
228
106
  },
229
- { // union of empty set with non-empty set
107
+ { // empty set is not equal to non-empty set
230
108
  []string{},
231
- []string{"c", "b", "e"},
232
- []string{"b", "c", "e"},
109
+ []string{"a", "b", "c"},
110
+ false,
233
111
  },
234
- { // union of non-empty set with empty set
235
- []string{"a", "c"},
112
+ { // non-empty set is not equal to empty set
113
+ []string{"a", "b", "c"},
236
114
  []string{},
237
- []string{"a", "c"},
115
+ false,
238
116
  },
239
- { // union of a set with itself
240
- []string{"a", "c"},
241
- []string{"c", "a"},
242
- []string{"a", "c"},
117
+ { // sets with the same elements are equal
118
+ []string{"a", "b"},
119
+ []string{"b", "a"},
120
+ true,
243
121
  },
244
- { // union with one element
245
- []string{"a", "c"},
246
- []string{"b"},
122
+ { // sets with different elements are not equal
247
123
  []string{"a", "b", "c"},
124
+ []string{"a", "b", "d"},
125
+ false,
248
126
  },
249
- { // one element in common, one different
250
- []string{"a", "c"},
251
- []string{"b", "c"},
252
- []string{"c", "b", "a"},
127
+ }
128
+
129
+ // Unique elements can be added to a set
130
+ var addCases = []eleOpCase{
131
+ { // add to empty set
132
+ []string{},
133
+ "c",
134
+ []string{"c"},
253
135
  },
254
- { // two elements in common
136
+ { // add to non-empty set
137
+ []string{"a", "b", "d"},
138
+ "c",
255
139
  []string{"a", "b", "c", "d"},
256
- []string{"c", "b", "e"},
257
- []string{"a", "b", "c", "d", "e"},
140
+ },
141
+ { // adding an existing element does not change the set
142
+ []string{"a", "b", "c"},
143
+ "c",
144
+ []string{"a", "b", "c"},
258
145
  },
259
146
  }
260
147
 
261
- // Intersect two sets.
148
+ // Intersect returns a set of all shared elements
262
149
  var intersectionCases = []binOpCase{
263
- { // intersect empty sets
150
+ { // intersection of two empty sets is an empty set
264
151
  []string{},
265
152
  []string{},
266
153
  []string{},
267
154
  },
268
- { // intersect empty set with non-empty set
155
+ { // intersection of an empty set and non-empty set is an empty set
269
156
  []string{},
270
157
  []string{"c", "b", "e"},
271
158
  []string{},
272
159
  },
273
- { // intersect non-empty set with empty set
160
+ { // intersection of a non-empty set and an empty set is an empty set
274
161
  []string{"a", "b", "c", "d"},
275
162
  []string{},
276
163
  []string{},
277
164
  },
278
- { // intersect one element with itself
279
- []string{"c"},
280
- []string{"c"},
281
- []string{"c"},
282
- },
283
- { // one element in common, extra elements in both sets
165
+ { // intersection of two sets with no shared elements is an empty set
284
166
  []string{"a", "b", "c"},
285
- []string{"c", "e", "d"},
286
- []string{"c"},
167
+ []string{"d", "e", "f"},
168
+ []string{},
287
169
  },
288
- { // two elements in common, extras in both sets
170
+ { // intersection of two sets with shared elements is a set of the shared elements
289
171
  []string{"a", "b", "c", "d"},
290
172
  []string{"c", "b", "e"},
291
173
  []string{"b", "c"},
292
174
  },
293
- { // intersect with subset
294
- []string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"},
295
- []string{"e", "f", "g", "h", "i", "j"},
296
- []string{"e", "f", "g", "h", "i", "j"},
297
- },
298
- { // nothing in common
299
- []string{"a", "b", "c"},
300
- []string{"d", "e", "f"},
301
- []string{},
302
- },
303
175
  }
304
176
 
305
- // Produce the set difference (set1 - set2)
306
- // or more specifically, (set1 ∖ set2)
177
+ // Difference (or Complement) of a set is a set of all elements that are only in the first set
307
178
  var differenceCases = []binOpCase{
308
- { // difference of two empty sets
179
+ { // difference of two empty sets is an empty set
309
180
  []string{},
310
181
  []string{},
311
182
  []string{},
312
183
  },
313
- { // difference of empty set and non-empty set
184
+ { // difference of empty set and non-empty set is an empty set
314
185
  []string{},
315
186
  []string{"c", "b", "e"},
316
187
  []string{},
317
188
  },
318
- { // difference of non-empty set and empty set
189
+ { // difference of a non-empty set and an empty set is the non-empty set
319
190
  []string{"a", "b", "c", "d"},
320
191
  []string{},
321
192
  []string{"a", "b", "c", "d"},
322
193
  },
323
- { // no elements in common
324
- []string{"a", "b", "c"},
325
- []string{"d"},
326
- []string{"a", "b", "c"},
327
- },
328
- { // one element in common, one extra
194
+ { // difference of two non-empty sets is a set of elements that are only in the first set
329
195
  []string{"c", "b", "a"},
330
196
  []string{"b", "d"},
331
197
  []string{"a", "c"},
332
198
  },
333
- { // two elements in common, one extra
334
- []string{"a", "b", "c", "d"},
335
- []string{"c", "b", "e"},
336
- []string{"a", "d"},
337
- },
338
199
  }
339
200
 
340
- // Produce the symmetric difference of two sets. The symmetric
341
- // difference consists of elements in one or the other but not both.
342
- var symmetricDifferenceCases = []binOpCase{
343
- { // two empty sets
201
+ // Union returns a set of all elements in either set
202
+ var unionCases = []binOpCase{
203
+ { // union of empty sets is an empty set
344
204
  []string{},
345
205
  []string{},
346
206
  []string{},
347
207
  },
348
- { // empty set and non-empty set
208
+ { // union of an empty set and non-empty set is the non-empty set
349
209
  []string{},
350
- []string{"c", "b", "e"},
351
- []string{"c", "b", "e"},
210
+ []string{"b"},
211
+ []string{"b"},
352
212
  },
353
- { // non-empty set and empty set
354
- []string{"a", "b", "c", "d"},
213
+ { // union of a non-empty set and empty set is the non-empty set
214
+ []string{"a", "c"},
355
215
  []string{},
356
- []string{"a", "b", "c", "d"},
357
- },
358
- { // no elements in common
359
- []string{"a", "b", "c"},
360
- []string{"d"},
361
- []string{"a", "b", "c", "d"},
216
+ []string{"a", "c"},
362
217
  },
363
- { // one element in common
218
+ { // union of non-empty sets contains all unique elements
219
+ []string{"a", "c"},
220
+ []string{"b", "c"},
364
221
  []string{"c", "b", "a"},
365
- []string{"b", "d"},
366
- []string{"a", "c", "d"},
367
222
  },
368
223
  }