Beispiel #1
0
def test_electric_car_charge():
    ec = ElectricCar(100)
    assert ec.drive(70) == 70
    assert ec.drive(50) == 30
    assert ec.drive(50) == 0
    ec.charge()
    assert ec.drive(50) == 50
Beispiel #2
0
def test_electric_car_drice_below_max_range():
    ec = ElectricCar(100)
    assert ec.drive(70) == 70
Beispiel #3
0
def test_electric_car_drice_below_over_max_range_in_to_drives():
    ec = ElectricCar(100)
    assert ec.drive(70) == 70
    assert ec.drive(50) == 30
    assert ec.drive(50) == 0
Beispiel #4
0
    def __init__(self, make, model, year):
        super().__init__(make, model, year)
        self.battery_size = 70
        self.charge_level = 0

    def charge(self):
        self.charge_level = 100
        print("The vehicle is fully charged")

    def fill_tank(self):
        print("This car has no fuel tank!")

my_ecar = ElectricCar('tesla', 'model s', 2016)
my_ecar.charge()
my_ecar.drive()


# Instances as attributes

class Battery():
    def __init__(self, size=70):
        self.size = size
        self.charge_level = 0
    def get_range(self):
        if self.size == 70:
            return 240
        elif self.size == 85:
            return 270

# Using an instance as an attribute
Beispiel #5
0
from car import Car, ElectricCar
from truck import Truck

electric_car = ElectricCar("Tesla", "Model X", 200)
electric_car.drive()

electric_car.fillUp()
from car import Car, ElectricCar

my_beetle = Car('volkswagen', 'beetle', 2016)
my_beetle.fill_tank()
my_beetle.drive()

my_tesla = ElectricCar('tesla', 'model s', 2016)
my_tesla.charge()
my_tesla.drive()