# Employee Manager

## Coding Challenge: Employee Management

This code is the very beginning of an employee management system for a company. There are three failing tests that need to be fixed.

* The test code can be assumed to be perfect. Only edit `employees.py`.
* The code is Python 2 and Python 3 compatible and has no dependencies.

#### Running the tests

```
python -m unittests tests
```

```python
class Employee(object):
    def __init__(self, first_name, last_name, job):
        self.first_name = first_name
        self.last_name = last_name
        self.job = job

    def __eq__(self, other):
        if isinstance(other, self.__class__):
            same_name = self.first_name == other.first_name and self.last_name == other.last_name
            same_job = self.job == other.job
            if same_name and same_job:
                return True
        return False

    def __repr__(self):
        return 'Employee(first_name={}, last_name={}, job={})'.format(self.first_name, self.last_name, repr(self.job))


class Job(object):
    def __init__(self, title, salary):
        self.title = title
        self.salary = salary

    def __str__(self):
        print(self.title)

    def __repr__(self):
        return 'Job(title={}, salary={})'.format(self.title, self.salary)


def sort_employees_by_salary(employee_list):
    """
    Returns a new employee list, sorted by low to high salary then last_name
    """
    employee_list.sort(key=lambda employee: (employee.last_name, employee.job.salary))
    return employee_list
```

{% file src="<https://377401609-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdhghxZnRaTVuI8YOtCXs%2Fuploads%2Fgit-blob-c4cce63a3d25e28be0f13d9b7cc9f29a9fe8878c%2Femployees.py?alt=media>" %}
employees.py
{% endfile %}

```python
from unittest import TestCase

from employees import Employee, Job, sort_employees_by_salary


class TestEmployees(TestCase):
    def setUp(self):
        agent = Job('Agent', 40000)
        manager = Job('Manager', 50000)

        self.alice = Employee('Alice', 'Anaheim', manager)
        self.bob = Employee('Bob', 'Bodega', agent)
        self.cindy = Employee('Cindy', 'Camille', agent)
        self.dan = Employee('Dan', 'Dirk', manager)

        self.employee_list = [self.dan, self.cindy, self.bob, self.alice]

    def test_equal(self):
        self.assertEqual(self.alice, self.alice)

    def test_not_equal(self):
        self.assertNotEqual(self.alice, self.bob)

    def test_sort_employees_by_salary_no_side_effects(self):
        frozen_employee_list = list(self.employee_list)
        sort_employees_by_salary(self.employee_list)
        for frozen_employee, employee in zip(frozen_employee_list, self.employee_list):
            self.assertEqual(frozen_employee, employee)

    def test_sort_employees_by_salary_sorting_works(self):
        sorted_employee_list = sort_employees_by_salary(self.employee_list)
        expected = [self.bob, self.cindy, self.alice, self.dan]
        self.assertEqual(sorted_employee_list, expected)


class TestJobs(TestCase):
    def test_str(self):
        job_title = 'Agent'
        job = Job(job_title, 40000)
        self.assertEqual(str(job), job_title)
```

{% file src="<https://377401609-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdhghxZnRaTVuI8YOtCXs%2Fuploads%2Fgit-blob-1d992a2815d7e8596c6f73810d57cf99663806fe%2Ftests.py?alt=media>" %}
test.py
{% endfile %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bryan-guner.gitbook.io/my-docs/pythonnotes/aux-exploration/subject/untitled-5.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
