開発環境
- 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 10の解答を求めてみる。
コード
#!/usr/bin/env python3
from unittest import TestCase, main
units = [['km', 'miles', 'league'],
['kg', 'pound', 'stone']]
class MyTestCase(TestCase):
def test_a(self):
self.assertEqual(units[0], ['km', 'miles', 'league'])
def test_b(self):
self.assertEqual(units[len(units) - 1], ['kg', 'pound', 'stone'])
def test_c(self):
self.assertEqual(units[0][0], 'km')
def test_d(self):
self.assertEqual(units[1][0], 'kg')
def test_e(self):
self.assertEqual(units[0][1:], ['miles', 'league'])
def test_f(self):
self.assertEqual(units[1][:2], ['kg', 'pound'])
if __name__ == '__main__':
main()
入出力結果(Zsh、cmd.exe(コマンドプロンプト)、Terminal、Jupyter(IPython))
% ./sample10.py -v
test_a (__main__.MyTestCase) ... ok
test_b (__main__.MyTestCase) ... ok
test_c (__main__.MyTestCase) ... ok
test_d (__main__.MyTestCase) ... ok
test_e (__main__.MyTestCase) ... ok
test_f (__main__.MyTestCase) ... ok
----------------------------------------------------------------------
Ran 6 tests in 0.000s
OK
%
0 コメント:
コメントを投稿