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); }