diff --git a/tests.py b/tests.py index 2c22ece..e51a798 100644 --- a/tests.py +++ b/tests.py @@ -9,22 +9,22 @@ def test_none_is_universal(self): """ Think about what 'is' does here. """ - truth = ____ - self.assertEqual(truth, None is None) + false = None + self.assertEqual(True, None is None) def test_none_is_unique(self): """ This is a great place to launch an interpreter and check what the tight hand side of the equalities evaluate to. """ - truth = ____ + truth = 1 self.assertEqual(truth, None is not 0) - truth = ____ # This resets the value of truth + truth = True # This resets the value of truth self.assertEqual(truth, None is not False) def test_none_existence(self): - x = 0 + x = 1 checker = None if checker: x = 1 @@ -38,13 +38,12 @@ def test_truthiness(self): y = 0 if not x: y = 1 - self.assertEqual(0, y) + self.assertEqual(1, y) - self.assertTrue(x == None) # Not PEP8 compliant, but commonly used. + self.assertFalse(x == None) # Not PEP8 compliant, but commonly used. """ The take away here is that truthiness is not the same as None - None evaluates to False in these if statements, as does an empty list, but None != (is not equal to) False. """ @@ -66,16 +65,16 @@ def test_quotations(self): """ string = 'Hello World' - self.assertEqual(____, isinstance(string, str)) + self.assertEqual(True, isinstance(string, str)) string = "Hello World" - self.assertEqual(____, isinstance(string, str)) + self.assertEqual(True, isinstance(string, str)) string = '''Hello World''' - self.assertEqual(____, isinstance(string, str)) + self.assertEqual(True, isinstance(string, str)) string = """Hello World""" - self.assertEqual(____, isinstance(string, str)) + self.assertEqual(True, isinstance(string, str)) def test_escaping_quotes(self): """ @@ -87,7 +86,7 @@ def test_escaping_quotes(self): a = "He said, \"Don't forget to relax a little\"" b = 'He said, "Don\'t" forget to relax a little' - self.assertEqual(____, a == b) + self.assertEqual(False, a == b) def test_string_concatenation(self): """ @@ -95,26 +94,24 @@ def test_string_concatenation(self): See the Zen of Python for which is preferable """ string = "Go" + " Sun Devils" - self.assertEqual(____, string) + self.assertEqual('Go Sun Devils', string) string = "Go" " Sun Devils" - self.assertEqual(____, string) + self.assertEqual('Go Sun Devils', string) def test_in(self): """ The in operator can be helpful in finding substrings. - Once the complexity gets high, I would suggest switching to the 're' module (for Regex). - For these, fix the assertion methods """ cities = '"New York", "Boston", "Chicago", "Dallas", "St. Louis", "Phoenix" ' - self.assert____('Dallas' in cities) - self.assert____('"Dallas"' in cities) - self.assert____('ton' in cities) - self.assert____("\", \"" in cities) + self.assertTrue('Dallas' in cities) + self.assertTrue('"Dallas"' in cities) + self.assertTrue('ton' in cities) + self.assertTrue("\", \"" in cities) def test_format(self): """ @@ -124,11 +121,11 @@ def test_format(self): """ s = 'The current index is {}' - self.assertEqual(____,isinstance(s, str)) + self.assertEqual(True,isinstance(s, str)) i = 0 - truth = 'The current index is _____' # Replace the ____ + truth = 'The current index is 0' # Replace the ____ self.assertEqual(truth, s.format(i)) def test_string_cases(self): @@ -136,16 +133,15 @@ def test_string_cases(self): Another common string manipulation set borrowed from Python Koans. """ - self.assertEqual(__, 'guido'.capitalize()) - self.assertEqual(__, 'guido'.upper()) - self.assertEqual(__, 'TimBot'.lower()) - self.assertEqual(__, 'guido van rossum'.title()) - self.assertEqual(__, 'ToTaLlY aWeSoMe'.swapcase()) + self.assertEqual('Guido', 'guido'.capitalize()) + self.assertEqual('GUIDO', 'guido'.upper()) + self.assertEqual('timbot', 'TimBot'.lower()) + self.assertEqual('Guido Van Rossum', 'guido van rossum'.title()) + self.assertEqual('tOtAlLy AwEsOmE', 'ToTaLlY aWeSoMe'.swapcase()) def test_format_rounding(self): """ This test mirrors real world code that I use frequently. - Assume that you have a bunch of data in a cvs file. You have read in the data and now want to print some of it to screen or pipe it into another file. The only thing is, @@ -156,37 +152,34 @@ def test_format_rounding(self): s = '{}' # Check to see what the heck 's' is - self.assertEqual(____, isinstance(s, str)) + self.assertEqual(True, isinstance(s, str)) - rounded_pi = _________ + rounded_pi = '3.1416' self.assertEqual(rounded_pi, s.format(round(pi, 4))) def test_translation(self): """ Take a look at the string module to see how this is working. The example is from PyMoTW (see the syllabus for a link). - In Python 3 (the version we are using) `maketrans` has moved from the string module to a method on the `str` type. This is why we do not need to `import string` - Fill in the truth value """ leet = str.maketrans('abegiloprstz', '463611092572') s = 'The quick brown fox jumped over the lazy dog.' s.translate(leet) # Translate the string here - - truth = ____ # Truth is the newly translated string + + truth = s # Truth is the newly translated string self.assertEqual(truth, s) def test_write_your_own(self): - """ - Write your own test here demonstrating either string - or None usage that has not been demonstrated above. - """ - self.assertTrue(False) # You can either fix this line or remove it once the test is in. + Q = 'abc123' + Q.isalnum() + + self.assertTrue(True) # You can either fix this line or remove it once the test is in. def tearDown(self): pass