Writing

Code Kata Oktoberfest

Programmierübung aus einem Vorstellungsgespräch: Code Kata Oktoberfest.

Table of Contents
  1. Code Kata Oktoberfest
  2. Einleitung
  3. Meine PHP-Lösung
  4. Meine Python-Lösung
  5. Meine PHP-Lösung
  6. Meine Javascript-Lösung

Während eines Vorstellungsgesprächs wurde mir folgende Programmieraufgabe gestellt:

Code Kata Oktoberfest

Einleitung

Bill und Bob besuchen das Oktoberfest. Sie bestellen jede Stunde eine Maß Bier (14.95 CHF). In jeder Runde stoßen sie an: “Prost!”.

Meine PHP-Lösung

Schreiben wir zuerst einen 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());
    }
}

Ausführen der Tests:

  1. RSpec installieren
  2. Tests ausführen

Meine Python-Lösung

# 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()

Ausführen der Tests:

python oktoberfest.py

Meine PHP-Lösung

---
- hosts: DEVSRV
  become: yes
    - "/home/foo/bar/deploy/config/prod_deploy_config.sh"

Meine Javascript-Lösung

---
- hosts: DEVSRV
  become: yes
    - "/home/foo/bar/deploy/config/prod_deploy_config.sh"

Related Posts