Writing
Code Kata Oktoberfest
Ansible Playbook
Table of Contents
During a job-interview I was asked to solve this programming exercise:
Code Kata Oktoberfest
Introduction
Bill and Bob attend the Oktoberfest. They are ordering every hour one Mass beer (14.95CHF). Each round they toast themselves:“Prost!”.
My PHP Solution
Let’s write a test first:
<?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());
}
}
Running the tests:
- Install RSpec:
- Execute the tests:
My Python Solution
# 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()
Running the tests:
python oktoberfest.py
My PHP Solution
---
- hosts: DEVSRV
become: yes
- "/home/foo/bar/deploy/config/prod_deploy_config.sh"
My Javascript Solution
---
- hosts: DEVSRV
become: yes
- "/home/foo/bar/deploy/config/prod_deploy_config.sh"