Completed 11-3 Employee

This commit is contained in:
cheeks 2025-03-10 00:13:14 +00:00
parent 1befd9566a
commit 3a611b2218
4 changed files with 44 additions and 0 deletions

View File

@ -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

11
Chapter_11/employee.py Normal file
View File

@ -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

View File

@ -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()

View File

@ -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()