From 3a611b2218364f98c32d8d0b5f61c6369036a5f3 Mon Sep 17 00:00:00 2001 From: cheeks <134818917+leftovertoast@users.noreply.github.com> Date: Mon, 10 Mar 2025 00:13:14 +0000 Subject: [PATCH] Completed 11-3 Employee --- Chapter_11/city_functions_expanded.py | 6 ++++++ Chapter_11/employee.py | 11 +++++++++++ Chapter_11/test_cities_expanded.py | 9 +++++++++ Chapter_11/test_employee.py | 18 ++++++++++++++++++ 4 files changed, 44 insertions(+) create mode 100644 Chapter_11/city_functions_expanded.py create mode 100644 Chapter_11/employee.py create mode 100644 Chapter_11/test_cities_expanded.py create mode 100644 Chapter_11/test_employee.py diff --git a/Chapter_11/city_functions_expanded.py b/Chapter_11/city_functions_expanded.py new file mode 100644 index 0000000..2ecdceb --- /dev/null +++ b/Chapter_11/city_functions_expanded.py @@ -0,0 +1,6 @@ +# Exercise 11-02 Population +# Learning Objective: Create a unit test for a function and run it. + +def create_city_string(city, country, population=''): + new_string = city.title() + ", " + country.title() + ", " + population + return new_string diff --git a/Chapter_11/employee.py b/Chapter_11/employee.py new file mode 100644 index 0000000..285e684 --- /dev/null +++ b/Chapter_11/employee.py @@ -0,0 +1,11 @@ +# Exercise 11-3 Employee +# Create and test a class + +class Employee: + def __init__(self, first_name, last_name, salary): + self.first_name = first_name + self.last_name = last_name + self.salary = salary + + def give_raise(self, increase=5000): + self.salary += increase diff --git a/Chapter_11/test_cities_expanded.py b/Chapter_11/test_cities_expanded.py new file mode 100644 index 0000000..9ab3cf3 --- /dev/null +++ b/Chapter_11/test_cities_expanded.py @@ -0,0 +1,9 @@ +from city_functions_expanded import create_city_string + +def test_city_country(): + output_string = create_city_string("talahasse", "united states", "12000000") + print(f"{output_string}") + #assert output_string == "Talahasse, United States" + assert output_string == "Talahasse, United States, 12000000" + +test_city_country() \ No newline at end of file diff --git a/Chapter_11/test_employee.py b/Chapter_11/test_employee.py new file mode 100644 index 0000000..cfed350 --- /dev/null +++ b/Chapter_11/test_employee.py @@ -0,0 +1,18 @@ +from employee import Employee + + +def test_default_raise(): + new_employee1 = Employee("Fred", "Bred", 4000) + new_employee1.give_raise() + assert new_employee1.salary == 9000 + print(f"{new_employee1.salary}") + + +def test_custom_raise(): + new_employee1 = Employee("Fred", "Bred", 4000) + new_employee1.give_raise(10000) + assert new_employee1.salary == 14000 + print(f"{new_employee1.salary}") + +test_default_raise() +test_custom_raise()