-
-
Save evrom/b16e644fbd31ff1dabbd89c5dc281ee6 to your computer and use it in GitHub Desktop.
exam4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Make 2 TestCases pass to pass the class | |
run with `python3 -m unittest exam4.py` | |
''' | |
from unittest import TestCase | |
class EasyTestCase(TestCase): | |
''' | |
Arguments: | |
recipient - string | |
sender - optional, defaults to 'Anonymous' | |
Returns: | |
a string with "Hi $RECIPIENT, from $SENDER." | |
Where "$RECIPIENT" is the `recipient`, and | |
$SENDER is the `sender`. If there is no sender, | |
then sender defaults to 'Anonymous' | |
>>> test_function('Bob') | |
'Hi Bob, from Anonymous.' | |
>>> test_function('Sally', sender='Bob') | |
'Hi Sally, from Bob' | |
''' | |
def setUp(self): | |
self.test_function = None # Assign to your function | |
def test_ex1(self): | |
result = self.test_function('Donald', sender='Kersti') | |
self.assertEqual(result, 'Hi Donald, from Kersti.') | |
def test_ex2(self): | |
result = self.test_function('Suvi') | |
self.assertEqual(result, 'Hi Suvi, from Anonymous.') | |
class CountTestCase(TestCase): | |
''' | |
Arguments: | |
n - an even number | |
Returns: | |
a list of numbers counting up to the number. | |
It counts by 2, so only even numbers are shown. | |
>>> test_function(6) | |
[2, 4, 6] | |
''' | |
def setUp(self): | |
self.test_function = None # Assign to your function | |
def test_ex1(self): | |
result = self.test_function(8) | |
self.assertEqual(result, [2, 4, 6, 8]) | |
def test_ex2(self): | |
result = self.test_function(4) | |
self.assertEqual(result, [2, 4]) | |
class EvenMapTestCase(TestCase): | |
''' | |
Arguments: | |
l - list of numbers | |
Returns: | |
dict of numbers mapped to boolean. An even number is mapped to `True`. | |
An odd number is mapped to `False`. | |
>>> test_function([1, 2, 3]) | |
# 1 and 3 are odd, therefore `False`. 2 is even, therefore `True` | |
{1: False, 2: Even, 3: False} | |
''' | |
def setUp(self): | |
self.test_function = None # Assign to your function | |
def test_ex1(self): | |
result = self.test_function([4, 10, 1]) | |
self.assertEqual(result, {4: True, 10: True, 1: False}) | |
def test_ex2(self): | |
result = self.test_function([5, 6, 12]) | |
self.assertEqual(result, {5: False, 6: True, 12: True}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment