Writing

코드 카타 옥토버페스트

입사 면접에서 출제된 프로그래밍 연습 문제: 코드 카타 옥토버페스트.

Table of Contents
  1. 코드 카타 옥토버페스트
  2. 소개
  3. 나의 PHP 솔루션
  4. 나의 Python 솔루션
  5. 나의 PHP 솔루션
  6. 나의 Javascript 솔루션

입사 면접 중에 다음과 같은 코딩 문제를 받았습니다:

코드 카타 옥토버페스트

소개

빌과 밥은 옥토버페스트에 참가했습니다. 그들은 매 시간 맥주 한 잔(14.95CHF)을 주문합니다. 매 라운드마다 그들은 서로 건배합니다: “Prost!”.

나의 PHP 솔루션

먼저 테스트 코드를 작성해 봅시다:

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

테스트 실행:

  1. RSpec 설치
  2. 테스트 실행

나의 Python 솔루션

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

테스트 실행:

python oktoberfest.py

나의 PHP 솔루션

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

나의 Javascript 솔루션

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

Related Posts