public function setUp() { $elevator = new Elevator(); $this->parser = new InstructionParser($elevator); $this->floorObserver = new FloorObserver($this->parser); $elevator->attach($this->floorObserver); }
public function it_should_log_instructions(Elevator $elevator) { $elevator->goDown()->shouldBeCalledTimes(1); $elevator->getFloor()->shouldBeCalledTimes(1)->willReturn('-1'); $this->parseInstructions(')'); $this->getInstructionsLog()->shouldBe(["-1"]); }
protected function execute(InputInterface $input, OutputInterface $output) { $instructions = file_get_contents(__DIR__ . '/instructions.txt'); $elevator = new Elevator(); $instructionParser = new InstructionParser($elevator); $instructionParser->parseInstructions($instructions); $output->writeln('Puzzle 1 answer: ' . $elevator->getFloor()); }
public function it_only_records_the_instruction_position_when_entering_basement_for_the_first_time(InstructionParser $parser, Elevator $elevator) { $position = random_int(1, 1000); $parser->getInstructionPosition()->willReturn($position); $elevator->getFloor()->willReturn(-1); $this->update($elevator); $this->getInstructionPosition()->shouldBe($position); $parser->getInstructionPosition()->willReturn($position * 2); $this->update($elevator); $this->getInstructionPosition()->shouldBe($position); }
public function it_should_store_only_the_first_instruction_for_basement_entry(InstructionParser $parser, Elevator $elevator) { $count = rand(1, 10000); $parser->getInstructionCount()->willReturn($count); $elevator->getFloor()->willReturn(-1); $this->update($elevator); $this->getInstructionNumber()->shouldBe($count); $parser->getInstructionCount()->willReturn($count * 2); $this->update($elevator); $this->getInstructionNumber()->shouldBe($count); }
function it_parses_multiple_instructions(Elevator $elevator) { $this->parseInstructions(')()))('); $elevator->goUp()->shouldHaveBeenCalledTimes(2); $elevator->goDown()->shouldHaveBeenCalledTimes(4); }
public function it_goes_to_third_basement_level_with_close_open_close_close_open_close_close(Elevator $elevator) { $elevator->goUp()->shouldBeCalledTimes(2); $elevator->goDown()->shouldBeCalledTimes(5); $this->parseInstructions(')())())'); }
public function it_can_use_multiple_parens_to_control_elevator(Elevator $elevator) { $elevator->goUp()->shouldBeCalledTimes(6); $elevator->goDown()->shouldBeCalledTimes(3); $this->parseInstructions('(()()(()('); }