Writing
Code Kata Oktoberfest
Programátorské cvičenie z pracovného pohovoru: Code Kata Oktoberfest.
Table of Contents
Počas pracovného pohovoru som dostal za úlohu vyriešiť toto programátorské cvičenie:
Code Kata Oktoberfest
Úvod
Bill a Bob sa zúčastňujú Oktoberfestu. Každú hodinu si objednajú jeden krígeľ piva (14.95 CHF). V každom kole si pripíjajú: “Prost!”.
Moje PHP riešenie
Najprv napíšme test:
<?php
class ParticipantTest extends PHPUnit\Framework\TestCase
{
public static function setUpBeforeClass() : void {
require_once 'participant.php';
}
public function setUp() : void {
$this->bob = new Participant('Bob');
$this->beer_price = 1495;
}
public function testGetDuration() : void {
$this->assertEquals(3.5, $this->bob->duration);
}
public function testGreeting() : void {
$this->assertEquals("Prost!", $this->bob->toast());
}
public function testGetTotalCost() : void {
$this->assertEquals(0, $this->bob->getTotalCost());
$this->bob->order();
$this->assertEquals($this->beer_price, $this->bob->getTotalCost());
$this->bob->order();
$this->assertEquals(($this->beer_price * 2), $this->bob->getTotalCost());
}
public function testGetTotalConsumption() : void {
$this->assertEquals(0, $this->bob->getTotalConsumption());
$this->bob->order();
$this->assertEquals(1, $this->bob->getTotalConsumption());
$this->bob->order();
$this->assertEquals(2, $this->bob->getTotalConsumption());
}
}
Spustenie testov:
- Nainštalujte RSpec
- Spustite testy
Moje Python riešenie
# oktoberfest_test.python
import unittest
from hello_world import hello
class HelloWorldTest(unittest.TestCase):
def test_say_hi(self):
self.assertEqual(hello(), "Hello, World!")
if __name__ == "__main__":
unittest.main()
Spustenie testov:
python oktoberfest.py
Moje PHP riešenie
---
- hosts: DEVSRV
become: yes
- "/home/foo/bar/deploy/config/prod_deploy_config.sh"
Moje Javascript riešenie
---
- hosts: DEVSRV
become: yes
- "/home/foo/bar/deploy/config/prod_deploy_config.sh"