# lucaminudel/TDDwithMockObjectsAndDesignPrinciples

Merge pull request #9 from Sam-Serpoosh/master

Ruby solution for TurnTicketDispenser problem
2 parents 2e297ad + 3ce5679 commit 4da69765cd3c39faa899d991bea184f829ae3317 committed Sep 6, 2012
 @@ -0,0 +1,14 @@ +require_relative "./turn_number_sequence" +require_relative "./turn_ticket" + +class TicketDispenser + + def initialize(ticket_sequence_generator=TurnNumberSequence) + @ticket_sequence_generator = ticket_sequence_generator + end + + def get_turn_ticket + new_turn_number = @ticket_sequence_generator.get_next_turn_number + TurnTicket.new(new_turn_number) + end +end
 @@ -0,0 +1,7 @@ +class TurnNumberSequence + @@current_turn_number = -1 + + def self.get_next_turn_number + @@current_turn_number += 1 + end +end
 @@ -0,0 +1,9 @@ +class TurnTicket + def initialize(turn_number) + @turn_number = turn_number + end + + def turn_number + @turn_number + end +end
 @@ -0,0 +1,12 @@ +require_relative "../../code/turn_ticket_dispenser/ticket_dispenser" + + +describe TicketDispenser do + it "gets the next ticket" do + TurnNumberSequence.stub(:get_next_turn_number => 2) + ticket_dispenser = TicketDispenser.new + + ticket = ticket_dispenser.get_turn_ticket + ticket.turn_number.should == 2 + end +end
 @@ -0,0 +1,24 @@ +require_relative "./sensor" + +class Alarm + LOWPRESSURETHRESHOLD = 17 + HIGHPRESSURETHRESHOLD = 21 + + def initialize + @sensor = Sensor.new + @alarm_on = false + @alarm_count = 0 + end + + def check + psi_pressure_value = @sensor.pop_next_pressure_psi_value + if psi_pressure_value < LOWPRESSURETHRESHOLD || HIGHPRESSURETHRESHOLD < psi_pressure_value + @alarm_on = true + @alarm_count += 1 + end + end + + def alarm_on + return @alarm_on + end +end
 @@ -0,0 +1,15 @@ +class Sensor + OFFSET = 16; + + def pop_next_pressure_psi_value + pressure_telemetry_value = sample_pressure + OFFSET + pressure_telemetry_value; + end + + def sample_pressure + #placeholder implementation that + #simulate a real sensor in a real tire + pressure_telemetry_value = 6 * rand(5) * rand(4) + pressure_telemetry_value + end +end
 @@ -0,0 +1,11 @@ +require_relative "./turn_number_sequence" +require_relative "./turn_ticket" + +class TicketDispenser + def get_turn_ticket + new_turn_number = TurnNumberSequence.get_next_turn_number + new_turn_ticket = TurnTicket.new(new_turn_number) + + return new_turn_ticket + end +end
 @@ -0,0 +1,7 @@ +class TurnNumberSequence + TURN_NUMBER = -1 + + def self.get_next_turn_number + TURN_NUMBER += 1 + end +end
 @@ -0,0 +1,9 @@ +class TurnTicket + def initialize(turn_number) + @turn_number = turn_number + end + + def turn_number + return @turn_number + end +end