Exemplo n.º 1
0
class RoomTests(unittest.TestCase):
    def setUp(self):
        self.room = Room("Smith", 1000, 3)

    def test_room_init_expect_attributes_to_be_set(self):
        self.assertEqual("Smith", self.room.family_name)
        self.assertEqual(1000, self.room.budget)
        self.assertEqual(3, self.room.members_count)
        self.assertEqual([], self.room.children)
        self.assertEqual(0, self.room.expenses)

    def test_room_expenses_setter__when_value_is_less_than_zero_expect_value_error(
            self):
        with self.assertRaises(ValueError) as err:
            self.room.expenses = -20
        self.assertEqual("Expenses cannot be negative", str(err.exception))

    def test_room_calculate_expenses__expect_calculation_of_all_costs_for_one_month(
            self):
        self.room.children = [Child(5, 5, 5), Child(4, 6, 2)]
        appliances = [Fridge(), Laptop(), Stove(), TV()]
        self.room.calculate_expenses(self.room.children, appliances)

        expected_cost = 942
        actual_cost = self.room.expenses
        self.assertEqual(expected_cost, actual_cost)
Exemplo n.º 2
0
class TestRoom(unittest.TestCase):
    def setUp(self) -> None:
        self.room = Room('Lindemann', 450, 1)

    def test_init__expect_attrs_set(self) -> None:
        self.assertEqual(self.room.family_name, 'Lindemann')
        self.assertEqual(self.room.budget, 450)
        self.assertEqual(self.room.members_count, 1)
        self.assertEqual(self.room.children, [])
        self.assertTrue(hasattr(self.room, 'expenses'))

    def test_setter_expenses__when_valid__expect_expenses_updates(
            self) -> None:
        self.room.expenses = 45
        self.assertEqual(self.room.expenses, 45)

    def test_setter_expenses__when_invalid__expect_exception(self) -> None:
        with self.assertRaises(ValueError) as context:
            self.room.expenses = -30

        self.assertEqual(context.exception.args[0],
                         'Expenses cannot be negative')

    def test_calculate_expenses(self) -> None:
        appliances = [Appliance(10), Appliance(8)]
        appliances1 = [Appliance(8), Appliance(10)]
        self.room.calculate_expenses(appliances, appliances1)

        self.assertEqual(self.room.expenses, 1080)
Exemplo n.º 3
0
class TestsRoom(unittest.TestCase):
    def setUp(self):
        self.room = Room('room_name', 1000, 4)

    def test_class_attributes_existence_upon_initialization(self):
        self.assertEqual(self.room.family_name, 'room_name')
        self.assertEqual(self.room.budget, 1000)
        self.assertEqual(self.room.members_count, 4)
        self.assertEqual(self.room.children, [])

    def test_expenses_is_property(self):
        self.assertEqual(self.room.expenses, 0)

    def test_set_expenses_to_positive_value_OK(self):
        self.room.expenses = 10
        self.assertEqual(self.room.expenses, 10)

    def test_set_expenses_to_negative_value_NOK(self):
        with self.assertRaises(ValueError) as exc:
            self.room.expenses = -10
        self.assertEqual(str(exc.exception), "Expenses cannot be negative")

    def test_calculate_expenses_with_zero_arguments(self):
        lst = []
        self.room.calculate_expenses(*lst)
        self.assertEqual(self.room.expenses, 0)
Exemplo n.º 4
0
class TestRoom(TestCase):
    def setUp(self):
        self.room = Room("Johson", 1800, 4)

    def test_init(self):
        self.assertEqual("Johson", self.room.family_name)
        self.assertEqual(1800, self.room.budget)
        self.assertEqual(4, self.room.members_count)
        self.assertEqual([], self.room.children)
        self.assertEqual(0, self.room.expenses)

    def test_set_expenses(self):
        self.room.expenses = 20
        self.assertEqual(20, self.room.expenses)

    def test_set_expenses_raises(self):
        with self.assertRaises(ValueError) as ex:
            self.room.expenses = -5

        self.assertEqual("Expenses cannot be negative", str(ex.exception))

    def test_calculate_expenses_with_children(self):
        fridge = [Fridge()]
        child = [Child(2, 1, 2, 3)]
        self.room.calculate_expenses(fridge, child)
        self.assertEqual(276, self.room.expenses)

    def test_calculate_expenses_without_children(self):
        fridge = [Fridge()]

        self.room.calculate_expenses(fridge)
        self.assertEqual(36, self.room.expenses)
Exemplo n.º 5
0
class TestRoom(unittest.TestCase):
    def setUp(self):
        self.room = Room('name', 1000, 3)

    def test_init(self):
        self.assertEqual('name', self.room.family_name)
        self.assertEqual(1000, self.room.budget)
        self.assertEqual(3, self.room.members_count)
        self.assertEqual(0, len(self.room.children))
        self.assertEqual(0, self.room.expenses)

    def test_expenses_setter_raises(self):
        with self.assertRaises(ValueError) as ex:
            self.room.expenses = -25
        self.assertEqual("Expenses cannot be negative", str(ex.exception))
        self.assertIsNotNone(ex.exception)

    def test_expenses_setter(self):
        self.assertEqual(0, self.room.expenses)
        self.room.expenses = 25
        self.assertEqual(25, self.room.expenses)

    def test_calculate_expenses(self):
        self.assertEqual(0, self.room.expenses)
        tv = TV()
        appliances = [tv]
        self.room.calculate_expenses(appliances)
        self.assertEqual(45, self.room.expenses)
Exemplo n.º 6
0
class TestRoom(unittest.TestCase):

    def setUp(self):
        self.room = Room("Vatovi", 2000, 2)

    def test_room_init(self):
        self.assertEqual(self.room.family_name, "Vatovi")
        self.assertEqual(self.room.budget, 2000)
        self.assertEqual(self.room.members_count, 2)
        self.assertEqual(self.room.children, [])
        self.assertEqual(self.room.expenses, 0)

    def test_if_setter_set_the_expenses(self):
        self.room.expenses = 20
        self.assertEqual(self.room.expenses, 20)

    def test_room_setter_raises_exception(self):
        with self.assertRaises(ValueError, msg="Expenses cannot be negative") as context:
            self.room.expenses = -20
        self.assertEqual(context.msg, "Expenses cannot be negative")

    def test_room_calculate_expenses(self):
        appliances = [TV(), Laptop(), Fridge()] * self.room.members_count
        child1 = Child(5, 2, 3, 1)
        children = [child1]
        self.room.calculate_expenses(appliances, children)
        self.assertEqual(self.room.expenses, 552)
Exemplo n.º 7
0
class TestRoom(TestCase):
    def setUp(self):
        self.room = Room("Test", 100, 2)

    def test_init(self):
        self.assertEqual("Test", self.room.family_name)
        self.assertEqual(100, self.room.budget)
        self.assertEqual(2, self.room.members_count)
        self.assertEqual([], self.room.children)
        self.assertEqual(0, self.room.expenses)

    def test_set_expenses_negative_number_raises_exception(self):
        with self.assertRaises(ValueError) as ex:
            self.room.expenses = -2
        self.assertEqual("Expenses cannot be negative", str(ex.exception))

    def test_set_expenses_positive_number(self):
        self.room.expenses = 3
        self.assertEqual(3, self.room.expenses)

    def test_calculate_expenses(self):
        self.assertEqual(0, self.room.expenses)
        c1 = Child(5, 4, 1)
        expected = 300
        self.room.calculate_expenses([c1])
        self.assertEqual(expected, self.room.expenses)
Exemplo n.º 8
0
 def __init__(self, family_name, pension):
     Room.__init__(self,
                   family_name,
                   budget=pension,
                   children=None,
                   expenses=None,
                   members_count=1)
     self.room_cost = 10
 def __init__(self, family_name, salary_one, salary_two, *children):
     Room.__init__(self, family_name, budget=None, members_count=2, children=children, expenses=None)
     self.appliances = [TV(), Fridge(), Laptop()]
     self.budget = salary_one + salary_two
     self.room_cost = 30
     self.members_count += len(children)
     self.child_cost = sum([c.cost for c in children])
     self.expenses = sum([a.get_monthly_expense() * self.members_count for a in self.appliances]) + self.child_cost
Exemplo n.º 10
0
 def __init__(self, family_name, salary):
     Room.__init__(self,
                   family_name,
                   budget=salary,
                   members_count=1,
                   children=None,
                   expenses=None)
     self.room_cost = 10
     self.appliances = [TV()]
     self.expenses = sum([
         a.get_monthly_expense() * self.members_count
         for a in self.appliances
     ])
 def __init__(self, family_name: str, pension_one, pension_two):
     Room.__init__(self,
                   family_name,
                   budget=None,
                   members_count=2,
                   children=None,
                   expenses=None)
     self.room_cost = 15
     self.budget = pension_one + pension_two
     self.appliances = [TV(), Fridge(), Stove()]
     self.expenses = sum([
         a.get_monthly_expense() * self.members_count
         for a in self.appliances
     ])
Exemplo n.º 12
0
 def test_attributes(self):
     room_one = Room('Ivanovi', 1500, 2)
     for attr in [
             'family_name', 'budget', 'members_count', 'children',
             'expenses'
     ]:
         self.assertTrue(hasattr(room_one, attr))
Exemplo n.º 13
0
 def test_initialization(self):
     room_one = Room('Ivanovi', 1500, 2)
     self.assertEqual(room_one.family_name, 'Ivanovi')
     self.assertEqual(room_one.budget, 1500)
     self.assertEqual(room_one.members_count, 2)
     self.assertEqual(room_one.children, [])
     self.assertEqual(room_one.expenses, 0)
Exemplo n.º 14
0
    def test_init(self):
        room = Room('name', 3, 1)
        for atr in ['family_name', 'budget', 'members_count', 'children']:
            self.assertTrue(hasattr(room, atr))

        self.assertEqual('name', room.family_name)
        self.assertEqual(3, room.budget)
        self.assertEqual(1, room.members_count)
        self.assertEqual([], room.children)
        self.assertEqual(0, room.expenses)
Exemplo n.º 15
0
class TestRoom(unittest.TestCase):
    def setUp(self) -> None:
        self.room = Room(name='Tsvetkovy', budget=250, members_count=4)

    def test_room_if_all_attributes_are_set_properly(self):
        self.assertEqual('Tsvetkovy', self.room.family_name)
        self.assertEqual(250, self.room.budget)
        self.assertEqual(4, self.room.members_count)

    def test_room_expenses_property_returns_the_expenses(self):
        result = self.room.expenses()
        self.assertEqual(0, result)
Exemplo n.º 16
0
    def setUp(self) -> None:
        self.room = Room("test", 3, 1)
        for attr in [
                'family_name', 'budget', "members_count", 'children',
                'expenses'
        ]:
            self.assertTrue(hasattr(self.room, attr))

        self.assertEqual('test', self.room.family_name)
        self.assertEqual(3, self.room.budget)
        self.assertEqual(1, self.room.members_count)
        self.assertEqual([], self.room.children)
        self.assertEqual(0, self.room.expenses)
Exemplo n.º 17
0
class RoomTests(TestCaseBase):
    name = 'RoomName'
    budget = 123
    members_count = 4

    def setUp(self):
        self.room = Room(self.name, self.budget, self.members_count)

    def test__init__when_all_valid__expect_be_set(self):
        self.assertEqual(self.name, self.room.family_name)
        self.assertEqual(self.budget, self.room.budget)
        self.assertEqual(self.members_count, self.room.members_count)
        self.assertListEmpty(self.room.children)
        for attr in [
                "family_name", "budget", "members_count", "expenses",
                "children"
        ]:
            self.assertTrue(hasattr(self.room, attr))

    def test__expenses__when_positive__expect_to_set(self):
        self.room.expenses = 5

        self.assertEqual(5, self.room.expenses)

    def test__expenses__when_0__expect_to_set(self):
        self.room.expenses = 0

        self.assertEqual(0, self.room.expenses)

    def test__expenses__when_negative__expect_raise(self):
        with self.assertRaises(ValueError) as context:
            self.room.expenses = -5

        self.assertEqual('Expenses cannot be negative', str(context.exception))

    def test__calculate_expenses_when_zero_consumers__expect_expenses_to_be_0(
            self):
        self.room.calculate_expenses([])
        self.assertEqual(0, self.room.expenses)

    def test__calculate_expenses_when_1_consumer__expect_expenses_to_be_correct(
            self):
        consumers = [Child(1, 2, 3, 4)]
        self.room.calculate_expenses(consumers)

        self.assertEqual(consumers[0].get_monthly_expense(),
                         self.room.expenses)

    def test__calculate_expenses_when_two_consumers__expect_expenses_to_be_correct(
            self):
        appliances = [Child(1, 2, 3, 4)]
        children = [Child(5, 1, 2, 3)]

        self.room.calculate_expenses(appliances, children)
        expected = appliances[0].get_monthly_expense(
        ) + children[0].get_monthly_expense()

        self.assertEqual(expected, self.room.expenses)
Exemplo n.º 18
0
class TestRoom(TestCase):
    name = 'Konst'
    budget = 800
    members_count = 2

    def setUp(self):
        self.room = Room(self.name, self.budget, self.members_count)

    def test_attributes_are_set(self):
        self.assertEqual(self.name, self.room.family_name)
        self.assertEqual(self.budget, self.room.budget)
        self.assertEqual(self.members_count, self.room.members_count)
        self.assertListEqual([], self.room.children)
        for attr in [
                "family_name", "budget", "members_count", "expenses",
                "children"
        ]:
            self.assertTrue(hasattr(self.room, attr))

    def test_expenses__set_positive_value(self):
        self.room.expenses = 50.00
        self.assertEqual(50, self.room.expenses)

    def test_expenses__set_0_value(self):
        self.room.expenses = 0
        self.assertEqual(0, self.room.expenses)

    def test_expenses__cannot_set_negative_value_raises(self):
        with self.assertRaises(ValueError) as ex:
            self.room.expenses = -50.00
        self.assertEqual("Expenses cannot be negative", str(ex.exception))

    def test_calculate_expenses_when_0_consumers(self):
        self.room.calculate_expenses([])
        self.assertEqual(0, self.room.expenses)

    def test_calculate_expenses_when_1_consumer(self):
        child = [Child(10, 5, 6)]
        self.room.calculate_expenses(child)

        self.assertEqual(child[0].get_monthly_expense(), self.room.expenses)

    def test_calculate_expenses_when_more_consumers(self):
        children = [Child(10, 5, 6), Child(5, 5, 5)]
        appliances = [Appliance(15)]
        self.room.calculate_expenses(children, appliances)

        expected = children[0].get_monthly_expense() + children[
            1].get_monthly_expense() + appliances[0].get_monthly_expense()

        self.assertEqual(expected, self.room.expenses)
Exemplo n.º 19
0
class TestRoom(unittest.TestCase):
    family_name = 'TestRoom'
    budget = 500
    members_count = 2

    def setUp(self):
        self.room = Room(self.family_name, self.budget, self.members_count)

    def test_init_attributes__expect_to_be_ok(self):
        self.assertEqual(self.family_name, self.room.family_name)
        self.assertEqual(self.budget, self.room.budget)
        self.assertEqual(self.members_count, self.room.members_count)
        self.assertListEqual([], self.room.children)
        self.assertEqual(0, self.room.expenses)

    def test_expenses__when_positive__expect_to_return_expenses(self):
        self.room.expenses = 5

        self.assertEqual(5, self.room.expenses)

    def test_expenses__when_0__expect_to_return_expenses(self):
        self.room.expenses = 0

        self.assertEqual(0, self.room.expenses)

    def test_expenses__when_negative__expect_to_raise_exception(self):
        with self.assertRaises(ValueError) as e:
            self.room.expenses = -5

        self.assertEqual('Expenses cannot be negative', str(e.exception))

    def test_calculate_expenses__when_no_aplliances__expect_to_be_0(self):
        consumers = []
        self.room.calculate_expenses(consumers)
        self.assertEqual(0, self.room.expenses)

    def test_calculate_expenses__when_one_child__expect_to_calculate_them(self):
        consumers = [Child(5, 2, 2)]
        self.room.calculate_expenses(consumers)
        self.assertEqual(consumers[0].get_monthly_expense(), self.room.expenses)

    def test_calculate_expenses__when_one_child_and_one_appliance__expect_to_calculate_them(self):
        consumers = [Child(5, 2, 2), TV()]
        self.room.calculate_expenses(consumers)
        expect = consumers[0].get_monthly_expense() + consumers[1].get_monthly_expense()
        self.assertEqual(expect, self.room.expenses)
Exemplo n.º 20
0
class TestRoom(unittest.TestCase):
    def setUp(self):
        self.room = Room('a', 1000.0, 2)

    def test_constructor(self):
        self.assertEqual(self.room.family_name, 'a')
        self.assertEqual(self.room.budget, 1000.0)
        self.assertEqual(self.room.members_count, 2)
        self.assertEqual(self.room.children, [])
        self.room.expenses = 500.0
        self.assertEqual(self.room.expenses, 500.0)

    def test_expenses_raises_error_if_negative(self):
        with self.assertRaises(ValueError):
            self.room.expenses = -100

    def test_calculate_expenses_calculates_correctly(self):
        c = Child(10.0, 10.0, 10.0)
        f = Fridge()
        children_list = [c]
        appliances_list = [f]
        self.assertEqual(
            self.room.calculate_expenses(children_list, appliances_list), 31.2)
Exemplo n.º 21
0
class RoomTest(unittest.TestCase):
    def setUp(self) -> None:
        self.room = Room("Double", 100, 2)

    def test_can_be_create_an_instance(self):
        Room("Double", 100, 2)

    def test_attributes(self):
        self.assertEqual(self.room.family_name, "Double")
        self.assertEqual(self.room.budget, 100)
        self.assertEqual(self.room.members_count, 2)
        self.assertEqual(len(self.room.children), 0)

    def test_expenses_value_error(self):
        with self.assertRaises(ValueError) as exc:
            self.room.expenses = -10
        self.assertEqual(str(exc.exception), "Expenses cannot be negative")

    def test_expenses_correct_set(self):
        res = self.room.expenses = 10
        self.assertEqual(res, 10)

    def test_property_expenses(self):
        self.assertEqual(self.room.expenses, 0)

    def test_custom_calculate_expenses(self):
        self.children = [10, 10]
        self.assertEqual(self.room.calculate_expenses(self.room.children, self.room.appliances), 0)
        self.assertEqual(self.room._expenses, 0)

    def test_custom_str_enough_budget(self):
        res = repr(self.room)
        self.assertEqual(f"{self.room.family_name} paid {self.room.expenses + self.room.room_cost:.2f}$ and have {self.room.budget:.2f}$ left.\n", res)

    def test_custom_str_not_enough_budget(self):
        self.room.budget = -1
        self.assertEqual(repr(self.room), f"{self.room.family_name} does not have enough budget and must leave the hotel.\n")
Exemplo n.º 22
0
 def setUp(self):
     self.room = Room('room_name', 1000, 4)
Exemplo n.º 23
0
 def test_can_be_create_an_instance(self):
     Room("Double", 100, 2)
Exemplo n.º 24
0
 def setUp(self) -> None:
     self.room = Room("Double", 100, 2)
Exemplo n.º 25
0
 def test_set_attr(self):
     room = Room('test', 100, 2)
     self.assertEqual(room.family_name, 'test')
     self.assertEqual(room.budget, 100)
     self.assertEqual(room.members_count, 2)
     self.assertEqual(room.children, [])
Exemplo n.º 26
0
 def test_expenses_set_when_eq_or_more_than_0(self):
     room = Room('test', 100, 2)
     room.expenses = 60
     self.assertEqual(room.expenses, 60)
Exemplo n.º 27
0
    def test_expenses_raise_ex_when_less_than_0(self):
        with self.assertRaises(Exception) as ex:
            room = Room('test', 100, 2)
            room.expenses = -6

        self.assertIsNotNone(ex.exception)
Exemplo n.º 28
0
 def setUp(self):
     self.room = Room("Johson", 1800, 4)
Exemplo n.º 29
0
 def test_calculate_expenses(self):
     child = Child(20)
     room_one = Room('Ivanovi', 1500, 2)
     room_one.calculate_expenses(child)
     self.assertEqual(room_one.expenses, 600)
Exemplo n.º 30
0
 def test_expenses_propery_should_raise_value_error(self):
     room_one = Room('Ivanovi', 1500, 2)
     with self.assertRaises(ValueError) as exc:
         room_one.expenses = -10