generated from mwc/lab_weather
	friend_functions.py
This commit is contained in:
		@@ -9,18 +9,18 @@
 | 
				
			|||||||
# Your job is to complete these functions. Remove the NotImplementedError from
 | 
					# Your job is to complete these functions. Remove the NotImplementedError from
 | 
				
			||||||
# each and instead write code which returns the expected values. 
 | 
					# each and instead write code which returns the expected values. 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def count_people(people):
 | 
					# def count_people(people):
 | 
				
			||||||
    """
 | 
					#     """
 | 
				
			||||||
    >>> count_people(family)
 | 
					#     >>> count_people(family)
 | 
				
			||||||
    5
 | 
					#     5
 | 
				
			||||||
    >>> count_people(friends)
 | 
					#     >>> count_people(friends)
 | 
				
			||||||
    10
 | 
					#     10
 | 
				
			||||||
    """
 | 
					#     """
 | 
				
			||||||
    return len(people)
 | 
					#     return len(people)
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
#def get_email(people, name):
 | 
					def get_email(people, name):
 | 
				
			||||||
    """Returns the named person's email address. If there is no such person, returns None.
 | 
					    """Returns the named person's email address. If there is no such person, returns None.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        >>> get_email(family, "Tad Winters")
 | 
					        >>> get_email(family, "Tad Winters")
 | 
				
			||||||
@@ -28,7 +28,12 @@ def count_people(people):
 | 
				
			|||||||
        >>> get_email(friends, "Tad Winters")
 | 
					        >>> get_email(friends, "Tad Winters")
 | 
				
			||||||
        None
 | 
					        None
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
#   raise NotImplementedError()
 | 
					
 | 
				
			||||||
 | 
					    for person in people:
 | 
				
			||||||
 | 
					        if (person["name"]==name):
 | 
				
			||||||
 | 
					            return person["email"]
 | 
				
			||||||
 | 
					           
 | 
				
			||||||
 | 
					    return None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#def count_favorite_colors(people, name):
 | 
					#def count_favorite_colors(people, name):
 | 
				
			||||||
    """Returns the number of colors liked by the named person. If there is no such person, returns None.
 | 
					    """Returns the number of colors liked by the named person. If there is no such person, returns None.
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,7 +4,7 @@
 | 
				
			|||||||
#
 | 
					#
 | 
				
			||||||
# Defines two data structures containing people data, meant to be used
 | 
					# Defines two data structures containing people data, meant to be used
 | 
				
			||||||
# with the functions in `friend_functions.py`.
 | 
					# with the functions in `friend_functions.py`.
 | 
				
			||||||
# You don't need to do anything with thie file.
 | 
					# You don't need to do anything with this file.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
family = [
 | 
					family = [
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@@ -36,7 +36,7 @@ family = [
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
friends = [
 | 
					friends = [
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        "name": "Connor Rodriguez",
 | 
					    "name": "Connor Rodriguez",
 | 
				
			||||||
	"email": "maecenas@yahoo.edu",
 | 
						"email": "maecenas@yahoo.edu",
 | 
				
			||||||
        "favorite_colors": ["aqua", "teal", "sea foam", "turquoise"],
 | 
					        "favorite_colors": ["aqua", "teal", "sea foam", "turquoise"],
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,20 +9,20 @@
 | 
				
			|||||||
from unittest import TestCase, main
 | 
					from unittest import TestCase, main
 | 
				
			||||||
from people import friends, family
 | 
					from people import friends, family
 | 
				
			||||||
from friend_functions import (
 | 
					from friend_functions import (
 | 
				
			||||||
    count_people, 
 | 
					   # count_people, 
 | 
				
			||||||
   # get_email, 
 | 
					   get_email, 
 | 
				
			||||||
   # count_favorite_colors, 
 | 
					   # count_favorite_colors, 
 | 
				
			||||||
   # people_who_like_color, 
 | 
					   # people_who_like_color, 
 | 
				
			||||||
   # count_people_who_like_color,
 | 
					   # count_people_who_like_color,
 | 
				
			||||||
   # get_color_dict,
 | 
					   # get_color_dict,
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestCountPeople(TestCase):
 | 
					# class TestCountPeople(TestCase):
 | 
				
			||||||
    def test_returns_correct_value(self):
 | 
					#     def test_returns_correct_value(self):
 | 
				
			||||||
        self.assertEqual(count_people(family), 5)
 | 
					#         self.assertEqual(count_people(family), 5)
 | 
				
			||||||
        self.assertEqual(count_people(friends), 10)
 | 
					#         self.assertEqual(count_people(friends), 10)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
"""class TestGetEmail(TestCase):
 | 
					class TestGetEmail(TestCase):
 | 
				
			||||||
    def test_returns_email_when_person_found(self):
 | 
					    def test_returns_email_when_person_found(self):
 | 
				
			||||||
        self.assertEqual(get_email(family, "Perry Calderon"), "mus.donec@outlook.org")
 | 
					        self.assertEqual(get_email(family, "Perry Calderon"), "mus.donec@outlook.org")
 | 
				
			||||||
        self.assertEqual(get_email(friends, "Joy Tate"), "risus.a.ultricies@hotmail.org")
 | 
					        self.assertEqual(get_email(friends, "Joy Tate"), "risus.a.ultricies@hotmail.org")
 | 
				
			||||||
@@ -30,61 +30,61 @@ class TestCountPeople(TestCase):
 | 
				
			|||||||
    def test_returns_none_when_person_missing(self):
 | 
					    def test_returns_none_when_person_missing(self):
 | 
				
			||||||
        self.assertEqual(get_email(family, "Ken Kesey"), None)
 | 
					        self.assertEqual(get_email(family, "Ken Kesey"), None)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestCountFavoriteColors(TestCase):
 | 
					# class TestCountFavoriteColors(TestCase):
 | 
				
			||||||
    def test_returns_len_favorite_colors_when_person_found(self):
 | 
					#     def test_returns_len_favorite_colors_when_person_found(self):
 | 
				
			||||||
        self.assertEqual(count_favorite_colors(family, "Tad Winters"), 2)
 | 
					#         self.assertEqual(count_favorite_colors(family, "Tad Winters"), 2)
 | 
				
			||||||
        self.assertEqual(count_favorite_colors(friends,"Connor Rodriguez"), 4)
 | 
					#         self.assertEqual(count_favorite_colors(friends,"Connor Rodriguez"), 4)
 | 
				
			||||||
        self.assertEqual(count_favorite_colors(friends, "Yuli Reynolds"), 0)
 | 
					#         self.assertEqual(count_favorite_colors(friends, "Yuli Reynolds"), 0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_returns_none_when_person_missing(self):
 | 
					#     def test_returns_none_when_person_missing(self):
 | 
				
			||||||
        self.assertEqual(count_favorite_colors(family, "Ken Kesey"), None)
 | 
					#         self.assertEqual(count_favorite_colors(family, "Ken Kesey"), None)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestPeopleWhoLikeColor(TestCase):
 | 
					# class TestPeopleWhoLikeColor(TestCase):
 | 
				
			||||||
    def test_returns_correct_length(self):
 | 
					#     def test_returns_correct_length(self):
 | 
				
			||||||
        self.assertEqual(len(people_who_like_color(family, "blue")), 2)
 | 
					#         self.assertEqual(len(people_who_like_color(family, "blue")), 2)
 | 
				
			||||||
        self.assertEqual(len(people_who_like_color(family, "purple")), 0)
 | 
					#         self.assertEqual(len(people_who_like_color(family, "purple")), 0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_returns_full_dicts(self):
 | 
					#     def test_returns_full_dicts(self):
 | 
				
			||||||
        result = people_who_like_color(family, "orange")
 | 
					#         result = people_who_like_color(family, "orange")
 | 
				
			||||||
        self.assertEqual(len(result), 1)
 | 
					#         self.assertEqual(len(result), 1)
 | 
				
			||||||
        self.assertEqual(result[0]["email"], "auctor.odio@icloud.ca")
 | 
					#         self.assertEqual(result[0]["email"], "auctor.odio@icloud.ca")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestCountPeopleWhoLikeColor(TestCase):
 | 
					# class TestCountPeopleWhoLikeColor(TestCase):
 | 
				
			||||||
    def test_returns_correct_count(self):
 | 
					#     def test_returns_correct_count(self):
 | 
				
			||||||
        self.assertEqual(count_people_who_like_color(friends, "grey"), 2)
 | 
					#         self.assertEqual(count_people_who_like_color(friends, "grey"), 2)
 | 
				
			||||||
        self.assertEqual(count_people_who_like_color(friends, "beige"), 1)
 | 
					#         self.assertEqual(count_people_who_like_color(friends, "beige"), 1)
 | 
				
			||||||
        self.assertEqual(count_people_who_like_color(friends, "cornflower"), 0)
 | 
					#         self.assertEqual(count_people_who_like_color(friends, "cornflower"), 0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# class TestGetColorDict(TestCase):
 | 
				
			||||||
 | 
					#     def test_returns_correct_dict(self):
 | 
				
			||||||
 | 
					#         familyExpected = {
 | 
				
			||||||
 | 
					#             "aqua": 2,
 | 
				
			||||||
 | 
					#             "red": 2,
 | 
				
			||||||
 | 
					#             "blue": 2,
 | 
				
			||||||
 | 
					#             "black": 2,
 | 
				
			||||||
 | 
					#             "white": 1,
 | 
				
			||||||
 | 
					#             "grey": 1,
 | 
				
			||||||
 | 
					#             "yellow": 2,
 | 
				
			||||||
 | 
					#             "orange": 1,
 | 
				
			||||||
 | 
					#         }
 | 
				
			||||||
 | 
					#         friendsExpected = {
 | 
				
			||||||
 | 
					#             "lime": 1, 
 | 
				
			||||||
 | 
					#             "grey": 2, 
 | 
				
			||||||
 | 
					#             "sea foam": 1, 
 | 
				
			||||||
 | 
					#             "aqua": 2, 
 | 
				
			||||||
 | 
					#             "teal": 1, 
 | 
				
			||||||
 | 
					#             "white": 1, 
 | 
				
			||||||
 | 
					#             "red": 2, 
 | 
				
			||||||
 | 
					#             "black": 2, 
 | 
				
			||||||
 | 
					#             "blue": 2, 
 | 
				
			||||||
 | 
					#             "tan": 1, 
 | 
				
			||||||
 | 
					#             "sand": 1, 
 | 
				
			||||||
 | 
					#             "green": 1, 
 | 
				
			||||||
 | 
					#             "beige": 1, 
 | 
				
			||||||
 | 
					#             "turquoise": 1, 
 | 
				
			||||||
 | 
					#             "yellow": 2,
 | 
				
			||||||
 | 
					#         }
 | 
				
			||||||
 | 
					#         self.assertEqual(get_color_dict(family), familyExpected)
 | 
				
			||||||
 | 
					#         self.assertEqual(get_color_dict(friends), friendsExpected)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestGetColorDict(TestCase):
 | 
					 | 
				
			||||||
    def test_returns_correct_dict(self):
 | 
					 | 
				
			||||||
        familyExpected = {
 | 
					 | 
				
			||||||
            "aqua": 2,
 | 
					 | 
				
			||||||
            "red": 2,
 | 
					 | 
				
			||||||
            "blue": 2,
 | 
					 | 
				
			||||||
            "black": 2,
 | 
					 | 
				
			||||||
            "white": 1,
 | 
					 | 
				
			||||||
            "grey": 1,
 | 
					 | 
				
			||||||
            "yellow": 2,
 | 
					 | 
				
			||||||
            "orange": 1,
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        friendsExpected = {
 | 
					 | 
				
			||||||
            "lime": 1, 
 | 
					 | 
				
			||||||
            "grey": 2, 
 | 
					 | 
				
			||||||
            "sea foam": 1, 
 | 
					 | 
				
			||||||
            "aqua": 2, 
 | 
					 | 
				
			||||||
            "teal": 1, 
 | 
					 | 
				
			||||||
            "white": 1, 
 | 
					 | 
				
			||||||
            "red": 2, 
 | 
					 | 
				
			||||||
            "black": 2, 
 | 
					 | 
				
			||||||
            "blue": 2, 
 | 
					 | 
				
			||||||
            "tan": 1, 
 | 
					 | 
				
			||||||
            "sand": 1, 
 | 
					 | 
				
			||||||
            "green": 1, 
 | 
					 | 
				
			||||||
            "beige": 1, 
 | 
					 | 
				
			||||||
            "turquoise": 1, 
 | 
					 | 
				
			||||||
            "yellow": 2,
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        self.assertEqual(get_color_dict(family), familyExpected)
 | 
					 | 
				
			||||||
        self.assertEqual(get_color_dict(friends), friendsExpected)
 | 
					 | 
				
			||||||
"""
 | 
					 | 
				
			||||||
main()
 | 
					main()
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user