Ver código fonte

Merged upstream/master and updated config.json

Dmitry Noranovich 9 anos atrás
pai
commit
9cca5f5593
36 arquivos alterados com 390 adições e 5 exclusões
  1. 9
    4
      bin/journey-test.sh
  2. 7
    1
      config.json
  3. 0
    0
      exercises/anagram/src/main/java/.keep
  4. 0
    0
      exercises/beer-song/src/example/java/.keep
  5. 0
    0
      exercises/beer-song/src/main/java/.keep
  6. 0
    0
      exercises/beer-song/src/test/java/.keep
  7. 0
    0
      exercises/difference-of-squares/src/example/java/.keep
  8. 0
    0
      exercises/difference-of-squares/src/main/java/.keep
  9. 0
    0
      exercises/etl/src/main/java/.keep
  10. 0
    0
      exercises/etl/src/test/java/.keep
  11. 0
    0
      exercises/grade-school/src/test/java/.keep
  12. 0
    0
      exercises/hamming/src/main/java/.keep
  13. 0
    0
      exercises/hello-world/src/main/java/.keep
  14. 0
    0
      exercises/hexadecimal/src/test/java/.keep
  15. 0
    0
      exercises/linked-list/src/example/java/.keep
  16. 0
    0
      exercises/linked-list/src/test/java/.keep
  17. 0
    0
      exercises/meetup/src/main/java/.keep
  18. 0
    0
      exercises/meetup/src/test/java/.keep
  19. 0
    0
      exercises/nth-prime/src/example/java/.keep
  20. 0
    0
      exercises/nth-prime/src/test/java/.keep
  21. 0
    0
      exercises/nucleotide-count/src/main/java/.keep
  22. 0
    0
      exercises/nucleotide-count/src/test/java/.keep
  23. 0
    0
      exercises/pangram/src/test/java/.keep
  24. 0
    0
      exercises/pascals-triangle/src/test/java/.keep
  25. 17
    0
      exercises/robot-simulator/build.gradle
  26. 1
    0
      exercises/robot-simulator/src/example/java/GridPosition.java
  27. 1
    0
      exercises/robot-simulator/src/example/java/Orientation.java
  28. 71
    0
      exercises/robot-simulator/src/example/java/Robot.java
  29. 29
    0
      exercises/robot-simulator/src/main/java/GridPosition.java
  30. 5
    0
      exercises/robot-simulator/src/main/java/Orientation.java
  31. 5
    0
      exercises/robot-simulator/src/main/java/Robot.java
  32. 244
    0
      exercises/robot-simulator/src/test/java/RobotTest.java
  33. 0
    0
      exercises/series/src/main/java/.keep
  34. 0
    0
      exercises/series/src/test/java/.keep
  35. 1
    0
      exercises/settings.gradle
  36. 0
    0
      exercises/triangle/src/main/java/.keep

+ 9
- 4
bin/journey-test.sh Ver arquivo

121
 
121
 
122
 make_local_trackler() {
122
 make_local_trackler() {
123
   local trackler="$1"
123
   local trackler="$1"
124
-  echo ">>> make_local_trackler(trackler=\"${trackler}\")"
124
+  local xapi_home="$2"
125
+  echo ">>> make_local_trackler(trackler=\"${trackler}\", xapi_home=\"${xapi_home}\")"
125
 
126
 
126
   local xjava=$( pwd )
127
   local xjava=$( pwd )
127
   pushd ${trackler}
128
   pushd ${trackler}
134
   cp ${xjava}/config.json tracks/java
135
   cp ${xjava}/config.json tracks/java
135
   cp -r ${xjava}/exercises tracks/java
136
   cp -r ${xjava}/exercises tracks/java
136
 
137
 
138
+  # Set the version to that expected by x-api
139
+  version=$( grep -m 1 'trackler' ${xapi_home}/Gemfile.lock | sed 's/.*(//' | sed 's/)//' )
140
+  echo "module Trackler VERSION = \"${version}\" end" > lib/trackler/version.rb
141
+
137
   gem install bundler
142
   gem install bundler
138
   bundle install
143
   bundle install
139
   gem build trackler.gemspec
144
   gem build trackler.gemspec
237
   clean "${build_dir}"
242
   clean "${build_dir}"
238
 
243
 
239
   # Make a version of trackler that includes the source from this repo.
244
   # Make a version of trackler that includes the source from this repo.
245
+  git_clone "x-api" "${xapi_home}"
240
   git_clone "trackler" "${trackler_home}"
246
   git_clone "trackler" "${trackler_home}"
241
   assert_ruby_installed "${trackler_home}"
247
   assert_ruby_installed "${trackler_home}"
242
-  make_local_trackler "${trackler_home}"
248
+  make_local_trackler "${trackler_home}" "${xapi_home}"
243
 
249
 
244
   # Stand-up a local instance of x-api so we can fetch the exercises through it.
250
   # Stand-up a local instance of x-api so we can fetch the exercises through it.
245
-  git_clone "x-api" "${xapi_home}"
246
   assert_ruby_installed "${xapi_home}"
251
   assert_ruby_installed "${xapi_home}"
247
   start_x_api "${xapi_home}"
252
   start_x_api "${xapi_home}"
248
 
253
 
257
 # Execution begins here...
262
 # Execution begins here...
258
 
263
 
259
 # If any command fails, fail the script.
264
 # If any command fails, fail the script.
260
-set -e
265
+set -ex
261
 SCRIPTPATH=$( pushd `dirname $0` > /dev/null && pwd && popd > /dev/null )
266
 SCRIPTPATH=$( pushd `dirname $0` > /dev/null && pwd && popd > /dev/null )
262
 EXECPATH=$( pwd )
267
 EXECPATH=$( pwd )
263
 # Make output easier to read in CI
268
 # Make output easier to read in CI

+ 7
- 1
config.json Ver arquivo

49
     "queen-attack",
49
     "queen-attack",
50
     "minesweeper",
50
     "minesweeper",
51
     "series",
51
     "series",
52
+    "robot-simulator",
52
     "binary-search"
53
     "binary-search"
53
   ],
54
   ],
54
   "exercises": [
55
   "exercises": [
278
       "topics": []
279
       "topics": []
279
     },
280
     },
280
     {
281
     {
282
+      "slug": "robot-simulator",
283
+      "difficulty": 1,
284
+      "topics": []
285
+    },
286
+    {
281
       "slug": "binary-search",
287
       "slug": "binary-search",
282
       "difficulty": 1,
288
       "difficulty": 1,
283
       "topics": []
289
       "topics": []
284
-    }
290
+    },
285
   ],
291
   ],
286
   "deprecated": [
292
   "deprecated": [
287
   ],
293
   ],

+ 0
- 0
exercises/anagram/src/main/java/.keep Ver arquivo


+ 0
- 0
exercises/beer-song/src/example/java/.keep Ver arquivo


+ 0
- 0
exercises/beer-song/src/main/java/.keep Ver arquivo


+ 0
- 0
exercises/beer-song/src/test/java/.keep Ver arquivo


+ 0
- 0
exercises/difference-of-squares/src/example/java/.keep Ver arquivo


+ 0
- 0
exercises/difference-of-squares/src/main/java/.keep Ver arquivo


+ 0
- 0
exercises/etl/src/main/java/.keep Ver arquivo


+ 0
- 0
exercises/etl/src/test/java/.keep Ver arquivo


+ 0
- 0
exercises/grade-school/src/test/java/.keep Ver arquivo


+ 0
- 0
exercises/hamming/src/main/java/.keep Ver arquivo


+ 0
- 0
exercises/hello-world/src/main/java/.keep Ver arquivo


+ 0
- 0
exercises/hexadecimal/src/test/java/.keep Ver arquivo


+ 0
- 0
exercises/linked-list/src/example/java/.keep Ver arquivo


+ 0
- 0
exercises/linked-list/src/test/java/.keep Ver arquivo


+ 0
- 0
exercises/meetup/src/main/java/.keep Ver arquivo


+ 0
- 0
exercises/meetup/src/test/java/.keep Ver arquivo


+ 0
- 0
exercises/nth-prime/src/example/java/.keep Ver arquivo


+ 0
- 0
exercises/nth-prime/src/test/java/.keep Ver arquivo


+ 0
- 0
exercises/nucleotide-count/src/main/java/.keep Ver arquivo


+ 0
- 0
exercises/nucleotide-count/src/test/java/.keep Ver arquivo


+ 0
- 0
exercises/pangram/src/test/java/.keep Ver arquivo


+ 0
- 0
exercises/pascals-triangle/src/test/java/.keep Ver arquivo


+ 17
- 0
exercises/robot-simulator/build.gradle Ver arquivo

1
+apply plugin: "java"
2
+apply plugin: "eclipse"
3
+apply plugin: "idea"
4
+
5
+repositories {
6
+  mavenCentral()
7
+}
8
+
9
+dependencies {
10
+  testCompile "junit:junit:4.12"
11
+}
12
+test {
13
+  testLogging {
14
+    exceptionFormat = 'full'
15
+    events = ["passed", "failed", "skipped"]
16
+  }
17
+}

+ 1
- 0
exercises/robot-simulator/src/example/java/GridPosition.java Ver arquivo

1
+../../main/java/GridPosition.java

+ 1
- 0
exercises/robot-simulator/src/example/java/Orientation.java Ver arquivo

1
+../../main/java/Orientation.java

+ 71
- 0
exercises/robot-simulator/src/example/java/Robot.java Ver arquivo

1
+final class Robot {
2
+
3
+    private GridPosition gridPosition;
4
+
5
+    private Orientation orientation;
6
+
7
+    Robot(final GridPosition initialGridPosition, final Orientation initialOrientation) {
8
+        this.gridPosition = initialGridPosition;
9
+        this.orientation = initialOrientation;
10
+    }
11
+
12
+    GridPosition getGridPosition() {
13
+        return gridPosition;
14
+    }
15
+
16
+    Orientation getOrientation() {
17
+        return orientation;
18
+    }
19
+
20
+    Robot advance() {
21
+        switch (orientation) {
22
+            case NORTH:
23
+                gridPosition = new GridPosition(gridPosition.x, gridPosition.y + 1);
24
+                break;
25
+            case EAST:
26
+                gridPosition = new GridPosition(gridPosition.x + 1, gridPosition.y);
27
+                break;
28
+            case SOUTH:
29
+                gridPosition = new GridPosition(gridPosition.x, gridPosition.y - 1);
30
+                break;
31
+            case WEST:
32
+                gridPosition = new GridPosition(gridPosition.x - 1, gridPosition.y);
33
+                break;
34
+        }
35
+
36
+        return this;
37
+    }
38
+
39
+    Robot simulate(final String instructions) {
40
+        for (final char instruction : instructions.toCharArray()) {
41
+            switch (instruction) {
42
+                case 'A':
43
+                    advance();
44
+                    break;
45
+                case 'R':
46
+                    turnRight();
47
+                    break;
48
+                case 'L':
49
+                    turnLeft();
50
+                    break;
51
+                default:
52
+                    throw new IllegalArgumentException(String.format("Invalid instruction: '%s'", instruction));
53
+            }
54
+        }
55
+
56
+        return this;
57
+    }
58
+
59
+    Robot turnLeft() {
60
+        final int newOrientationOrdinal = Math.floorMod(orientation.ordinal() - 1, Orientation.values().length);
61
+        orientation = Orientation.values()[newOrientationOrdinal];
62
+        return this;
63
+    }
64
+
65
+    Robot turnRight() {
66
+        final int newOrientationOrdinal = Math.floorMod(orientation.ordinal() + 1, Orientation.values().length);
67
+        orientation = Orientation.values()[newOrientationOrdinal];
68
+        return this;
69
+    }
70
+
71
+}

+ 29
- 0
exercises/robot-simulator/src/main/java/GridPosition.java Ver arquivo

1
+final class GridPosition {
2
+
3
+    final int x;
4
+
5
+    final int y;
6
+
7
+    GridPosition(final int x, final int y) {
8
+        this.x = x;
9
+        this.y = y;
10
+    }
11
+
12
+    /*
13
+     * This equals method is of deliberately narrow scope (only allows comparison with another GridPosition) to increase
14
+     * readability. In general, one should provide a full implementation of Object.equals(Object obj) and a
15
+     * corresponding implementation of Object.hashCode(). See
16
+     *
17
+     * https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#equals(java.lang.Object)
18
+     *
19
+     * and
20
+     *
21
+     * https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#hashCode()
22
+     *
23
+     * for more information.
24
+     */
25
+    boolean equals(final GridPosition gridPosition) {
26
+        return this.x == gridPosition.x && this.y == gridPosition.y;
27
+    }
28
+
29
+}

+ 5
- 0
exercises/robot-simulator/src/main/java/Orientation.java Ver arquivo

1
+enum Orientation {
2
+
3
+    NORTH, EAST, SOUTH, WEST
4
+
5
+}

+ 5
- 0
exercises/robot-simulator/src/main/java/Robot.java Ver arquivo

1
+final class Robot {
2
+
3
+
4
+
5
+}

+ 244
- 0
exercises/robot-simulator/src/test/java/RobotTest.java Ver arquivo

1
+import org.junit.Ignore;
2
+import org.junit.Test;
3
+
4
+import static org.junit.Assert.assertTrue;
5
+
6
+public final class RobotTest {
7
+
8
+    @Test
9
+    public void testRobotIsCreatedWithCorrectInitialPosition() {
10
+        final GridPosition initialGridPosition = new GridPosition(0, 0);
11
+        final Robot robot = new Robot(initialGridPosition, Orientation.NORTH);
12
+
13
+        assertTrue(robot.getGridPosition().equals(initialGridPosition));
14
+    }
15
+
16
+    @Ignore
17
+    @Test
18
+    public void testRobotIsCreatedWithCorrectInitialOrientation() {
19
+        final Orientation initialOrientation = Orientation.NORTH;
20
+        final Robot robot = new Robot(new GridPosition(0, 0), initialOrientation);
21
+
22
+        assertTrue(robot.getOrientation().equals(initialOrientation));
23
+    }
24
+
25
+    @Ignore
26
+    @Test
27
+    public void testTurningRightDoesNotChangePosition() {
28
+        final GridPosition initialGridPosition = new GridPosition(0, 0);
29
+        final Robot robot = new Robot(initialGridPosition, Orientation.NORTH);
30
+
31
+        robot.turnRight();
32
+
33
+        assertTrue(robot.getGridPosition().equals(initialGridPosition));
34
+    }
35
+
36
+    @Ignore
37
+    @Test
38
+    public void testTurningRightCorrectlyChangesOrientationFromNorthToEast() {
39
+        final Robot robot = new Robot(new GridPosition(0, 0), Orientation.NORTH);
40
+
41
+        robot.turnRight();
42
+
43
+        final Orientation expectedOrientation = Orientation.EAST;
44
+
45
+        assertTrue(robot.getOrientation().equals(expectedOrientation));
46
+    }
47
+
48
+    @Ignore
49
+    @Test
50
+    public void testTurningRightCorrectlyChangesOrientationFromEastToSouth() {
51
+        final Robot robot = new Robot(new GridPosition(0, 0), Orientation.EAST);
52
+
53
+        robot.turnRight();
54
+
55
+        final Orientation expectedOrientation = Orientation.SOUTH;
56
+
57
+        assertTrue(robot.getOrientation().equals(expectedOrientation));
58
+    }
59
+
60
+    @Ignore
61
+    @Test
62
+    public void testTurningRightCorrectlyChangesOrientationFromSouthToWest() {
63
+        final Robot robot = new Robot(new GridPosition(0, 0), Orientation.SOUTH);
64
+
65
+        robot.turnRight();
66
+
67
+        final Orientation expectedOrientation = Orientation.WEST;
68
+
69
+        assertTrue(robot.getOrientation().equals(expectedOrientation));
70
+    }
71
+
72
+    @Ignore
73
+    @Test
74
+    public void testTurningRightCorrectlyChangesOrientationFromWestToNorth() {
75
+        final Robot robot = new Robot(new GridPosition(0, 0), Orientation.WEST);
76
+
77
+        robot.turnRight();
78
+
79
+        final Orientation expectedOrientation = Orientation.NORTH;
80
+
81
+        assertTrue(robot.getOrientation().equals(expectedOrientation));
82
+    }
83
+
84
+    @Ignore
85
+    @Test
86
+    public void testTurningLeftDoesNotChangePosition() {
87
+        final GridPosition initialGridPosition = new GridPosition(0, 0);
88
+        final Robot robot = new Robot(initialGridPosition, Orientation.NORTH);
89
+
90
+        robot.turnLeft();
91
+
92
+        assertTrue(robot.getGridPosition().equals(initialGridPosition));
93
+    }
94
+
95
+    @Ignore
96
+    @Test
97
+    public void testTurningLeftCorrectlyChangesOrientationFromNorthToWest() {
98
+        final Robot robot = new Robot(new GridPosition(0, 0), Orientation.NORTH);
99
+
100
+        robot.turnLeft();
101
+
102
+        final Orientation expectedOrientation = Orientation.WEST;
103
+
104
+        assertTrue(robot.getOrientation().equals(expectedOrientation));
105
+    }
106
+
107
+    @Ignore
108
+    @Test
109
+    public void testTurningLeftCorrectlyChangesOrientationFromWestToSouth() {
110
+        final Robot robot = new Robot(new GridPosition(0, 0), Orientation.WEST);
111
+
112
+        robot.turnLeft();
113
+
114
+        final Orientation expectedOrientation = Orientation.SOUTH;
115
+
116
+        assertTrue(robot.getOrientation().equals(expectedOrientation));
117
+    }
118
+
119
+    @Ignore
120
+    @Test
121
+    public void testTurningLeftCorrectlyChangesOrientationFromSouthToEast() {
122
+        final Robot robot = new Robot(new GridPosition(0, 0), Orientation.SOUTH);
123
+
124
+        robot.turnLeft();
125
+
126
+        final Orientation expectedOrientation = Orientation.EAST;
127
+
128
+        assertTrue(robot.getOrientation().equals(expectedOrientation));
129
+    }
130
+
131
+    @Ignore
132
+    @Test
133
+    public void testTurningLeftCorrectlyChangesOrientationFromEastToNorth() {
134
+        final Robot robot = new Robot(new GridPosition(0, 0), Orientation.EAST);
135
+
136
+        robot.turnLeft();
137
+
138
+        final Orientation expectedOrientation = Orientation.NORTH;
139
+
140
+        assertTrue(robot.getOrientation().equals(expectedOrientation));
141
+    }
142
+
143
+    @Ignore
144
+    @Test
145
+    public void testAdvancingDoesNotChangeOrientation() {
146
+        final Orientation initialOrientation = Orientation.NORTH;
147
+        final Robot robot = new Robot(new GridPosition(0, 0), initialOrientation);
148
+
149
+        robot.advance();
150
+
151
+        assertTrue(robot.getOrientation().equals(initialOrientation));
152
+    }
153
+
154
+    @Ignore
155
+    @Test
156
+    public void testAdvancingWhenFacingNorthIncreasesYCoordinateByOne() {
157
+        final Robot robot = new Robot(new GridPosition(0, 0), Orientation.NORTH);
158
+
159
+        robot.advance();
160
+
161
+        final GridPosition expectedGridPosition = new GridPosition(0, 1);
162
+
163
+        assertTrue(robot.getGridPosition().equals(expectedGridPosition));
164
+    }
165
+
166
+    @Ignore
167
+    @Test
168
+    public void testAdvancingWhenFacingSouthDecreasesYCoordinateByOne() {
169
+        final Robot robot = new Robot(new GridPosition(0, 0), Orientation.SOUTH);
170
+
171
+        robot.advance();
172
+
173
+        final GridPosition expectedGridPosition = new GridPosition(0, -1);
174
+
175
+        assertTrue(robot.getGridPosition().equals(expectedGridPosition));
176
+    }
177
+
178
+    @Ignore
179
+    @Test
180
+    public void testAdvancingWhenFacingEastIncreasesXCoordinateByOne() {
181
+        final Robot robot = new Robot(new GridPosition(0, 0), Orientation.EAST);
182
+
183
+        robot.advance();
184
+
185
+        final GridPosition expectedGridPosition = new GridPosition(1, 0);
186
+
187
+        assertTrue(robot.getGridPosition().equals(expectedGridPosition));
188
+    }
189
+
190
+    @Ignore
191
+    @Test
192
+    public void testAdvancingWhenFacingWestDecreasesXCoordinateByOne() {
193
+        final Robot robot = new Robot(new GridPosition(0, 0), Orientation.WEST);
194
+
195
+        robot.advance();
196
+
197
+        final GridPosition expectedGridPosition = new GridPosition(-1, 0);
198
+
199
+        assertTrue(robot.getGridPosition().equals(expectedGridPosition));
200
+    }
201
+
202
+    @Ignore
203
+    @Test
204
+    public void testInstructionsToMoveWestAndNorth() {
205
+        final Robot robot = new Robot(new GridPosition(0, 0), Orientation.NORTH);
206
+
207
+        robot.simulate("LAAARALA");
208
+
209
+        final GridPosition expectedGridPosition = new GridPosition(-4, 1);
210
+        final Orientation expectedOrientation = Orientation.WEST;
211
+
212
+        assertTrue(robot.getGridPosition().equals(expectedGridPosition));
213
+        assertTrue(robot.getOrientation().equals(expectedOrientation));
214
+    }
215
+
216
+    @Ignore
217
+    @Test
218
+    public void testInstructionsToMoveWestAndSouth() {
219
+        final Robot robot = new Robot(new GridPosition(2, -7), Orientation.EAST);
220
+
221
+        robot.simulate("RRAAAAALA");
222
+
223
+        final GridPosition expectedGridPosition = new GridPosition(-3, -8);
224
+        final Orientation expectedOrientation = Orientation.SOUTH;
225
+
226
+        assertTrue(robot.getGridPosition().equals(expectedGridPosition));
227
+        assertTrue(robot.getOrientation().equals(expectedOrientation));
228
+    }
229
+
230
+    @Ignore
231
+    @Test
232
+    public void testInstructionsToMoveEastAndNorth() {
233
+        final Robot robot = new Robot(new GridPosition(8, 4), Orientation.SOUTH);
234
+
235
+        robot.simulate("LAAARRRALLLL");
236
+
237
+        final GridPosition expectedGridPosition = new GridPosition(11, 5);
238
+        final Orientation expectedOrientation = Orientation.NORTH;
239
+
240
+        assertTrue(robot.getGridPosition().equals(expectedGridPosition));
241
+        assertTrue(robot.getOrientation().equals(expectedOrientation));
242
+    }
243
+
244
+}

+ 0
- 0
exercises/series/src/main/java/.keep Ver arquivo


+ 0
- 0
exercises/series/src/test/java/.keep Ver arquivo


+ 1
- 0
exercises/settings.gradle Ver arquivo

31
 include 'raindrops'
31
 include 'raindrops'
32
 include 'rna-transcription'
32
 include 'rna-transcription'
33
 include 'robot-name'
33
 include 'robot-name'
34
+include 'robot-simulator'
34
 include 'roman-numerals'
35
 include 'roman-numerals'
35
 include 'prime-factors'
36
 include 'prime-factors'
36
 include 'scrabble-score'
37
 include 'scrabble-score'

+ 0
- 0
exercises/triangle/src/main/java/.keep Ver arquivo