booleans: tests


what are booleans?: tests

The code in booleans/tests/test_booleans.py from booleans

booleans/tests/test_booleans.py
 1import unittest
 2
 3
 4class TestBooleans(unittest.TestCase):
 5
 6    def test_what_is_false(self):
 7        self.assertIsInstance(False, (bool, int))
 8        self.assertNotIsInstance(
 9            False,
10            (
11                float, tuple, str,
12                list, set, dict,
13            )
14        )
15        self.assertIs(False, False)
16        self.assertIs(bool(False), False)
17        self.assertFalse(bool(False))
18        self.assertFalse(False)
booleans/tests/test_booleans.py
20    def test_what_is_true(self):
21        self.assertIsInstance(True, (bool, int))
22        self.assertNotIsInstance(
23            True,
24            (
25                float, tuple, str,
26                list, set, dict,
27            )
28        )
29        self.assertIs(True, True)
30        self.assertIs(bool(True), True)
31        self.assertTrue(bool(True))
32        self.assertTrue(True)
booleans/tests/test_booleans.py
34    def assert_is_not_the_same_as_false_or_true(self, an_object):
35        self.assertNotEqual(an_object, False)
36        self.assertIsNot(an_object, False)
37        self.assertNotEqual(an_object, True)
38        self.assertIsNot(an_object, True)
39
40    def assert_is_falsy(self, an_object):
41        self.assert_is_not_the_same_as_false_or_true(an_object)
42        self.assertFalse(bool(an_object))
43        self.assertFalse(an_object)
booleans/tests/test_booleans.py
45    def assert_is_truthy(self, an_object):
46        self.assert_is_not_the_same_as_false_or_true(an_object)
47        self.assertTrue(bool(an_object))
48        self.assertTrue(an_object)
49
50    def test_is_none_falsy_or_truthy(self):
51        self.assert_is_falsy(None)
booleans/tests/test_booleans.py
53    def test_is_an_integer_falsy_or_truthy(self):
54        self.assert_is_truthy(-1)
55
56        self.assertEqual(0, False)
57        self.assertIsNot(0, False)
58        self.assertNotEqual(0, True)
59        self.assertIsNot(0, True)
60        self.assertFalse(bool(0))
61        self.assertFalse(0)
62
63        a_positive_integer = 1
64        self.assertNotEqual(a_positive_integer, False)
65        self.assertIsNot(a_positive_integer, False)
66        self.assertEqual(1, True)
67        self.assertIsNot(a_positive_integer, True)
68        self.assertTrue(bool(a_positive_integer))
69        self.assertTrue(a_positive_integer)
booleans/tests/test_booleans.py
71    def test_is_a_float_falsy_or_truthy(self):
72        self.assert_is_truthy(-0.1)
73
74        self.assertEqual(0.0, False)
75        self.assertIsNot(0.0, False)
76        self.assertNotEqual(0.0, True)
77        self.assertIsNot(0.0, True)
78        self.assertFalse(bool(0.0))
79        self.assertFalse(0.0)
80
81        self.assert_is_truthy(0.1)
booleans/tests/test_booleans.py
83    def test_is_a_string_falsy_or_truthy(self):
84        self.assert_is_falsy(str())
85        self.assert_is_truthy('string with things')
86
87    def test_is_a_tuple_falsy_or_truthy(self):
88        self.assert_is_falsy(tuple())
89        self.assert_is_truthy((0, 1, 2, 'n'))
booleans/tests/test_booleans.py
 91    def test_is_a_list_falsy_or_truthy(self):
 92        self.assert_is_falsy(list())
 93        self.assert_is_truthy([0, 1, 2, 'n'])
 94
 95    def test_is_a_set_falsy_or_truthy(self):
 96        self.assert_is_falsy(set())
 97        self.assert_is_truthy({0, 1, 2, 'n'})
 98
 99    def test_is_a_dictionary_falsy_or_truthy(self):
100        self.assert_is_falsy(dict())
101        self.assert_is_truthy({'key': 'value'})
booleans/tests/test_booleans.py
104# NOTES
105# the value of True is 1
106# bool(a dictionary with things) is True
107# bool(a set with things) is True
108# bool(a list with things) is True
109# bool(a tuple with things) is True
110# bool(a string with things) is True
111# bool(a positive number) is True
112# bool(a negative number) is True
113# True is True
114# True is an integer
115# True is a boolean
116# True is NOT False
booleans/tests/test_booleans.py
117# the value of False is 0
118# bool(the empty dictionary) is False
119# bool(the empty set) is False
120# bool(the empty list) is False
121# bool(the empty tuple) is False
122# bool(the empty string) is False
123# bool(zero) is False
124# bool(None) is False
125# False is False
126# False is an integer
127# False is a boolean
128# False is NOT True
129
130
131# Exceptions seen
132# AssertionError