trackler 2.2.1.70 → 2.2.1.71

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/lib/trackler/version.rb +1 -1
  3. data/tracks/c/exercises/all-your-base/src/example.c +1 -1
  4. data/tracks/c/exercises/beer-song/src/example.c +2 -2
  5. data/tracks/c/exercises/meetup/src/example.c +3 -4
  6. data/tracks/c/exercises/nucleotide-count/src/example.c +1 -1
  7. data/tracks/c/exercises/raindrops/src/example.c +1 -1
  8. data/tracks/c/exercises/sieve/src/example.c +1 -2
  9. data/tracks/delphi/docs/EXERCISE_README_INSERT.md +1 -1
  10. data/tracks/java/exercises/binary-search-tree/.meta/src/reference/java/BinarySearchTree.java +8 -8
  11. data/tracks/java/exercises/book-store/.meta/src/reference/java/BookStore.java +30 -30
  12. data/tracks/java/exercises/bowling/.meta/src/reference/java/BowlingGame.java +4 -4
  13. data/tracks/java/exercises/bowling/src/test/java/BowlingTest.java +11 -11
  14. data/tracks/java/exercises/collatz-conjecture/src/main/java/CollatzCalculator.java +7 -0
  15. data/tracks/java/exercises/difference-of-squares/src/main/java/DifferenceOfSquaresCalculator.java +15 -0
  16. data/tracks/python/exercises/beer-song/example.py +8 -6
  17. data/tracks/python/exercises/clock/example.py +1 -1
  18. data/tracks/python/exercises/nucleotide-count/example.py +1 -1
  19. data/tracks/python/exercises/phone-number/example.py +3 -3
  20. data/tracks/python/exercises/protein-translation/example.py +1 -1
  21. data/tracks/python/exercises/say/example.py +1 -1
  22. data/tracks/python/exercises/two-fer/example.py +1 -1
  23. data/tracks/ruby/exercises/minesweeper/.meta/solutions/minesweeper.rb +3 -5
  24. data/tracks/ruby/exercises/minesweeper/minesweeper_test.rb +3 -3
  25. data/tracks/scala/config.json +12 -12
  26. data/tracks/scala/exercises/flatten-array/src/test/scala/FlattenArrayTest.scala +7 -10
  27. data/tracks/scala/testgen/src/main/scala/FlattenArrayTestGenerator.scala +44 -0
  28. metadata +5 -4
  29. data/tracks/java/exercises/collatz-conjecture/src/main/java/.keep +0 -0
  30. data/tracks/java/exercises/difference-of-squares/src/main/java/.keep +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: db1dac190572a67ad1c9066086bc27f651d43512
4
- data.tar.gz: e7f6a561bcfec5e8f015f3f234592119a786764f
3
+ metadata.gz: 035f344758e70ee0d97c2246e5cfdf0878ec339b
4
+ data.tar.gz: 7b52f923df0cb958c251e599a75de951173521ee
5
5
  SHA512:
6
- metadata.gz: d881520b55a7e22887cb9cf931583c9d84db97deda9bbe370ab89a3ae2ff9782cd05f31947246fa2874803229c0a54fc87126488ed5b011ed232fac9127d4929
7
- data.tar.gz: 970a8aed655deaf30103ccf71a6891350aefbad2263c4e5f9950e753b3e8fa55dcccaf79083db80fcab3a69e253ddb57dff30b79242e5c546841d9d3170691a1
6
+ metadata.gz: cdbc6ff2470de2c426509584b99d3853b3f59c25f6942883f8902a3acc8baae255f23b8f202758f3ea646d63c98d11acec4cedf6c78d5c64731737390b0ebb99
7
+ data.tar.gz: a47dc3a6adc5811139e22b25216924c2b669088bc12def99668fb36fec8cc69dbbb8571b4281981c5bdb427cb9373289e931c6df766732230dabafd286cb3cb8
@@ -1,3 +1,3 @@
1
1
  module Trackler
2
- VERSION = "2.2.1.70"
2
+ VERSION = "2.2.1.71"
3
3
  end
@@ -8,7 +8,7 @@ size_t rebase(int8_t digits[DIGITS_ARRAY_SIZE], int16_t from_base,
8
8
  uint16_t denary = 0;
9
9
  size_t new_num_digits = 0;
10
10
 
11
- if ((from_base <= 1) || (to_base <= 1) || (num_digits <= 0))
11
+ if ((from_base <= 1) || (to_base <= 1) || (num_digits == 0))
12
12
  return 0; /* invalid bases or length */
13
13
  if (digits[0] == 0)
14
14
  return 0; /* leading zeros */
@@ -24,8 +24,8 @@ static unsigned int get_verse(char *buffer, unsigned int verse_number)
24
24
  } else if (verse_number <= 99) {
25
25
  bytes_written =
26
26
  sprintf(buffer,
27
- "%d bottles of beer on the wall, %d bottles of beer.\n"
28
- "Take one down and pass it around, %d bottles of beer on the wall.\n",
27
+ "%u bottles of beer on the wall, %u bottles of beer.\n"
28
+ "Take one down and pass it around, %u bottles of beer on the wall.\n",
29
29
  verse_number, verse_number, verse_number - 1);
30
30
  }
31
31
 
@@ -108,16 +108,15 @@ int meetup_day_of_month(unsigned int year, unsigned int month, const char *week,
108
108
  const char *day_of_week)
109
109
  {
110
110
  int day_of_month = BAD_DATE_REQUESTED;
111
- int baseline_day_of_week;
112
111
  int days_in_test_month = days_in_month(year, month);
113
- int day_offset;
114
- int reference_day = 1; // used to calculate a baseline day of week given a target date.
115
112
 
116
113
  int which_week_of_month = get_week_of_month(week);
117
114
  int target_day_in_week = get_requested_day_of_week(day_of_week);
118
115
 
119
116
  // check for valid lookup...
120
117
  if ((which_week_of_month >= 0) && (target_day_in_week >= 0)) {
118
+ int day_offset;
119
+ int reference_day = 1; // used to calculate a baseline day of week given a target date.
121
120
  // first - fifth Xday of month
122
121
  if (which_week_of_month <= 5) {
123
122
  day_offset = 1 + ((which_week_of_month - 1) * 7);
@@ -130,7 +129,7 @@ int meetup_day_of_month(unsigned int year, unsigned int month, const char *week,
130
129
  }
131
130
  day_offset = reference_day;
132
131
  }
133
- baseline_day_of_week =
132
+ int baseline_day_of_week =
134
133
  get_day_of_week_from_date(year, month, reference_day);
135
134
  day_of_month =
136
135
  day_offset + ((target_day_in_week + 7 - baseline_day_of_week) % 7);
@@ -36,7 +36,7 @@ char *count(const char *dna_strand)
36
36
  }
37
37
 
38
38
  if (!invalid_char) {
39
- sprintf(count_results, "A:%zd C:%zd G:%zd T:%zd", nucleotide_a_count,
39
+ sprintf(count_results, "A:%zu C:%zu G:%zu T:%zu", nucleotide_a_count,
40
40
  nucleotide_c_count, nucleotide_g_count, nucleotide_t_count);
41
41
  }
42
42
  return count_results;
@@ -15,7 +15,7 @@ char *convert(char result[], int drops)
15
15
  strcat(result, "Plong");
16
16
  }
17
17
  if (strlen(result) == 0) {
18
- char drops_string[12] = "";
18
+ char drops_string[12] = "\0";
19
19
  sprintf(drops_string, "%d", drops);
20
20
  strcat(result, drops_string);
21
21
  }
@@ -6,14 +6,13 @@
6
6
  unsigned int sieve(const unsigned int limit, primes_array_t primes)
7
7
  {
8
8
  unsigned int number_of_primes = 0;
9
- unsigned char *number_is_prime;
10
9
 
11
10
  // clear the results
12
11
  memset(primes, 0, sizeof(*primes));
13
12
 
14
13
  if (limit > 1) {
15
14
  //allocate 1 more than limit for convenience so the number and the index are same
16
- number_is_prime = malloc(limit + 1);
15
+ unsigned char *number_is_prime = malloc(limit + 1);
17
16
  memset(number_is_prime, 1, limit + 1);
18
17
 
19
18
  unsigned int max_factor = sqrt(limit) + 1;
@@ -1,7 +1,7 @@
1
1
  ## Testing
2
2
 
3
3
  In order to run the tests for this track, you will need to install
4
- DUnitX. Please see the [installation](http://www.exercism.io/languages/delphi/installing) instructions for more information.
4
+ DUnitX. Please see the [installation](http://www.exercism.io/languages/delphi/installation) instructions for more information.
5
5
 
6
6
  ### Loading Exercises into Delphi
7
7
 
@@ -9,20 +9,20 @@ class BinarySearchTree<T extends Comparable<T>> {
9
9
  if (root == null) {
10
10
  root = new Node<>(value);
11
11
  } else {
12
- this.insert(this.root, value);
12
+ insert(root, value);
13
13
  }
14
- this.nodeCount++;
14
+ nodeCount++;
15
15
  }
16
16
 
17
17
  List<T> getAsSortedList() {
18
- List<T> result = new ArrayList<>(this.nodeCount);
19
- this.putInSortedOrderToList(this.root, result);
18
+ List<T> result = new ArrayList<>(nodeCount);
19
+ putInSortedOrderToList(root, result);
20
20
  return Collections.unmodifiableList(result);
21
21
  }
22
22
 
23
23
  List<T> getAsLevelOrderList() {
24
- List<T> result = new ArrayList<>(this.nodeCount);
25
- this.putInLevelOrderToList(this.root, result);
24
+ List<T> result = new ArrayList<>(nodeCount);
25
+ putInLevelOrderToList(root, result);
26
26
  return Collections.unmodifiableList(result);
27
27
  }
28
28
 
@@ -33,13 +33,13 @@ class BinarySearchTree<T extends Comparable<T>> {
33
33
  private void insert(Node<T> node, T value) {
34
34
  if (value.compareTo(node.getData()) <= 0) {
35
35
  if (node.getLeft() == null) {
36
- node.setLeft(new Node<T>(value));
36
+ node.setLeft(new Node<>(value));
37
37
  } else {
38
38
  insert(node.getLeft(), value);
39
39
  }
40
40
  } else {
41
41
  if (node.getRight() == null) {
42
- node.setRight(new Node<T>(value));
42
+ node.setRight(new Node<>(value));
43
43
  } else {
44
44
  insert(node.getRight(), value);
45
45
  }
@@ -4,47 +4,47 @@ import java.util.stream.Collectors;
4
4
 
5
5
  class BookStore {
6
6
 
7
- private static final int BOOK_PRICE = 8, MAX_GROUP_SIZE = 5;
7
+ private static final int BOOK_PRICE = 8, MAX_GROUP_SIZE = 5;
8
8
 
9
- private static double[] DISCOUNT_TIERS = {0, 5, 10, 20, 25};
9
+ private static double[] DISCOUNT_TIERS = {0, 5, 10, 20, 25};
10
10
 
11
- double calculateBasketCost(final List<Integer> books) {
12
- return calculateBasketCost(books, 0);
13
- }
14
-
15
- private double calculateBasketCost(final List<Integer> books, final double priceSoFar) {
16
- if (books.size() == 0) {
17
- return priceSoFar;
11
+ double calculateBasketCost(final List<Integer> books) {
12
+ return calculateBasketCost(books, 0);
18
13
  }
19
14
 
20
- List<Integer> availableBookNumbers = books.stream()
21
- .distinct()
22
- .collect(Collectors.toList());
15
+ private double calculateBasketCost(final List<Integer> books, final double priceSoFar) {
16
+ if (books.size() == 0) {
17
+ return priceSoFar;
18
+ }
23
19
 
24
- double minPrice = Double.MAX_VALUE;
20
+ List<Integer> availableBookNumbers = books.stream()
21
+ .distinct()
22
+ .collect(Collectors.toList());
25
23
 
26
- for (int i = 0; i < availableBookNumbers.size(); i++) {
27
- List<Integer> newGroupBooks = new ArrayList<>(availableBookNumbers.subList(0, i + 1));
28
- List<Integer> remainingBooks = new ArrayList<>(books);
24
+ double minPrice = Double.MAX_VALUE;
29
25
 
30
- for (final Integer newGroupBook : newGroupBooks) {
31
- //noinspection UseBulkOperation - we want to remove _one_ of each book number, not _all_ of each book number.
32
- remainingBooks.remove(newGroupBook);
33
- }
26
+ for (int i = 0; i < availableBookNumbers.size(); i++) {
27
+ List<Integer> newGroupBooks = new ArrayList<>(availableBookNumbers.subList(0, i + 1));
28
+ List<Integer> remainingBooks = new ArrayList<>(books);
34
29
 
35
- double price = calculateBasketCost(remainingBooks, priceSoFar + costOfGroupSize(newGroupBooks.size()));
36
- minPrice = Math.min(minPrice, price);
37
- }
30
+ for (final Integer newGroupBook : newGroupBooks) {
31
+ //noinspection UseBulkOperation - we want to remove _one_ of each book number, not _all_ of each book number.
32
+ remainingBooks.remove(newGroupBook);
33
+ }
38
34
 
39
- return minPrice;
40
- }
35
+ double price = calculateBasketCost(remainingBooks, priceSoFar + costOfGroupSize(newGroupBooks.size()));
36
+ minPrice = Math.min(minPrice, price);
37
+ }
41
38
 
42
- private double costOfGroupSize(int groupSize) {
43
- if (groupSize < 1 || groupSize > MAX_GROUP_SIZE) {
44
- throw new IllegalStateException("Invalid group size : " + groupSize);
39
+ return minPrice;
45
40
  }
46
41
 
47
- return BOOK_PRICE * groupSize * (100 - DISCOUNT_TIERS[groupSize - 1]) / 100;
48
- }
42
+ private double costOfGroupSize(int groupSize) {
43
+ if (groupSize < 1 || groupSize > MAX_GROUP_SIZE) {
44
+ throw new IllegalStateException("Invalid group size : " + groupSize);
45
+ }
46
+
47
+ return BOOK_PRICE * groupSize * (100 - DISCOUNT_TIERS[groupSize - 1]) / 100;
48
+ }
49
49
 
50
50
  }
@@ -1,16 +1,16 @@
1
1
  import java.util.ArrayList;
2
2
  import java.util.List;
3
3
 
4
- public class BowlingGame {
4
+ class BowlingGame {
5
5
  private static final int NUMBER_OF_FRAMES = 10;
6
6
  private static final int MAXIMUM_FRAME_SCORE = 10;
7
- private List<Integer> rolls = new ArrayList<Integer>();
7
+ private List<Integer> rolls = new ArrayList<>();
8
8
 
9
- public void roll(int pins) {
9
+ void roll(int pins) {
10
10
  rolls.add(pins);
11
11
  }
12
12
 
13
- public int score() {
13
+ int score() {
14
14
  int score = 0;
15
15
  int frameIndex = 0;
16
16
 
@@ -150,7 +150,7 @@ public class BowlingTest {
150
150
 
151
151
  @Ignore("Remove to run test")
152
152
  @Test
153
- public void rollsCanNotScoreNegativePoints() throws IllegalStateException {
153
+ public void rollsCanNotScoreNegativePoints() {
154
154
  int[] rolls = {-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
155
155
 
156
156
  playGame(rolls);
@@ -163,7 +163,7 @@ public class BowlingTest {
163
163
 
164
164
  @Ignore("Remove to run test")
165
165
  @Test
166
- public void aRollCanNotScoreMoreThan10Points() throws IllegalStateException {
166
+ public void aRollCanNotScoreMoreThan10Points() {
167
167
  int[] rolls = {11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
168
168
 
169
169
  playGame(rolls);
@@ -176,7 +176,7 @@ public class BowlingTest {
176
176
 
177
177
  @Ignore("Remove to run test")
178
178
  @Test
179
- public void twoRollsInAFrameCanNotScoreMoreThan10Points() throws IllegalStateException {
179
+ public void twoRollsInAFrameCanNotScoreMoreThan10Points() {
180
180
  int[] rolls = {5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
181
181
 
182
182
  playGame(rolls);
@@ -189,7 +189,7 @@ public class BowlingTest {
189
189
 
190
190
  @Ignore("Remove to run test")
191
191
  @Test
192
- public void twoBonusRollsAfterAStrikeInTheLastFrameCanNotScoreMoreThan10Points() throws IllegalStateException {
192
+ public void twoBonusRollsAfterAStrikeInTheLastFrameCanNotScoreMoreThan10Points() {
193
193
  int[] rolls = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 5, 6};
194
194
 
195
195
  playGame(rolls);
@@ -202,7 +202,7 @@ public class BowlingTest {
202
202
 
203
203
  @Ignore("Remove to run test")
204
204
  @Test
205
- public void twoBonusRollsAfterAStrikeInTheLastFrameCanScoreMoreThan10PointsIfOneIsAStrike() throws IllegalStateException {
205
+ public void twoBonusRollsAfterAStrikeInTheLastFrameCanScoreMoreThan10PointsIfOneIsAStrike() {
206
206
  int[] rolls = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10, 6};
207
207
 
208
208
  playGame(rolls);
@@ -212,7 +212,7 @@ public class BowlingTest {
212
212
 
213
213
  @Ignore("Remove to run test")
214
214
  @Test
215
- public void anUnstartedGameCanNotBeScored() throws IllegalStateException {
215
+ public void anUnstartedGameCanNotBeScored() {
216
216
  int[] rolls = new int[0];
217
217
 
218
218
  playGame(rolls);
@@ -225,7 +225,7 @@ public class BowlingTest {
225
225
 
226
226
  @Ignore("Remove to run test")
227
227
  @Test
228
- public void anIncompleteGameCanNotBeScored() throws IllegalStateException {
228
+ public void anIncompleteGameCanNotBeScored() {
229
229
  int[] rolls = {0, 0};
230
230
 
231
231
  playGame(rolls);
@@ -238,7 +238,7 @@ public class BowlingTest {
238
238
 
239
239
  @Ignore("Remove to run test")
240
240
  @Test
241
- public void aGameWithMoreThanTenFramesCanNotBeScored() throws IllegalStateException {
241
+ public void aGameWithMoreThanTenFramesCanNotBeScored() {
242
242
  int[] rolls = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
243
243
 
244
244
  playGame(rolls);
@@ -251,7 +251,7 @@ public class BowlingTest {
251
251
 
252
252
  @Ignore("Remove to run test")
253
253
  @Test
254
- public void bonusRollsForAStrikeInTheLastFrameMustBeRolledBeforeScoreCanBeCalculated() throws IllegalStateException {
254
+ public void bonusRollsForAStrikeInTheLastFrameMustBeRolledBeforeScoreCanBeCalculated() {
255
255
  int[] rolls = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10};
256
256
 
257
257
  playGame(rolls);
@@ -264,7 +264,7 @@ public class BowlingTest {
264
264
 
265
265
  @Ignore("Remove to run test")
266
266
  @Test
267
- public void bothBonusRollsForAStrikeInTheLastFrameMustBeRolledBeforeScoreCanBeCalculated() throws IllegalStateException {
267
+ public void bothBonusRollsForAStrikeInTheLastFrameMustBeRolledBeforeScoreCanBeCalculated() {
268
268
  int[] rolls = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10};
269
269
 
270
270
  playGame(rolls);
@@ -277,7 +277,7 @@ public class BowlingTest {
277
277
 
278
278
  @Ignore("Remove to run test")
279
279
  @Test
280
- public void bonusRollForASpareInTheLastFrameMustBeRolledBeforeScoreCanBeCalculated() throws IllegalStateException {
280
+ public void bonusRollForASpareInTheLastFrameMustBeRolledBeforeScoreCanBeCalculated() {
281
281
  int[] rolls = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 3};
282
282
 
283
283
  playGame(rolls);
@@ -0,0 +1,7 @@
1
+ class CollatzCalculator {
2
+
3
+ int computeStepCount(int start) {
4
+ throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
5
+ }
6
+
7
+ }
@@ -0,0 +1,15 @@
1
+ class DifferenceOfSquaresCalculator {
2
+
3
+ int computeSquareOfSumTo(int input) {
4
+ throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
5
+ }
6
+
7
+ int computeSumOfSquaresTo(int input) {
8
+ throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
9
+ }
10
+
11
+ int computeDifferenceOfSquares(int input) {
12
+ throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
13
+ }
14
+
15
+ }
@@ -8,8 +8,8 @@ def song(first, last=0):
8
8
 
9
9
  def verse(number):
10
10
  return ''.join([
11
- "%s of beer on the wall, " % _bottles(number).capitalize(),
12
- "%s of beer.\n" % _bottles(number),
11
+ "{} of beer on the wall, ".format(_bottles(number).capitalize()),
12
+ "{} of beer.\n".format(_bottles(number)),
13
13
  _action(number),
14
14
  _next_bottle(number),
15
15
  ])
@@ -19,13 +19,15 @@ def _action(current_verse):
19
19
  if current_verse == 0:
20
20
  return "Go to the store and buy some more, "
21
21
  else:
22
- return "Take %s down and pass it around, " % (
23
- "one" if current_verse > 1 else "it"
22
+ return "Take {} down and pass it around, ".format(
23
+ "one" if current_verse > 1 else "it",
24
24
  )
25
25
 
26
26
 
27
27
  def _next_bottle(current_verse):
28
- return "%s of beer on the wall.\n" % _bottles(_next_verse(current_verse))
28
+ return "{} of beer on the wall.\n".format(
29
+ _bottles(_next_verse(current_verse)),
30
+ )
29
31
 
30
32
 
31
33
  def _bottles(number):
@@ -34,7 +36,7 @@ def _bottles(number):
34
36
  if number == 1:
35
37
  return '1 bottle'
36
38
  else:
37
- return '%d bottles' % number
39
+ return '{} bottles'.format(number)
38
40
 
39
41
 
40
42
  def _next_verse(current_verse):
@@ -8,7 +8,7 @@ class Clock(object):
8
8
  self.cleanup()
9
9
 
10
10
  def __repr__(self):
11
- return "%02d:%02d" % (self.hour, self.minute)
11
+ return "{:02d}:{:02d}".format(self.hour, self.minute)
12
12
 
13
13
  def __eq__(self, other):
14
14
  return repr(self) == repr(other)
@@ -15,4 +15,4 @@ def nucleotide_counts(strand):
15
15
 
16
16
  def _validate(abbreviation):
17
17
  if abbreviation not in NUCLEOTIDES:
18
- raise ValueError('%s is not a nucleotide.' % abbreviation)
18
+ raise ValueError('{} is not a nucleotide.'.format(abbreviation))
@@ -9,15 +9,15 @@ class Phone(object):
9
9
  self.subscriber_number = self.number[-4:]
10
10
 
11
11
  def pretty(self):
12
- return "(%s) %s-%s" % (
12
+ return "({}) {}-{}".format(
13
13
  self.area_code,
14
14
  self.exchange_code,
15
- self.subscriber_number
15
+ self.subscriber_number,
16
16
  )
17
17
 
18
18
  def _clean(self, number):
19
19
  return self._normalize(
20
- re.sub(r'[^\d]', '', number)
20
+ re.sub(r'[^\d]', '', number),
21
21
  )
22
22
 
23
23
  def _normalize(self, number):
@@ -8,7 +8,7 @@ CODONS = {'AUG': "Methionine", 'UUU': "Phenylalanine",
8
8
 
9
9
  def of_codon(codon):
10
10
  if codon not in CODONS:
11
- raise ValueError('Invalid codon: %s' % codon)
11
+ raise ValueError('Invalid codon: {}'.format(codon))
12
12
  return CODONS[codon]
13
13
 
14
14
 
@@ -12,7 +12,7 @@ def say(number, recursive=False):
12
12
  if number < 0:
13
13
  raise ValueError('number is negative')
14
14
  if number >= t:
15
- raise ValueError('number is too large: %s' % str(number))
15
+ raise ValueError('number is too large: {}'.format(number))
16
16
 
17
17
  if number < 20:
18
18
  return small[number] if not recursive else 'and ' + small[number]
@@ -2,4 +2,4 @@ def two_fer(name=""):
2
2
  if not name.strip():
3
3
  return "One for you, one for me."
4
4
  else:
5
- return "One for %s, one for me." % name
5
+ return "One for {}, one for me.".format(name)
@@ -64,7 +64,7 @@ class Board
64
64
  def validate_size
65
65
  len = rows.first.length
66
66
  if rows.any? { |row| row.length != len }
67
- fail ValueError, 'Invalid board'
67
+ fail ArgumentError, 'Invalid board'
68
68
  end
69
69
  end
70
70
 
@@ -73,7 +73,7 @@ class Board
73
73
  invalid = row.chars.any? do |char|
74
74
  !VALID_BORDERS.include?(char)
75
75
  end
76
- fail ValueError, 'Invalid board' if invalid
76
+ fail ArgumentError, 'Invalid board' if invalid
77
77
  end
78
78
  end
79
79
 
@@ -82,9 +82,7 @@ class Board
82
82
  invalid = row.chars.any? do |char|
83
83
  !VALID_DATA.include?(char)
84
84
  end
85
- fail ValueError, 'Invalid board' if invalid
85
+ fail ArgumentError, 'Invalid board' if invalid
86
86
  end
87
87
  end
88
88
  end
89
-
90
- ValueError = Class.new(StandardError)
@@ -73,7 +73,7 @@ class MinesweeperTest < Minitest::Test
73
73
  def test_different_len
74
74
  skip
75
75
  inp = ['+-+', '| |', '|* |', '| |', '+-+']
76
- assert_raises(ValueError) do
76
+ assert_raises(ArgumentError) do
77
77
  Board.transform(inp)
78
78
  end
79
79
  end
@@ -81,7 +81,7 @@ class MinesweeperTest < Minitest::Test
81
81
  def test_faulty_border
82
82
  skip
83
83
  inp = ['+-----+', '* * |', '+-- --+']
84
- assert_raises(ValueError) do
84
+ assert_raises(ArgumentError) do
85
85
  Board.transform(inp)
86
86
  end
87
87
  end
@@ -89,7 +89,7 @@ class MinesweeperTest < Minitest::Test
89
89
  def test_invalid_char
90
90
  skip
91
91
  inp = ['+-----+', '|X * |', '+-----+']
92
- assert_raises(ValueError) do
92
+ assert_raises(ArgumentError) do
93
93
  Board.transform(inp)
94
94
  end
95
95
  end
@@ -34,18 +34,6 @@
34
34
  "Mathematics"
35
35
  ]
36
36
  },
37
- {
38
- "uuid": "825e94e5-6fc8-4dce-befe-74e1516fae14",
39
- "slug": "flatten-array",
40
- "core": true,
41
- "unlocked_by": null,
42
- "difficulty": 2,
43
- "topics": [
44
- "Recursion",
45
- "Lists",
46
- "Pattern matching"
47
- ]
48
- },
49
37
  {
50
38
  "uuid": "57b76aba-a485-464d-84ba-e9a445b25be6",
51
39
  "slug": "bob",
@@ -94,6 +82,18 @@
94
82
  "Transforming"
95
83
  ]
96
84
  },
85
+ {
86
+ "uuid": "825e94e5-6fc8-4dce-befe-74e1516fae14",
87
+ "slug": "flatten-array",
88
+ "core": true,
89
+ "unlocked_by": "accumulate",
90
+ "difficulty": 2,
91
+ "topics": [
92
+ "Recursion",
93
+ "Lists",
94
+ "Pattern matching"
95
+ ]
96
+ },
97
97
  {
98
98
  "uuid": "65a76aba-a485-222d-84ba-e9a445b25be6",
99
99
  "slug": "collatz-conjecture",
@@ -1,18 +1,15 @@
1
1
  import org.scalatest.{Matchers, FunSuite}
2
2
 
3
+ /** @version 1.1.0 */
3
4
  class FlattenArrayTest extends FunSuite with Matchers {
4
- test("empty list") {
5
- FlattenArray.flatten(List()) should equal(List())
6
- }
7
5
 
8
6
  test("no nesting") {
9
- pending
10
- FlattenArray.flatten(List(0, 1, 2)) should equal(List(0, 1, 2))
7
+ FlattenArray.flatten(List(0, 1, 2)) should be(List(0, 1, 2))
11
8
  }
12
9
 
13
10
  test("flattens array with just integers present") {
14
11
  pending
15
- FlattenArray.flatten(List(1, List(2, 3, 4, 5, 6, 7), 8)) should equal(
12
+ FlattenArray.flatten(List(1, List(2, 3, 4, 5, 6, 7), 8)) should be(
16
13
  List(1, 2, 3, 4, 5, 6, 7, 8))
17
14
  }
18
15
 
@@ -21,7 +18,7 @@ class FlattenArrayTest extends FunSuite with Matchers {
21
18
  FlattenArray.flatten(List(0,
22
19
  2,
23
20
  List(List(2, 3), 8, 100, 4, List(List(List(50)))),
24
- -2)) should equal(
21
+ -2)) should be(
25
22
  List(0, 2, 2, 3, 8, 100, 4, 50, -2))
26
23
  }
27
24
 
@@ -30,7 +27,7 @@ class FlattenArrayTest extends FunSuite with Matchers {
30
27
  FlattenArray.flatten(List(
31
28
  1,
32
29
  List(2, List(List(3)), List(4, List(List(5))), 6, 7),
33
- 8)) should equal(List(1, 2, 3, 4, 5, 6, 7, 8))
30
+ 8)) should be(List(1, 2, 3, 4, 5, 6, 7, 8))
34
31
  }
35
32
 
36
33
  test("6 level nest list with null values") {
@@ -39,7 +36,7 @@ class FlattenArrayTest extends FunSuite with Matchers {
39
36
  List(0,
40
37
  2,
41
38
  List(List(2, 3), 8, List(List(100)), null, List(List(null))),
42
- -2)) should equal(List(0, 2, 2, 3, 8, 100, -2))
39
+ -2)) should be(List(0, 2, 2, 3, 8, 100, -2))
43
40
  }
44
41
 
45
42
  test("all values in nested list are null") {
@@ -50,6 +47,6 @@ class FlattenArrayTest extends FunSuite with Matchers {
50
47
  null,
51
48
  null,
52
49
  List(List(null, null), null),
53
- null)) should equal(List())
50
+ null)) should be(List())
54
51
  }
55
52
  }
@@ -0,0 +1,44 @@
1
+ import java.io.File
2
+
3
+ import testgen.TestSuiteBuilder._
4
+ import testgen._
5
+
6
+ object FlattenArrayTestGenerator {
7
+ def main(args: Array[String]): Unit = {
8
+ val file = new File("src/main/resources/flatten-array.json")
9
+
10
+ def sutArgs(parseResult: CanonicalDataParser.ParseResult, argNames: String*): String =
11
+ argNames map (name => toArgString(parseResult(name))) mkString ", "
12
+
13
+ def toArgString(any: Any): String = {
14
+ any match {
15
+ case xs: List[Any] => s"List(${xs.map(x => toArgString(x)).mkString(", ")})"
16
+ case null => "null"
17
+ case _ => any.toString
18
+ }
19
+ }
20
+
21
+ def toExpectedString(expected: CanonicalDataParser.Expected): String = {
22
+ expected match {
23
+ case Left(_) => throw new IllegalStateException()
24
+ case Right(xs: List[Any]) => s"List(${xs.mkString(", ")})"
25
+ }
26
+ }
27
+
28
+ def fromLabeledTest(argNames: String*): ToTestCaseData =
29
+ withLabeledTest { sut =>
30
+ labeledTest =>
31
+ val args = sutArgs(labeledTest.result, argNames: _*)
32
+ val property = labeledTest.property
33
+ val sutCall =
34
+ s"""$sut.$property($args)"""
35
+ val expected = toExpectedString(labeledTest.expected)
36
+ TestCaseData(labeledTest.description, sutCall, expected)
37
+ }
38
+
39
+ val code = TestSuiteBuilder.build(file, fromLabeledTest("input"))
40
+ println(s"-------------")
41
+ println(code)
42
+ println(s"-------------")
43
+ }
44
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trackler
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1.70
4
+ version: 2.2.1.71
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katrina Owen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-22 00:00:00.000000000 Z
11
+ date: 2017-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip
@@ -7103,7 +7103,7 @@ files:
7103
7103
  - tracks/java/exercises/collatz-conjecture/.meta/version
7104
7104
  - tracks/java/exercises/collatz-conjecture/README.md
7105
7105
  - tracks/java/exercises/collatz-conjecture/build.gradle
7106
- - tracks/java/exercises/collatz-conjecture/src/main/java/.keep
7106
+ - tracks/java/exercises/collatz-conjecture/src/main/java/CollatzCalculator.java
7107
7107
  - tracks/java/exercises/collatz-conjecture/src/test/java/CollatzCalculatorTest.java
7108
7108
  - tracks/java/exercises/complex-numbers/.meta/src/reference/java/ComplexNumber.java
7109
7109
  - tracks/java/exercises/complex-numbers/.meta/version
@@ -7132,7 +7132,7 @@ files:
7132
7132
  - tracks/java/exercises/difference-of-squares/.meta/version
7133
7133
  - tracks/java/exercises/difference-of-squares/README.md
7134
7134
  - tracks/java/exercises/difference-of-squares/build.gradle
7135
- - tracks/java/exercises/difference-of-squares/src/main/java/.keep
7135
+ - tracks/java/exercises/difference-of-squares/src/main/java/DifferenceOfSquaresCalculator.java
7136
7136
  - tracks/java/exercises/difference-of-squares/src/test/java/DifferenceOfSquaresCalculatorTest.java
7137
7137
  - tracks/java/exercises/etl/.meta/src/reference/java/Etl.java
7138
7138
  - tracks/java/exercises/etl/README.md
@@ -12808,6 +12808,7 @@ files:
12808
12808
  - tracks/scala/testgen/src/main/scala/DifferenceOfSquaresTestGenerator.scala
12809
12809
  - tracks/scala/testgen/src/main/scala/DominoesTestGenerator.scala
12810
12810
  - tracks/scala/testgen/src/main/scala/EtlTestGenerator.scala
12811
+ - tracks/scala/testgen/src/main/scala/FlattenArrayTestGenerator.scala
12811
12812
  - tracks/scala/testgen/src/main/scala/FoodChainTestGenerator.scala
12812
12813
  - tracks/scala/testgen/src/main/scala/ForthTestGenerator.scala
12813
12814
  - tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala