Exemplo n.º 1
0
 def test_good_limit_filling(self):
     """
     Test filling with limit.
     """
     for limits, car in zip(self.ex1_prc, self.ex1):
         for (prc, ans) in limits:
             c = Car(*car)
             self.assertEqual(c.fill_tank(limit=prc), ans)
Exemplo n.º 2
0
 def test_bad_input_methods(self):
     for car in self.ex1:
         c = Car(*car)
         with self.assertRaises(TypeError):
             c.fill_tank(liters='sto')
         with self.assertRaises(TypeError):
             c.fill_tank(limit='sto')
         with self.assertRaises(TypeError):
             c.fill_tank(limit=1., liters=100)
         with self.assertRaises(ValueError):
             c.fill_tank(other=10)
Exemplo n.º 3
0
 def test_bad_pool(self):
     exs = [
         'sto',
         1.1,
         0.5,
         '20',
         [],
         [1,23]
     ]
     for e in exs:
         with self.assertRaises(TypeError):
             Car.get_carpool(e)
         with self.assertRaises(TypeError):
             DieselCar.get_carpool(e)
Exemplo n.º 4
0
 def test_good_full_filling(self):
     """
     Checking filling the tank to maximum with all the methods.
     """
     for car, ans in zip(self.ex1, self.ex1_full):
         c = Car(*car)
         self.assertEqual(c.fill_tank(), ans)
         c = Car(*car)
         self.assertEqual(c.fill_tank(limit=1.), ans)
         c = Car(*car)
         self.assertEqual(c.fill_tank(liters=ans), ans)
Exemplo n.º 5
0
 def test_good_empty_filling(self):
     """
     Filling tank with nothing.
     """
     for car in self.ex1:
         c = Car(*car)
         self.assertEqual(c.fill_tank(liters=0), 0)
         c = Car(*car)
         self.assertEqual(c.fill_tank(limit=0.), 0)
Exemplo n.º 6
0
 def test_good_pool(self):
     pools = [
         0,
         1,
         2,
         3,
         10,
         100
     ]
     for nr in pools:
         cp = Car.get_carpool(nr)
         cps = [c.brand for c in cp]
         self.assertEqual(len(cps), nr)
         dp = DieselCar.get_carpool(nr)
         dps = [d.brand for d in dp]
         self.assertEqual(len(dps), nr)
Exemplo n.º 7
0
 def test_numers_liters(self):
     for car, (f, a) in zip(self.ex_numbers, self.ex_numbers_liters):
         c = Car(*car)
         self.assertEqual(c.fill_tank(liters=f), a)
Exemplo n.º 8
0
 def test_numbers_limit(self):
     for car, (f, a) in zip(self.ex_numbers, self.ex_numbers_limit):
         c = Car(*car)
         res = c.fill_tank(limit=f)
         self.assertEqual(res, a)
Exemplo n.º 9
0
 def test_method_pool(self):
     for i in [10,20,30]:
         cars = Car.get_carpool(i)
         for c in cars:
             self.assertEqual(c.fill_tank(limit=0.), 0)
             self.assertEqual(c.fill_tank(liters=0), 0)
Exemplo n.º 10
0
 def test_bad_liters(self):
     for liters, car in zip(self.ex1_bad_liters, self.ex1):
         for e in liters:
             c = Car(*car)
             with self.assertRaises(ValueError):
                 c.fill_tank(liters=e)
Exemplo n.º 11
0
 def test_good_liters_filling(self):
     for liters, car in zip(self.ex1_liters, self.ex1):
         for ans in liters:
             c = Car(*car)
             self.assertEqual(c.fill_tank(liters=ans), ans)
Exemplo n.º 12
0
 def test_good_creating(self):
     for car in self.ex1:
         c = Car(*car)
         d = DieselCar(*car)
         self.assertEqual(str(c), info(c, car))
         self.assertEqual(str(d), info(d, car))
Exemplo n.º 13
0
import unittest

from zadanie2 import Car, get_carpool, DieselCar

test_car = Car('Test', 100, 70)
test_diesel_car = DieselCar('Test_diesel', 100, 10)
brand_car = [
    'Peugeot', 'Volvo', 'Skoda', 'Fiat', 'Ford', 'Doge', 'BMW', 'Toyota',
    'Mazda', 'Jaguar'
]


class TestZadanie2(unittest.TestCase):
    def test_fill_tank_over_limit(self):
        with self.assertRaises(Exception) as context:
            test_car.fill_tank(limit=1.1)
        self.assertTrue(
            'You can add limit only on range 0 to 1' in str(context.exception))

    def test_fill_tank_to_many_parameters(self):
        with self.assertRaises(Exception) as context:
            test_car.fill_tank(limit=0.5, liters=10)
        self.assertTrue(
            "You can add only one parameters they are mutually exclusive" in
            str(context.exception))

    def test_fill_tank_under_limit(self):
        with self.assertRaises(Exception) as context:
            limit = 0.5
            test_car.fill_tank(limit=limit)
        self.assertTrue(