開発環境
- 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 1の解答を求めてみる。
コード
Python 3
#!/usr/bin/env python3 from unittest import TestCase, main kingdoms = ['Bacteria', 'Protozoa', 'Chromista', 'Plantae', 'Fungi', 'Animalia'] class MyTestCase(TestCase): def test(self): spam = [kingdoms[0], kingdoms[5], kingdoms[:3], kingdoms[2:5], kingdoms[4:], kingdoms[:0]] egg = ['Bacteria', 'Animalia', ['Bacteria', 'Protozoa', 'Chromista'], ['Chromista', 'Plantae', 'Fungi'], ['Fungi', 'Animalia'], []] for s, t in zip(spam, egg): self.assertEqual(s, t) if __name__ == '__main__': main()
入出力結果(Zsh、cmd.exe(コマンドプロンプト)、Terminal、Jupyter(IPython))
% ./sample1.py -v test (__main__.MyTestCase) ... ok ---------------------------------------------------------------------- Ran 1 test in 0.000s OK %
0 コメント:
コメントを投稿