forked from donnemartin/system-design-primer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed two issues and add sanity tests. Issue donnemartin#1: super now…
… calls the right class, donnemartin#2: decoupled the initiatlization of call_center and employee.
- Loading branch information
Showing
3 changed files
with
103 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
76 changes: 76 additions & 0 deletions
76
solutions/object_oriented_design/call_center/tests/test_call_center.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
|
||
# test_call_center.py - Generated by CodiumAI | ||
|
||
import pytest | ||
from call_center.call_center import Operator, Supervisor, Director, Call, CallCenter, Rank | ||
|
||
""" | ||
Code Analysis: | ||
- The CallCenter class is used to manage calls in a call center. | ||
- It takes three parameters: operators, supervisors, and directors. | ||
- The queued_calls attribute is a deque object, which is a double-ended queue. | ||
- The dispatch_call() method is used to assign a call to an employee based on the call's rank. | ||
- If an employee is not available, the call is added to the queued_calls deque. | ||
- The _dispatch_call() method is used to assign a call to an employee. | ||
- The notify_call_escalated() and notify_call_completed() methods are used to notify the call center when a call is escalated or completed. | ||
- The dispatch_queued_call_to_newly_freed_employee() method is used to assign a queued call to an employee who has just become available. | ||
""" | ||
|
||
""" | ||
Test Plan: | ||
- test_dispatch_call(): tests that the dispatch_call() method assigns the call to the correct employee based on the call's rank | ||
- test_dispatch_call_with_no_available_employee(): tests that the dispatch_call() method adds the call to the queued_calls deque if no employee is available | ||
- test_add_employee(): tests that the add_employee() method adds the employee to the correct list based on the employee's type | ||
""" | ||
|
||
class TestCallCenter(): | ||
|
||
def setup_method(self, method): | ||
self.operators = [Operator(1, 'John'), Operator(2, 'Jane')] | ||
self.supervisors = [Supervisor(3, 'Bob')] | ||
self.directors = [Director(4, 'Alice')] | ||
self.call_center = CallCenter(self.operators, self.supervisors, self.directors) | ||
|
||
def test_dispatch_call(self): | ||
call = Call(Rank.OPERATOR) | ||
self.call_center.dispatch_call(call) | ||
assert self.operators[0].call == call | ||
|
||
call = Call(Rank.SUPERVISOR) | ||
self.call_center.dispatch_call(call) | ||
assert self.supervisors[0].call == call | ||
|
||
call = Call(Rank.DIRECTOR) | ||
self.call_center.dispatch_call(call) | ||
assert self.directors[0].call == call | ||
|
||
def test_dispatch_call_with_no_available_employee(self): | ||
for employee in self.operators + self.supervisors + self.directors: | ||
employee.take_call(Call(Rank.OPERATOR)) | ||
assert employee.call is not None | ||
|
||
call = Call(Rank.OPERATOR) | ||
self.call_center.dispatch_call(call) | ||
assert len(self.call_center.queued_calls) == 1 | ||
|
||
|
||
def test_add_employee(self): | ||
operator = Operator(5, 'Tom') | ||
supervisor = Supervisor(6, 'Jerry') | ||
director = Director(7, 'Sally') | ||
|
||
self.call_center.add_employee(operator) | ||
assert operator in self.call_center.operators | ||
|
||
self.call_center.add_employee(supervisor) | ||
assert supervisor in self.call_center.supervisors | ||
|
||
self.call_center.add_employee(director) | ||
assert director in self.call_center.directors | ||
|
||
|
||
|
||
|
||
|
||
|