-
Notifications
You must be signed in to change notification settings - Fork 32
Description
Description of the bug:
The add_member() method in the Manager class performs no validation before adding to self.team. This leads to two bugs: the same employee can be added multiple times, and a manager can add themselves to their own team. Both cases cause team_size() to return an incorrect count.
To Reproduce
Steps to reproduce the behavior:
Bug 1 - Duplicate entries:
Go to the Manager class and locate the add_member()
Call add_member() multiple times with the same Employee object
Call team_size() on the manager
See incorrect inflated count returned
Bug 2 — Self-assignment:
Go to the Manager class and locate the add_member()
Pass the manager instance itself as the argument to add_member()
Call team_size() on the manager
See count return 1 despite no real team member being added
Example
#Bug 1
e1 = Employee("abc", 30, "A11") #abc is the name, A11 is the id number
mgr = Manager("lmn", 40, "A12")
mgr.add_member(e1)
mgr.add_member(e1)
mgr.add_member(e1)
print(mgr.team_size()) #prints 3 - expected 1
#Bug 2
mgr = Manager("abcd", 40, "M11")
mgr.add_member(mgr)
print(mgr.team_size()) # prints 1 - expected 0
Expected behavior
add_member() should reject duplicate entries and the same employee should only be added once.
add_member() should reject self-assignment and a manager should not be able to add themselves to their own team.
team_size() should always reflect the count of unique, valid team members.
Additional context
Both bugs share the same root cause, add_member() blindly adds with no validation.