2019年11月4日月曜日

開発環境

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 3の解答を求めてみる。

コード

#!/usr/bin/env python3
from unittest import TestCase, main

appointments = ['9:00', '10:30', '14:00', '15:00', '15:30']
id_global = id(appointments)


class MyTestCase(TestCase):
    def setUp(self):
        self.appointments = ['9:00', '10:30', '14:00', '15:00', '15:30']
        self.result = ['9:00', '10:30', '14:00', '15:00', '15:30', '16:30']

    def test_a(self):
        self.appointments.append('16:30')
        self.assertListEqual(self.appointments, self.result)

    def test_b(self):
        self.appointments += ['16:30']
        self.assertListEqual(self.appointments, self.result)

    # c.
    # a. modified the list
    # b. ccreated a new list


if __name__ == '__main__':
    main()

入出力結果(Zsh、cmd.exe(コマンドプロンプト)、Terminal、Jupyter(IPython))

% ./sample3.py -v
test_a (__main__.MyTestCase) ... ok
test_b (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 2 tests in 0.000s

OK
%

0 コメント:

コメントを投稿