Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ doc/

config/database.yml
TODO

.idea
9 changes: 9 additions & 0 deletions lib/sales_person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,13 @@ def schedule_city(city)
def route
CalculatesRoute.calculate(cities)
end

## ex. salesperson.start_city(place_obj)
def start_city(city)
if @cities.include?(city)
@cities.delete(city)
end

@cities.insert(0, city)
end
end
23 changes: 22 additions & 1 deletion salesperson.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
Dir["./lib/*.rb"].each {|file| require file }


=begin
phil = SalesPerson.new
phil.schedule_city(Place.build("Dallas, TX"))
phil.schedule_city(Place.build("El Paso, TX"))
phil.schedule_city(Place.build("Austin, TX"))
phil.schedule_city(Place.build("Lubbock, TX"))

puts phil.route
=end

mochi = SalesPerson.new

benicia = Place.build('Benicia, CA')
berkeley = Place.build('Berkeley, CA')
eville = Place.build('Emeryville, CA')
sf = Place.build('San Francisco, CA')
sm = Place.build('San Mateo, CA')
wc = Place.build('Walnut Creek, CA')

cities = [berkeley, wc, sf, sm, benicia, eville]

cities.each { |city|
mochi.schedule_city(city)
}

mochi.start_city(benicia) # city that was already scheduled
#mochi.start_city(Place.build('Pleasant Hill, CA')) # a new city not already scheduled
#mochi.start_city(Place.build('Mill Valley'))
puts mochi.route
4 changes: 2 additions & 2 deletions spec/place_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
it "should have a name" do
subject.should respond_to(:name)
end
it "should have a coordinates" do
it "should have coordinates" do
subject.coordinates = [29,-95]
subject.coordinates.should eq([29,-95])
end
Expand Down Expand Up @@ -35,7 +35,7 @@
end

describe "#to_coordinates" do
it "should delegate to_coorinates to coordinates" do
it "should delegate to_coordinates to coordinates" do
subject.stub(:coordinates) { [5,5]}
subject.to_coordinates.should eq ([5,5])
end
Expand Down
6 changes: 6 additions & 0 deletions spec/sales_person_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,10 @@
CalculatesRoute.stub(:calculate) { route_stub }
subject.route.should eq(route_stub)
end

it 'should let you specify starting point' do
city = stub
subject.start_city(city)
subject.cities.first.should eq(city)
end
end