Skip to content

Commit

Permalink
FIX: Error in the fileExtractor, we are not reading the correct line …
Browse files Browse the repository at this point in the history
…for the movement.

 - Now we are reading the line + 1 which is the movement line.
 - Adding test checks to be sure of what we get with a valid file.
  • Loading branch information
thomaspoignant committed Mar 24, 2020
1 parent 2765211 commit 8a998b7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/services/FileExtractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default function extractFile(filePath: string): Map<AutoMower, Array<Move
const autoMower = autoMowerFromLine(autoMowerConfig);
autoMower.garden = garden;

const movementConfig = otherLines[iterator];
const movementConfig = otherLines[iterator + 1];
const movements = movementsFromLine(movementConfig);
autoMowers.set(autoMower, movements);
iterator += 2;
Expand Down
18 changes: 18 additions & 0 deletions test/services/FileExtractor.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import FileExtractor from '../../src/services/FileExtractor';
import InvalidInputFile from '../../src/errors/InvalidInputFile';
import Orientation from '../../src/models/Orientation';

test('should not extract file with garden limit in string', () => {
const filePath = './test/resources/input_invalid_limit';
Expand Down Expand Up @@ -42,4 +43,21 @@ test('should extract file with valid config.', () => {
const filePath = './test/resources/input_valid';
const res = FileExtractor(filePath);
expect(res.size).toBe(2);

const values = Array.from(res.values());
expect(values[0]).toStrictEqual(['L', 'F', 'L', 'F', 'L', 'F', 'L', 'F', 'F']);
expect(values[1]).toStrictEqual(['F', 'F', 'R', 'F', 'F', 'R', 'F', 'R', 'R', 'F']);

const keys = Array.from(res.keys());
expect(keys[0].x).toBe(1);
expect(keys[0].y).toBe(2);
expect(keys[0].orientation).toBe(Orientation.N);
expect(keys[0].garden && keys[0].garden.column).toBe(5);
expect(keys[0].garden && keys[0].garden.row).toBe(5);

expect(keys[1].x).toBe(3);
expect(keys[1].y).toBe(3);
expect(keys[1].orientation).toBe(Orientation.E);
expect(keys[1].garden && keys[1].garden.column).toBe(5);
expect(keys[1].garden && keys[1].garden.row).toBe(5);
});

0 comments on commit 8a998b7

Please sign in to comment.