trackler 2.0.8.36 → 2.0.8.37

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/.gitmodules +3 -0
  3. data/lib/trackler/version.rb +1 -1
  4. data/tracks/c/config.json +7 -0
  5. data/tracks/c/exercises/perfect-numbers/makefile +16 -0
  6. data/tracks/c/exercises/perfect-numbers/src/example.c +28 -0
  7. data/tracks/c/exercises/perfect-numbers/src/example.h +13 -0
  8. data/tracks/c/exercises/perfect-numbers/src/perfect_numbers.h +11 -0
  9. data/tracks/c/exercises/perfect-numbers/test/test_perfect_numbers.c +87 -0
  10. data/tracks/c/exercises/perfect-numbers/test/vendor/unity.c +1300 -0
  11. data/tracks/c/exercises/perfect-numbers/test/vendor/unity.h +274 -0
  12. data/tracks/c/exercises/perfect-numbers/test/vendor/unity_internals.h +701 -0
  13. data/tracks/ceylon/README.md +1 -1
  14. data/tracks/ceylon/docs/RESOURCES.md +5 -0
  15. data/tracks/ceylon/exercises/anagram/source/anagram/module.ceylon +1 -1
  16. data/tracks/ceylon/exercises/bracket-push/example/module.ceylon +2 -2
  17. data/tracks/ceylon/exercises/bracket-push/source/bracketpush/module.ceylon +1 -1
  18. data/tracks/ceylon/exercises/hamming/source/hamming/module.ceylon +1 -1
  19. data/tracks/ceylon/exercises/largest-series-product/source/largestseriesproduct/module.ceylon +1 -1
  20. data/tracks/ceylon/exercises/leap/source/leap/module.ceylon +1 -1
  21. data/tracks/ceylon/exercises/react/example/module.ceylon +2 -2
  22. data/tracks/ceylon/exercises/react/source/react/module.ceylon +1 -1
  23. data/tracks/ceylon/exercises/sieve/example/module.ceylon +2 -2
  24. data/tracks/ceylon/exercises/sieve/source/sieve/module.ceylon +1 -1
  25. data/tracks/clojurescript/.github/ISSUE_TEMPLATE.md +9 -0
  26. data/tracks/clojurescript/.gitignore +4 -0
  27. data/tracks/clojurescript/.travis.yml +5 -0
  28. data/tracks/clojurescript/LICENSE +21 -0
  29. data/tracks/clojurescript/README.md +72 -0
  30. data/tracks/clojurescript/bin/fetch-configlet +32 -0
  31. data/tracks/clojurescript/config.json +21 -0
  32. data/tracks/clojurescript/docs/ABOUT.md +0 -0
  33. data/tracks/clojurescript/docs/INSTALLATION.md +0 -0
  34. data/tracks/clojurescript/docs/LEARNING.md +0 -0
  35. data/tracks/clojurescript/docs/RESOURCES.md +0 -0
  36. data/tracks/clojurescript/docs/TESTS.md +0 -0
  37. data/tracks/clojurescript/exercises/TRACK_HINTS.md +0 -0
  38. data/tracks/clojurescript/img/.keep +0 -0
  39. data/tracks/csharp/exercises/grade-school/Example.cs +13 -1
  40. data/tracks/csharp/exercises/grade-school/GradeSchool.cs +1 -1
  41. data/tracks/csharp/exercises/grade-school/GradeSchoolTest.cs +42 -18
  42. data/tracks/go/README.md +8 -0
  43. data/tracks/go/exercises/twelve-days/HINTS.md +2 -0
  44. data/tracks/haskell/config.json +0 -1
  45. data/tracks/objective-c/config.json +9 -0
  46. data/tracks/objective-c/exercises/crypto-square/CryptoSquareExample.h +14 -0
  47. data/tracks/objective-c/exercises/crypto-square/CryptoSquareExample.m +96 -0
  48. data/tracks/objective-c/exercises/crypto-square/CryptoSquareTest.m +94 -0
  49. data/tracks/objective-c/xcodeProject/ObjectiveC.xcodeproj/project.pbxproj +18 -0
  50. data/tracks/purescript/.gitignore +2 -2
  51. data/tracks/purescript/bin/test-one.sh +58 -0
  52. data/tracks/purescript/bin/test.sh +13 -44
  53. data/tracks/purescript/config.json +7 -0
  54. data/tracks/purescript/exercises/bracket-push/bower.json +17 -0
  55. data/tracks/purescript/exercises/bracket-push/examples/src/BracketPush.purs +43 -0
  56. data/tracks/purescript/exercises/bracket-push/src/BracketPush.purs +3 -0
  57. data/tracks/purescript/exercises/bracket-push/test/Main.purs +64 -0
  58. data/tracks/scala/exercises/hello-world/HINTS.md +0 -4
  59. data/tracks/scala/exercises/hello-world/example.scala +1 -2
  60. data/tracks/scala/exercises/hello-world/src/test/scala/HelloWorldTest.scala +4 -11
  61. data/tracks/scala/testgen/build.sbt +9 -0
  62. data/tracks/scala/testgen/project/build.properties +2 -0
  63. data/tracks/scala/testgen/project/plugins.sbt +2 -0
  64. data/tracks/scala/testgen/src/main/scala/BeerSongTestGenerator.scala +15 -0
  65. data/tracks/scala/testgen/src/main/scala/BowlingTestGenerator.scala +23 -44
  66. data/tracks/scala/testgen/src/main/scala/FoodChainTestGenerator.scala +31 -0
  67. data/tracks/scala/testgen/src/main/scala/HelloWorldTestGenerator.scala +14 -0
  68. data/tracks/scala/testgen/src/main/scala/NucleotideCountTestGenerator.scala +15 -0
  69. data/tracks/scala/testgen/src/main/scala/PangramsTestGenerator.scala +20 -38
  70. data/tracks/scala/testgen/src/main/scala/SumOfMultiplesTestGenerator.scala +14 -0
  71. data/tracks/scala/testgen/src/main/scala/testgen/CanonicalDataParser.scala +105 -0
  72. data/tracks/scala/testgen/src/main/scala/testgen/TestSuiteBuilder.scala +111 -0
  73. data/tracks/scala/testgen/src/main/twirl/funSuiteTemplate.scala.txt +12 -0
  74. metadata +44 -4
  75. data/tracks/haskell/common/stack.yaml +0 -1
  76. data/tracks/haskell/exercises/pov/.dummylink +0 -1
@@ -0,0 +1,14 @@
1
+ #import <Foundation/Foundation.h>
2
+
3
+ @interface CryptoSquare : NSObject
4
+
5
+ @property (nonatomic, assign) int numberOfRows;
6
+ @property (nonatomic, assign) int numberOfColumns;
7
+ @property (nonatomic, strong) NSArray<NSString *> *plaintextSegments;
8
+ @property (nonatomic, strong) NSString *cipherText;
9
+ @property (nonatomic, strong) NSString *normalizedCipherText;
10
+
11
+ - (instancetype)initWithText:(NSString *)text;
12
+ - (NSString *)normalizePlaintext;
13
+
14
+ @end
@@ -0,0 +1,96 @@
1
+ #import "CryptoSquareExample.h"
2
+
3
+ @interface CryptoSquare ()
4
+
5
+ @property (nonatomic, strong) NSString *text;
6
+ @property (nonatomic, strong) NSString *normalizedText;
7
+
8
+ @end
9
+
10
+ @implementation CryptoSquare
11
+
12
+ - (instancetype)initWithText:(NSString *)text {
13
+ self = [super init];
14
+
15
+ if (self) {
16
+ _text = text;
17
+ _normalizedText = [self normalizePlaintext];
18
+ [self getSquareSize];
19
+ _plaintextSegments = [self getPlaintextSegments];
20
+ _cipherText = [self getCipherText];
21
+ _normalizedCipherText = [self getNormalizedCipherText];
22
+ }
23
+
24
+ return self;
25
+ }
26
+
27
+ - (NSString *)normalizePlaintext {
28
+ NSCharacterSet *characterSet = [[NSCharacterSet alphanumericCharacterSet] invertedSet];
29
+ NSArray<NSString *> *components = [self.text componentsSeparatedByCharactersInSet:characterSet];
30
+ NSString *rejoinedText = [components componentsJoinedByString:@""];
31
+
32
+ return [rejoinedText lowercaseString];
33
+ }
34
+
35
+ - (void)getSquareSize {
36
+ double length = (double)self.normalizedText.length;
37
+ double root = sqrt(length);
38
+
39
+ self.numberOfRows = (int)round(root);
40
+ self.numberOfColumns = (int)ceil(root);
41
+ }
42
+
43
+ - (NSArray<NSString *> *)getPlaintextSegments {
44
+ NSMutableArray<NSString *> *result = [[NSMutableArray alloc] init];
45
+ NSMutableString *segment = [[NSMutableString alloc] initWithString:@""];
46
+
47
+ for (int index = 0; index < self.normalizedText.length; index++) {
48
+ NSString *newCharacter = [NSString stringWithFormat:@"%C", [self.normalizedText characterAtIndex:index]];
49
+ [segment appendString:newCharacter];
50
+
51
+ int position = index + 1;
52
+
53
+ if (position % self.numberOfColumns == 0 || position == self.normalizedText.length) {
54
+ [result addObject:[segment copy]];
55
+ [segment setString:@""];
56
+ }
57
+ }
58
+
59
+ return result;
60
+ }
61
+
62
+ - (NSString *)getCipherText {
63
+ NSMutableString *result = [[NSMutableString alloc] initWithString:@""];
64
+
65
+ for (int column = 0; column < self.numberOfColumns; column++) {
66
+ for (NSString *segment in self.plaintextSegments) {
67
+ if (column < segment.length) {
68
+ NSString *newCharacter = [NSString stringWithFormat:@"%C", [segment characterAtIndex:column]];
69
+ [result appendString:newCharacter];
70
+ }
71
+ }
72
+ }
73
+
74
+ return result;
75
+ }
76
+
77
+ - (NSString *)getNormalizedCipherText {
78
+ NSMutableString *result = [[NSMutableString alloc] init];
79
+ int counter = 0;
80
+
81
+ for (int index = 0; index < self.cipherText.length; index++) {
82
+ NSString *newCharacter = [NSString stringWithFormat:@"%C", [self.cipherText characterAtIndex:index]];
83
+
84
+ if (counter % self.numberOfRows == 0 && counter != 0) {
85
+ [result appendFormat:@" %@", newCharacter];
86
+ } else {
87
+ [result appendString:newCharacter];
88
+ }
89
+
90
+ counter++;
91
+ }
92
+
93
+ return result;
94
+ }
95
+
96
+ @end
@@ -0,0 +1,94 @@
1
+ #import <XCTest/XCTest.h>
2
+ #if __has_include("CryptoSquareExample.h")
3
+ # import "CryptoSquareExample.h"
4
+ # else
5
+ # import "CryptoSquare.h"
6
+ #endif
7
+
8
+ @interface CryptoSquareTest : XCTestCase
9
+
10
+ @end
11
+
12
+ @implementation CryptoSquareTest
13
+
14
+ - (void)testNormalizeStrangeCharacters {
15
+ CryptoSquare *crypto = [[CryptoSquare alloc] initWithText:@"s#$%^&plunk"];
16
+ XCTAssertEqualObjects(@"splunk", [crypto normalizePlaintext]);
17
+ }
18
+
19
+ - (void)testNormalizeUppercaseCharacters {
20
+ CryptoSquare *crypto = [[CryptoSquare alloc] initWithText:@"WHOA HEY!"];
21
+ XCTAssertEqualObjects(@"whoahey", [crypto normalizePlaintext]);
22
+ }
23
+
24
+ - (void)testNormalizeWithNumbers {
25
+ CryptoSquare *crypto = [[CryptoSquare alloc] initWithText:@"1, 2, 3 GO!"];
26
+ XCTAssertEqualObjects(@"123go", [crypto normalizePlaintext]);
27
+ }
28
+
29
+ - (void)testSizeOfSmallSquare {
30
+ CryptoSquare *crypto = [[CryptoSquare alloc] initWithText:@"1234"];
31
+ XCTAssertEqual(2, crypto.numberOfColumns);
32
+ }
33
+
34
+ - (void)testSizeOfSlightlyLargerSquare {
35
+ CryptoSquare *crypto = [[CryptoSquare alloc] initWithText:@"123456789"];
36
+ XCTAssertEqual(3, crypto.numberOfColumns);
37
+ }
38
+
39
+ - (void)testSizeOfNonPerfectSquare {
40
+ CryptoSquare *crypto = [[CryptoSquare alloc] initWithText:@"123456789abc"];
41
+ XCTAssertEqual(4, crypto.numberOfColumns);
42
+ }
43
+
44
+ - (void)testSizeIsDeterminedByNormalizedPlaintext {
45
+ CryptoSquare *crypto = [[CryptoSquare alloc] initWithText:@"Oh hey, this is nuts!"];
46
+ XCTAssertEqual(4, crypto.numberOfColumns);
47
+ }
48
+
49
+ - (void)testPlaintextSegments {
50
+ CryptoSquare *crypto = [[CryptoSquare alloc] initWithText:@"Never vex thine heart with idle woes"];
51
+ NSArray *expected = @[@"neverv", @"exthin", @"eheart", @"withid", @"lewoes"];
52
+ XCTAssertEqualObjects(expected, crypto.plaintextSegments);
53
+ }
54
+
55
+ - (void)testOtherPlaintextSegments {
56
+ CryptoSquare *crypto = [[CryptoSquare alloc] initWithText:@"ZOMG! ZOMBIES!!!"];
57
+ NSArray *expected = @[@"zomg", @"zomb", @"ies"];
58
+ XCTAssertEqualObjects(expected, crypto.plaintextSegments);
59
+ }
60
+
61
+ - (void)testCiphertext {
62
+ CryptoSquare *crypto = [[CryptoSquare alloc] initWithText:@"Time is an illusion. Lunchtime doubly so."];
63
+ XCTAssertEqualObjects(@"tasneyinicdsmiohooelntuillibsuuml", crypto.cipherText);
64
+ }
65
+
66
+ - (void)testAnotherCiphertext {
67
+ CryptoSquare *crypto = [[CryptoSquare alloc] initWithText:@"We all know interspecies romance is weird."];
68
+ XCTAssertEqualObjects(@"wneiaweoreneawssciliprerlneoidktcms", crypto.cipherText);
69
+ }
70
+
71
+ - (void)testNormalizedCiphertext {
72
+ CryptoSquare *crypto = [[CryptoSquare alloc] initWithText:@"Vampires are people too!"];
73
+ XCTAssertEqualObjects(@"vrel aepe mset paoo irpo", crypto.normalizedCipherText);
74
+ }
75
+
76
+ - (void)testNormalizedCiphertextSpillsIntoShortSegment {
77
+ CryptoSquare *crypto = [[CryptoSquare alloc] initWithText:@"Madness, and then illumination."];
78
+ XCTAssertEqualObjects(@"msemo aanin dninn dlaet ltshu i", crypto.normalizedCipherText);
79
+ }
80
+
81
+ - (void)testAnotherNormalizedCiphertext {
82
+ CryptoSquare *crypto = [[CryptoSquare alloc] initWithText:
83
+ @"If man was meant to stay on the ground god would have given us roots"];
84
+ NSString *expected = @"imtgdvs fearwer mayoogo anouuio ntnnlvt wttddes aohghns seoau";
85
+ XCTAssertEqualObjects(expected, crypto.normalizedCipherText);
86
+ }
87
+
88
+ - (void)testNormalizedCiphertextWithPunctuation {
89
+ CryptoSquare *crypto = [[CryptoSquare alloc] initWithText:@"Have a nice day. Feed the dog & chill out!"];
90
+ NSString *expected = @"hifei acedl veeol eddgo aatcu nyhht";
91
+ XCTAssertEqualObjects(expected, crypto.normalizedCipherText);
92
+ }
93
+
94
+ @end
@@ -79,6 +79,8 @@
79
79
  E95C52561E81C82A0095D321 /* BinarySearchTest.m in Sources */ = {isa = PBXBuildFile; fileRef = E95C52541E81C82A0095D321 /* BinarySearchTest.m */; };
80
80
  E96993981DF60E1E009EA223 /* TransposeExample.m in Sources */ = {isa = PBXBuildFile; fileRef = E96993971DF60E1E009EA223 /* TransposeExample.m */; };
81
81
  E969939A1DF60E5F009EA223 /* TransposeTest.m in Sources */ = {isa = PBXBuildFile; fileRef = E96993991DF60E5F009EA223 /* TransposeTest.m */; };
82
+ E9895B6E1E8DA8E8006AD25D /* CryptoSquareExample.m in Sources */ = {isa = PBXBuildFile; fileRef = E9895B6D1E8DA8E8006AD25D /* CryptoSquareExample.m */; };
83
+ E9895B701E8DA914006AD25D /* CryptoSquareTest.m in Sources */ = {isa = PBXBuildFile; fileRef = E9895B6F1E8DA914006AD25D /* CryptoSquareTest.m */; };
82
84
  E99D1D811D5533BF0006A303 /* SumOfMultiplesExample.m in Sources */ = {isa = PBXBuildFile; fileRef = E99D1D801D5533BF0006A303 /* SumOfMultiplesExample.m */; };
83
85
  E99D1D831D5533D80006A303 /* SumOfMultiplesTest.m in Sources */ = {isa = PBXBuildFile; fileRef = E99D1D821D5533D80006A303 /* SumOfMultiplesTest.m */; };
84
86
  E9A7B2F71DA5AC37009056B6 /* LargestSeriesProductExample.m in Sources */ = {isa = PBXBuildFile; fileRef = E9A7B2F61DA5AC37009056B6 /* LargestSeriesProductExample.m */; };
@@ -187,6 +189,9 @@
187
189
  E96993961DF60E1E009EA223 /* TransposeExample.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TransposeExample.h; path = ../../exercises/transpose/TransposeExample.h; sourceTree = "<group>"; };
188
190
  E96993971DF60E1E009EA223 /* TransposeExample.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TransposeExample.m; path = ../../exercises/transpose/TransposeExample.m; sourceTree = "<group>"; };
189
191
  E96993991DF60E5F009EA223 /* TransposeTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TransposeTest.m; path = ../../exercises/transpose/TransposeTest.m; sourceTree = "<group>"; };
192
+ E9895B6C1E8DA8E8006AD25D /* CryptoSquareExample.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CryptoSquareExample.h; path = "../../exercises/crypto-square/CryptoSquareExample.h"; sourceTree = "<group>"; };
193
+ E9895B6D1E8DA8E8006AD25D /* CryptoSquareExample.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CryptoSquareExample.m; path = "../../exercises/crypto-square/CryptoSquareExample.m"; sourceTree = "<group>"; };
194
+ E9895B6F1E8DA914006AD25D /* CryptoSquareTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CryptoSquareTest.m; path = "../../exercises/crypto-square/CryptoSquareTest.m"; sourceTree = "<group>"; };
190
195
  E99D1D7F1D5533BF0006A303 /* SumOfMultiplesExample.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SumOfMultiplesExample.h; path = "../../exercises/sum-of-multiples/SumOfMultiplesExample.h"; sourceTree = "<group>"; };
191
196
  E99D1D801D5533BF0006A303 /* SumOfMultiplesExample.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SumOfMultiplesExample.m; path = "../../exercises/sum-of-multiples/SumOfMultiplesExample.m"; sourceTree = "<group>"; };
192
197
  E99D1D821D5533D80006A303 /* SumOfMultiplesTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SumOfMultiplesTest.m; path = "../../exercises/sum-of-multiples/SumOfMultiplesTest.m"; sourceTree = "<group>"; };
@@ -237,6 +242,7 @@
237
242
  E9E8B6EC1D519DEF0012F12C /* Bob */,
238
243
  A09A906D1E28C1380087CCB7 /* BracketPush */,
239
244
  E9381D4F1D8F2DA4003F22A1 /* Clock */,
245
+ E9895B6B1E8DA8AA006AD25D /* CryptoSquare */,
240
246
  E9381D431D8EDFB8003F22A1 /* DifferenceOfSquares */,
241
247
  E9E8B6ED1D519DF50012F12C /* Etl */,
242
248
  A09A4C001E3875C200FEFB7A /* FlattenArray */,
@@ -425,6 +431,16 @@
425
431
  name = Transpose;
426
432
  sourceTree = "<group>";
427
433
  };
434
+ E9895B6B1E8DA8AA006AD25D /* CryptoSquare */ = {
435
+ isa = PBXGroup;
436
+ children = (
437
+ E9895B6C1E8DA8E8006AD25D /* CryptoSquareExample.h */,
438
+ E9895B6D1E8DA8E8006AD25D /* CryptoSquareExample.m */,
439
+ E9895B6F1E8DA914006AD25D /* CryptoSquareTest.m */,
440
+ );
441
+ name = CryptoSquare;
442
+ sourceTree = "<group>";
443
+ };
428
444
  E99D1D7B1D5532C50006A303 /* SumOfMultiples */ = {
429
445
  isa = PBXGroup;
430
446
  children = (
@@ -770,6 +786,7 @@
770
786
  A09A4C031E38761A00FEFB7A /* FlattenArrayExample.m in Sources */,
771
787
  A0BBFCC31E37728100230071 /* SublistTest.m in Sources */,
772
788
  E9C1C02F1D9EC1130015E86E /* RunLengthEncodingExample.m in Sources */,
789
+ E9895B6E1E8DA8E8006AD25D /* CryptoSquareExample.m in Sources */,
773
790
  E92FCC0F1D78F3B600061017 /* MeetupTest.m in Sources */,
774
791
  E9381D4E1D8F2982003F22A1 /* RaindropsTest.m in Sources */,
775
792
  E9381D541D8F2DE1003F22A1 /* ClockTest.m in Sources */,
@@ -807,6 +824,7 @@
807
824
  E9386EEE1E0B692D0009A414 /* AtbashCipherExample.m in Sources */,
808
825
  1EFACAA61CCCAF3D006F2E69 /* BobTest.m in Sources */,
809
826
  E9B345FA1DB93839006EFBE2 /* PangramTest.m in Sources */,
827
+ E9895B701E8DA914006AD25D /* CryptoSquareTest.m in Sources */,
810
828
  E9A7B2F91DA5AC55009056B6 /* LargestSeriesProductTest.m in Sources */,
811
829
  1EFACAAF1CCCAF3D006F2E69 /* LeapExample.m in Sources */,
812
830
  E9386EF01E0B694D0009A414 /* AtbashCipherTest.m in Sources */,
@@ -6,9 +6,9 @@ bin/configlet.exe
6
6
  **/npm-debug.log
7
7
 
8
8
  # Purescript artifact directories
9
- **/bower_components/
9
+ **/bower_components
10
10
  **/node_modules/
11
11
  **/.pulp-cache/
12
- **/output/
12
+ **/output
13
13
  **/.psc*
14
14
  **/.psa*
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env bash
2
+
3
+ exercise_dir="$1"
4
+ if [[ -z "$exercise_dir" ]]; then
5
+ echo "Usage: $BASH_SOURCE <exercise>"
6
+ exit 1
7
+ fi
8
+
9
+ xpurescript=$(dirname "$BASH_SOURCE")
10
+ xpurescript=$(readlink -f "$xpurescript/..")
11
+ cd "$xpurescript"
12
+
13
+ cache_dir="$HOME"
14
+ if [ -z "$TRAVIS" ]; then
15
+ cache_dir="$xpurescript"
16
+ fi
17
+ cache_dir="$cache_dir/.exercise_cache"
18
+
19
+ declare -i TEST_RESULT=0
20
+
21
+ echo
22
+ echo -e "\e[1;34m----- Testing exercise \e[33m$exercise_dir\e[34m -----\e[0;39m"
23
+ echo
24
+
25
+ if [[ ! -f "exercises/$exercise_dir/bower.json" ]]; then
26
+ echo -e "\e[1;31mExercise \e[33m$exercise_dir\e[31m is missing bower.json, failing test\e[0;39m"
27
+ exit 1
28
+ fi
29
+
30
+ cd "exercises/$exercise_dir"
31
+
32
+ exercise_src=src
33
+ exercise_examples_src=examples/src
34
+
35
+ # Setup Travis cache
36
+ for dir in bower_components output; do
37
+ cache="$cache_dir/$exercise_dir/$dir"
38
+
39
+ mkdir -p "$cache"
40
+ ln -f -s "$cache"
41
+ done
42
+
43
+ mv "$exercise_src" "$exercise_src.impl"
44
+ mv "$exercise_examples_src" "$exercise_src"
45
+
46
+ bower install
47
+ pulp test
48
+
49
+ # capture result from last command (pulp test)
50
+ if [[ $? == 0 ]]; then
51
+ TEST_RESULT=1
52
+ fi
53
+
54
+ # be kind, rewind
55
+ mv "$exercise_src" "$exercise_examples_src"
56
+ mv "$exercise_src.impl" "$exercise_src"
57
+
58
+ exit $TEST_RESULT
@@ -1,18 +1,8 @@
1
1
  #!/usr/bin/env bash
2
2
 
3
- # TEST
4
-
5
3
  xpurescript=$(dirname "$BASH_SOURCE")
6
4
  xpurescript=$(readlink -f "$xpurescript/..")
7
5
  cd "$xpurescript"
8
- echo "xpurescript: $xpurescript"
9
-
10
- cache_dir="$HOME"
11
- if [ -z "$TRAVIS" ]; then
12
- cache_dir="$xpurescript"
13
- fi
14
- cache_dir="$cache_dir/.exercise_cache"
15
- echo "cache_dir: $cache_dir"
16
6
 
17
7
  declare -i TEST_RESULT=0
18
8
  FAILED_EXERCISES=''
@@ -21,44 +11,23 @@ cd exercises
21
11
 
22
12
  for exercise_dir in *
23
13
  do
24
- echo "-------------------------------------------------------"
25
- echo "Testing $exercise_dir"
26
-
27
- cd "$exercise_dir"
28
-
29
- exercise_src=src
30
- exercise_examples_src=examples/src
31
-
32
- # Setup Travis cache
33
- for dir in bower_components output; do
34
- cache="$cache_dir/$exercise_dir/$dir"
35
-
36
- mkdir -p "$cache"
37
- ln -f -s "$cache"
38
- echo "cache: $(ls -l "$dir")"
39
- done
14
+ "$xpurescript/bin/test-one.sh" "$exercise_dir"
40
15
 
41
- mv "$exercise_src" "$exercise_src.impl"
42
- mv "$exercise_examples_src" "$exercise_src"
43
-
44
- bower install
45
- pulp test
46
-
47
- # capture result from last command (pulp test)
48
- if [ $? -ne 0 ]; then
49
- TEST_RESULT=1
50
- FAILED_EXERCISES+="$exercise_dir\n"
16
+ if [[ $? == 0 ]]; then
17
+ TEST_RESULT=1
18
+ FAILED_EXERCISES+="$exercise_dir\n"
51
19
  fi
52
-
53
- # be kind, rewind
54
- mv "$exercise_src" "$exercise_examples_src"
55
- mv "$exercise_src.impl" "$exercise_src"
56
-
57
- cd -
58
20
  done
59
21
 
60
- if [ $TEST_RESULT -ne 0 ]; then
61
- echo "The following exercises failed"
22
+ echo
23
+ if [[ $TEST_RESULT == 0 ]]; then
24
+ echo -e "\e[1;32mAll exercises passed\e[0;39m"
25
+ else
26
+ echo -e "\e[1;31mThe following exercises failed"
27
+
28
+ echo -e "\e[1;33m"
62
29
  printf $FAILED_EXERCISES
30
+ echo -e "\e[0;39m"
31
+
63
32
  exit $TEST_RESULT
64
33
  fi
@@ -93,6 +93,13 @@
93
93
  "topics": [
94
94
  "strings"
95
95
  ]
96
+ },
97
+ {
98
+ "slug": "bracket-push",
99
+ "difficulty": 1,
100
+ "topics": [
101
+ "dates"
102
+ ]
96
103
  }
97
104
  ],
98
105
  "deprecated": [
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "bracket-push",
3
+ "ignore": [
4
+ "**/.*",
5
+ "node_modules",
6
+ "bower_components",
7
+ "output"
8
+ ],
9
+ "dependencies": {
10
+ "purescript-prelude": "^2.5.0",
11
+ "purescript-lists": "^3.4.0"
12
+ },
13
+ "devDependencies": {
14
+ "purescript-psci-support": "^2.0.0",
15
+ "purescript-test-unit": "^10.1.0"
16
+ }
17
+ }
@@ -0,0 +1,43 @@
1
+ module BracketPush
2
+ ( isPaired
3
+ ) where
4
+
5
+ import Prelude
6
+ import Data.Array (toUnfoldable)
7
+ import Data.List (List(..), filter, (:))
8
+ import Data.String (toCharArray)
9
+
10
+ data Bracket = Round | Square | Curly
11
+
12
+ derive instance eqBracket :: Eq Bracket
13
+
14
+ data Token = Open Bracket
15
+ | Close Bracket
16
+ | Other
17
+
18
+ derive instance eqToken :: Eq Token
19
+
20
+ token :: Char -> Token
21
+ token c
22
+ | c == '(' = Open Round
23
+ | c == '[' = Open Square
24
+ | c == '{' = Open Curly
25
+ | c == ')' = Close Round
26
+ | c == ']' = Close Square
27
+ | c == '}' = Close Curly
28
+ token _ = Other
29
+
30
+ walk :: List Token -> List Token -> Boolean
31
+ walk Nil Nil = true
32
+ walk xs (y@(Open c):ys) = walk (y:xs) ys
33
+ walk (Open x:xs) (Close y:ys)
34
+ | x == y = walk xs ys
35
+ | otherwise = false
36
+ walk _ _ = false
37
+
38
+ isPaired :: String -> Boolean
39
+ isPaired = toCharArray
40
+ >>> toUnfoldable
41
+ >>> map token
42
+ >>> filter ((/=) Other)
43
+ >>> walk Nil