mirror of
https://github.com/donnemartin/system-design-primer.git
synced 2025-12-17 02:18:56 +03:00
Fixed two issues and add sanity tests. Issue #1: super now calls the right class, #2: decoupled the initiatlization of call_center and employee.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user