Parts I and II of lab complete
This commit is contained in:
parent
c5ed9459c1
commit
05ed95fb65
|
@ -0,0 +1,5 @@
|
|||
# Title. No more than 50 characters ----> |
|
||||
|
||||
# Leave a single blank line between the title and the body (excluding comments)
|
||||
|
||||
# Body. Write a description of what you've changed.
|
|
@ -0,0 +1,90 @@
|
|||
# Each of the functions below expects a list of dictionaries as its first
|
||||
# argument. Two examples of the expected input are provided in people.family
|
||||
# and people.friends.
|
||||
|
||||
# Your job is to complete these functions. Remove the NotImplementedError from
|
||||
# each and instead write code which returns the expected values.
|
||||
|
||||
def count_people(people):
|
||||
"""Counts the number of people.
|
||||
|
||||
>>> count_people(family)
|
||||
5
|
||||
>>> count_people(friends)
|
||||
10
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def get_email(people, name):
|
||||
"""Returns the named person's email address. If there is no such person, returns None.
|
||||
|
||||
>>> get_email(family, "Tad Winters")
|
||||
"ligula.aenean@hotmail.edu"
|
||||
>>> get_email(friends, "Tad Winters")
|
||||
None
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def count_favorite_colors(people, name):
|
||||
"""Returns the number of colors liked by the named person. If there is no such person, returns None.
|
||||
|
||||
>>> count_favorite_colors(family, "Tad Winters")
|
||||
2
|
||||
>>> count_favorite_colors(family, "Raphael Chambers")
|
||||
1
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def people_who_like_color(people, color):
|
||||
"""Returns a list containing only those people who like the given color.
|
||||
>>> people_who_like_color(family, "yellow")
|
||||
[
|
||||
{
|
||||
"name": "Walker Hurley",
|
||||
"email": "auctor.odio@icloud.ca",
|
||||
"favorite_colors": ["red", "yellow", "blue", "orange"],
|
||||
},
|
||||
{
|
||||
"name": "Clementine Joseph",
|
||||
"email": "hendrerit@aol.co.uk",
|
||||
"favorite_colors": ["yellow", "aqua", "black"],
|
||||
}
|
||||
]
|
||||
>>> people_who_like_color(family, "indigo")
|
||||
[]
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def count_people_who_like_color(people, color):
|
||||
"""Returns the number of people who like a given color.
|
||||
|
||||
>>> count_people_who_like_color(family, "red")
|
||||
2
|
||||
>>> count_people_who_like_color(family, "orange")
|
||||
1
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def get_color_dict(people):
|
||||
"""Returns a dict showing how many people like each color.
|
||||
Any color liked by any of the people will be included, and only colors
|
||||
liked by someone will be included. The order of items in the dict doesn't matter.
|
||||
|
||||
>>> get_color_dict(family)
|
||||
{
|
||||
"aqua": 2,
|
||||
"red": 2,
|
||||
"blue": 2,
|
||||
"black": 2,
|
||||
"white": 1,
|
||||
"grey": 1,
|
||||
"yellow": 2,
|
||||
"orange": 1,
|
||||
}
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
family = [
|
||||
{
|
||||
"name": "Tad Winters",
|
||||
"email": "ligula.aenean@hotmail.edu",
|
||||
"favorite_colors": ["aqua", "red"],
|
||||
},
|
||||
{
|
||||
"name": "Raphael Chambers",
|
||||
"email": "ac.eleifend.vitae@protonmail.com",
|
||||
"favorite_colors": ["blue"],
|
||||
},
|
||||
{
|
||||
"name": "Perry Calderon",
|
||||
"email": "mus.donec@outlook.org",
|
||||
"favorite_colors": ["black", "white", "grey"],
|
||||
},
|
||||
{
|
||||
"name": "Walker Hurley",
|
||||
"email": "auctor.odio@icloud.ca",
|
||||
"favorite_colors": ["red", "yellow", "blue", "orange"],
|
||||
},
|
||||
{
|
||||
"name": "Clementine Joseph",
|
||||
"email": "hendrerit@aol.co.uk",
|
||||
"favorite_colors": ["yellow", "aqua", "black"],
|
||||
}
|
||||
]
|
||||
|
||||
friends = [
|
||||
{
|
||||
"name": "Connor Rodriguez",
|
||||
"email": "maecenas@yahoo.edu",
|
||||
"favorite_colors": ["aqua", "teal", "sea foam", "turquoise"],
|
||||
},
|
||||
{
|
||||
"name": "Rosalyn Hubbard",
|
||||
"email": "elit.pharetra@google.edu",
|
||||
"favorite_colors": ["red", "yellow", "black"],
|
||||
},
|
||||
{
|
||||
"name": "Thomas Puckett",
|
||||
"email": "sit.amet@aol.net",
|
||||
"favorite_colors": ["blue"],
|
||||
},
|
||||
{
|
||||
"name": "Yuli Reynolds",
|
||||
"email": "augue.malesuada@google.edu",
|
||||
"favorite_colors": [],
|
||||
},
|
||||
{
|
||||
"name": "Joy Tate",
|
||||
"email": "risus.a.ultricies@hotmail.org",
|
||||
"favorite_colors": ["white", "grey", "sand"],
|
||||
},
|
||||
{
|
||||
"name": "Prescott Price",
|
||||
"email": "cursus.nunc@yahoo.edu",
|
||||
"favorite_colors": ["red", "blue", "green"],
|
||||
},
|
||||
{
|
||||
"name": "Josephine Keller",
|
||||
"email": "nulla@protonmail.edu",
|
||||
"favorite_colors": ["black"],
|
||||
},
|
||||
{
|
||||
"name": "Isadora Carney",
|
||||
"email": "sagittis.lobortis@protonmail.co.uk",
|
||||
"favorite_colors": ["aqua", "lime"],
|
||||
},
|
||||
{
|
||||
"name": "Jelani West",
|
||||
"email": "vehicula.pellentesque.tincidunt@yahoo.org",
|
||||
"favorite_colors": ["grey", "beige", "tan"],
|
||||
},
|
||||
{
|
||||
"name": "Gay Pittman",
|
||||
"email": "etiam.bibendum@yahoo.org",
|
||||
"favorite_colors": ["yellow"],
|
||||
}
|
||||
]
|
|
@ -0,0 +1,15 @@
|
|||
[tool.poetry]
|
||||
name = "mwc-pedprog-unit01-lab02"
|
||||
version = "0.1.0"
|
||||
description = ""
|
||||
authors = ["Chris <github.com@accounts.chrisproctor.net>"]
|
||||
license = "MIT"
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.9"
|
||||
|
||||
[tool.poetry.dev-dependencies]
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core>=1.0.0"]
|
||||
build-backend = "poetry.core.masonry.api"
|
|
@ -0,0 +1,82 @@
|
|||
from unittest import TestCase, main
|
||||
from people import friends, family
|
||||
from friend_functions_solutions import (
|
||||
count_people,
|
||||
get_email,
|
||||
count_favorite_colors,
|
||||
people_who_like_color,
|
||||
count_people_who_like_color,
|
||||
get_color_dict,
|
||||
)
|
||||
|
||||
class TestCountPeople(TestCase):
|
||||
def test_returns_correct_value(self):
|
||||
self.assertEqual(count_people(family), 5)
|
||||
self.assertEqual(count_people(friends), 10)
|
||||
|
||||
class TestGetEmail(TestCase):
|
||||
def test_returns_email_when_person_found(self):
|
||||
self.assertEqual(get_email(family, "Perry Calderon"), "mus.donec@outlook.org")
|
||||
self.assertEqual(get_email(friends, "Joy Tate"), "risus.a.ultricies@hotmail.org")
|
||||
|
||||
def test_returns_none_when_person_missing(self):
|
||||
self.assertEqual(get_email(family, "Ken Kesey"), None)
|
||||
|
||||
class TestCountFavoriteColors(TestCase):
|
||||
def test_returns_len_favorite_colors_when_person_found(self):
|
||||
self.assertEqual(count_favorite_colors(family, "Tad Winters"), 2)
|
||||
self.assertEqual(count_favorite_colors(friends,"Connor Rodriguez"), 4)
|
||||
self.assertEqual(count_favorite_colors(friends, "Yuli Reynolds"), 0)
|
||||
|
||||
def test_returns_none_when_person_missing(self):
|
||||
self.assertEqual(count_favorite_colors(family, "Ken Kesey"), None)
|
||||
|
||||
class TestPeopleWhoLikeColor(TestCase):
|
||||
def test_returns_correct_length(self):
|
||||
self.assertEqual(len(people_who_like_color(family, "blue")), 2)
|
||||
self.assertEqual(len(people_who_like_color(family, "purple")), 0)
|
||||
|
||||
def test_returns_full_dicts(self):
|
||||
result = people_who_like_color(family, "orange")
|
||||
self.assertEqual(len(result), 1)
|
||||
self.assertEqual(result[0]["email"], "auctor.odio@icloud.ca")
|
||||
|
||||
class TestCountPeopleWhoLikeColor(TestCase):
|
||||
def test_returns_correct_count(self):
|
||||
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, "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)
|
||||
|
||||
main()
|
Loading…
Reference in New Issue