> For the complete documentation index, see [llms.txt](https://bryan-guner.gitbook.io/my-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bryan-guner.gitbook.io/my-docs/pythonnotes/aux-exploration/subject/untitled-5.md).

# 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="/files/W5WOgiFFfstlDL9TuCSd" %}
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="/files/ZaIW7BKqbpSTxjP7nBrs" %}
test.py
{% endfile %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
