yashinomi / sysdev2020_advanced

0 stars 0 forks source link

Class 5. (後半) Exercise 3. log #29

Open yashinomi opened 4 years ago

yashinomi commented 4 years ago

実際にtddを体験

yashinomi commented 4 years ago

ユニットテストにメソッドを追加。 これはコンパイル(今回ならインポートエラーなど)が発生するべき。

import unittest
from calc_str_eval import parse_add_or_minus, parse_multi_or_div, parse_expression

class TestEquationParse(unittest.TestCase):
    """
    中略
    """

    def test_expression(self):
        correct: int = 25
        equation: str = "(3+2)*5"
        result = parse_expression(equation)
        self.assertEqual(correct, result)

if __name__ == "__main__":
    unittest.main()

実行するとインポートエラーが無事に発生。

> python test_parse_equation.py
Traceback (most recent call last):
  File "test_parse_equation.py", line 2, in <module>
    from calc_str_eval import parse_add_or_minus, parse_multi_or_div, parse_expression
ImportError: cannot import name 'parse_expression'
yashinomi commented 4 years ago

空の関数を実装

def parse_expression(equation: str) -> Union[int, float]:
    pass

テストも無事に失敗。

> python test_parse_equation.py
.F..
======================================================================
FAIL: test_expression (__main__.TestEquationParse)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_parse_equation.py", line 43, in test_expression
    self.assertEqual(correct, result)
AssertionError: 25 != None

----------------------------------------------------------------------
Ran 4 tests in 0.000s

FAILED (failures=1)