## 2019年9月4日水曜日

### Python - Making Choices - A Boolean Type, Boolean Operators(and, not, or), expressions

Practical Programming: An Introduction to Computer Science Using Python 3.6 (Paul Gries(著)、Jennifer Campbell(著)、Jason Montojo(著)、Pragmatic Bookshelf)のChapter 5(Making Choices)、Exercises 2の解答を求めてみる。

コード

Python 3

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

class MyTestCase(TestCase):
def setUp(self):
pass

def tearDown(self):
pass

def test_a(self):
def f(x, y):
return x and y
self.assertTrue(f(True, True))
self.assertFalse(f(True, False))
self.assertFalse(f(False, True))
self.assertFalse(f(False, False))

def test_b(self):
def f(x, y):
return not x
self.assertFalse(f(True, True))
self.assertFalse(f(True, False))
self.assertTrue(f(False, True))
self.assertTrue(f(False, False))

def test_c(self):
def f(x, y):
return x or y
self.assertTrue(f(True, True))
self.assertTrue(f(True, False))
self.assertTrue(f(False, True))
self.assertFalse(f(False, False))

if __name__ == '__main__':
main()
```

```\$ ./sample2.py
test_a (__main__.MyTestCase) ... ok
test_b (__main__.MyTestCase) ... ok
test_c (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 3 tests in 0.000s

OK
\$
```