ICS4

Module 3 (April 15-23)

Monday April 23

Testing Exercise: Choose two questions from the docstrings quiz and create a test suite (collection of test cases, as practiced for "all fluffy" and "isteenager"). You can choose whichever testing method you like. see the examples below and we will share tomorrow.
When finished, move onto next steps of Software Dev Project

Python Snake (just for fun)

Follow @ericqweinstein's tutorial to make a Snake game using the terminal

Creating Test Suites

Sample exercises from CSC108:

  1. Is Teenager
  2. All Fluffy
  3. Choosing Test Cases Worksheet

Testing Your Code

Read the following articles from The Hitchhiker's Guide to Python:

  1. Structuring Your Project
  2. Testing Your Code
  3. Examples for using pytest

Some Testing Examples

Unittest (docs.python-guide.org)
 
    import unittest

    class TestStringMethods(unittest.TestCase):

        def test_upper(self):
            self.assertEqual('foo'.upper(), 'FOO')  # Edit FOO to see fail output

        def test_isupper(self):
            self.assertTrue('FOO'.isupper())
            self.assertFalse('Foo'.isupper())

        def test_split(self):
            s = 'hello world'
            self.assertEqual(s.split(), ['hello', 'world'])
            # check that s.split fails when the separator is not a string
            with self.assertRaises(TypeError):
                s.split(2)

    if __name__ == '__main__':
        unittest.main()
    
Pytest (https://docs.pytest.org)
 
    def inc(x):
        return x + 1

    def test_answer():
        assert inc(3) == 5 #Fails, since inc(3) is 4, not 5
    
Doctest (https://docs.python-guide.org/)
 
    def square(x):
        """Return the square of x.

        >>> square(2)
        4
        >>> square(-2)
        4
        """

        return x * x

    if __name__ == '__main__':
        import doctest
        doctest.testmod() # Expect no output if everything passes
    
Here are more thorough examples using doctest

Assignment 3: April 23 2019Submit Project Analysis and Planning phases of Software Development Project. Upload a file, Analysis_and_planning.docx, and all supporting docs to your team repo by due date

Quiz 3: TBD 2019 Python topics to Review

Note that in addition to Python 'Topics to Review', any material presented in this module is fair game for the quiz

This work and other materials under github.com/ICS4U-ICS4C,
are licensed under Creative Commons Attribution 4.0 Int'l License.