開発環境
- macOS Catalina - Apple (OS)
- Emacs (Text Editor)
- Windows 10 Pro (OS)
- Visual Studio Code (Text Editor)
- Python 3.7 (プログラミング言語)
Practical Programming: An Introduction to Computer Science Using Python 3.6 (Paul Gries(著)、Jennifer Campbell(著)、Jason Montojo(著)、Pragmatic Bookshelf)のChapter 8(Storing Collections of Data Using Lists)、Exercise 5の解答を求めてみる。
コード
#!/usr/bin/env python3
from unittest import TestCase, main
alkaline_earth_metals = [4, 12, 20, 38, 56, 88]
class MyTestCase(TestCase):
def test_b_positive(self):
self.assertEqual(alkaline_earth_metals[5], 88)
def test_b_negative(self):
self.assertEqual(alkaline_earth_metals[-1], 88)
def test_c(self):
self.assertEqual(len(alkaline_earth_metals), 6)
def test_d(self):
self.assertEqual(max(alkaline_earth_metals), 88)
if __name__ == '__main__':
main()
入出力結果(Zsh、cmd.exe(コマンドプロンプト)、Terminal、Jupyter(IPython))
% ./sample5.py -v
test_b_negative (__main__.MyTestCase) ... ok
test_b_positive (__main__.MyTestCase) ... ok
test_c (__main__.MyTestCase) ... ok
test_d (__main__.MyTestCase) ... ok
----------------------------------------------------------------------
Ran 4 tests in 0.000s
OK
%
0 コメント:
コメントを投稿