Completed 11-3 Employee
This commit is contained in:
parent
1befd9566a
commit
3a611b2218
6
Chapter_11/city_functions_expanded.py
Normal file
6
Chapter_11/city_functions_expanded.py
Normal 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
11
Chapter_11/employee.py
Normal 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
|
||||||
9
Chapter_11/test_cities_expanded.py
Normal file
9
Chapter_11/test_cities_expanded.py
Normal 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()
|
||||||
18
Chapter_11/test_employee.py
Normal file
18
Chapter_11/test_employee.py
Normal 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()
|
||||||
Loading…
x
Reference in New Issue
Block a user