Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added initial segment in the Path constructor, fixed Path length

  • Loading branch information...
commit 60042166e3a3c34d0307666ddd407fc541cc8350 1 parent 209ffeb
Venelin Valkov authored
4 features/path_finding_length.feature
@@ -40,7 +40,7 @@ Feature: Find the length path in a maze with given rows, columns, walls, start a
40 40 And the Maze is build
41 41 When I set start at 1 and end at 12
42 42 And the path finding is executed
43   - Then the path distance should be 8
  43 + Then the path distance should be 7
44 44
45 45 # S * * *
46 46 # * * * *
@@ -50,4 +50,4 @@ Feature: Find the length path in a maze with given rows, columns, walls, start a
50 50 Given the Maze is build
51 51 When I set start at 1 and end at 12
52 52 And the path finding is executed
53   - Then the path distance should be 6
  53 + Then the path distance should be 5
5 lib/naughty_maze/path.rb
@@ -3,12 +3,13 @@ class Path
3 3
4 4 attr_accessor :segments
5 5
6   - def initialize
  6 + def initialize(start_segment)
7 7 @segments = []
  8 + @segments << start_segment
8 9 end
9 10
10 11 def length
11   - @segments.length
  12 + @segments.length - 1
12 13 end
13 14 end
14 15 end
5 lib/naughty_maze/path_finder.rb
@@ -8,7 +8,7 @@ def initialize(start_point, end_point, maze)
8 8
9 9 def execute
10 10 if @start_point == @end_point
11   - return Path.new
  11 + return Path.new(@start_point)
12 12 end
13 13 unless @maze.include?(@start_point)
14 14 raise CellNotFoundError.new("Start point: #@start_point is not in the maze")
@@ -62,8 +62,7 @@ def execute
62 62 private
63 63
64 64 def reconstruct_path(parent_map)
65   - path = Path.new
66   - path.segments << @end_point
  65 + path = Path.new(@end_point)
67 66 add_segments_to_path(path, parent_map, parent_map[@end_point])
68 67 path.segments.reverse!
69 68 path

0 comments on commit 6004216

Please sign in to comment.
Something went wrong with that request. Please try again.