Example #1
0
 def test_car_wheels(self):
     man = Car('MAN', 'Truck', 'trailer')
     koenigsegg = Car('Koenigsegg', 'Agera R')
     self.assertEqual(
         [8, 4], [man.num_of_wheels, koenigsegg.num_of_wheels],
         msg=
         'The car shoud have four (4) wheels except its a type of trailer')
Example #2
0
 def test_drive_car(self):
     man = Car('MAN', 'Truck', 'trailer')
     moving_man = man.drive(7)
     moving_man_instance = isinstance(moving_man, Car)
     moving_man_type = type(moving_man) is Car
     self.assertListEqual([True, True, man.speed],
                          [moving_man_instance, moving_man_type, moving_man.speed],
                          msg='The car drive function should return the instance of the Car class')
Example #3
0
    def test_car_speed2(self):
        man = Car('Mercedes', 'SLR500')
        parked_speed = man.speed
        moving_speed = man.drive(3).speed

        self.assertListEqual([parked_speed, moving_speed],
                             [0, 1000],
                             msg='The Mercedes should have speed 0 km/h until you put `the pedal to the metal`')
Example #4
0
    def test_car_speed(self):
        man = Car('MAN', 'Truck', 'trailer')
        parked_speed = man.speed
        moving_speed = man.drive(7).speed

        self.assertListEqual([parked_speed, moving_speed],
                             [0, 77],
                             msg='The Trailer should have speed 0 km/h until you put `the pedal to the metal`')
Example #5
0
    def test_car_speed2(self):
        man = Car('Mercedes', 'SLR500')
        parked_speed = man.speed
        moving_speed = man.drive(3).speed

        self.assertListEqual(
            [parked_speed, moving_speed], [0, 1000],
            msg=
            'The Mercedes should have speed 0 km/h until you put `the pedal to the metal`'
        )
Example #6
0
    def test_car_speed(self):
        man = Car('MAN', 'Truck', 'trailer')
        parked_speed = man.speed
        moving_speed = man.drive(7).speed

        self.assertListEqual(
            [parked_speed, moving_speed], [0, 77],
            msg=
            'The Trailer should have speed 0 km/h until you put `the pedal to the metal`'
        )
Example #7
0
 def test_drive_car(self):
     man = Car('MAN', 'Truck', 'trailer')
     moving_man = man.drive(7)
     moving_man_instance = isinstance(moving_man, Car)
     moving_man_type = type(moving_man) is Car
     self.assertListEqual(
         [True, True, man.speed],
         [moving_man_instance, moving_man_type, moving_man.speed],
         msg=
         'The car drive function should return the instance of the Car class'
     )
Example #8
0
 def test_car_doors(self):
     opel = Car('Opel', 'Omega 3')
     porshe = Car('Porshe', '911 Turbo')
     self.assertListEqual(
         [
             opel.num_of_doors, porshe.num_of_doors,
             Car('Koenigsegg', 'Agera R').num_of_doors
         ], [4, 2, 2],
         msg=
         'The car shoud have four (4) doors except its a Porshe or Koenigsegg'
     )
Example #9
0
 def test_default_car_model(self):
     gm = Car()
     self.assertEqual(
         'GM',
         gm.model,
         msg=
         "The car's model should be called `GM` if no model was passed as an argument"
     )
Example #10
0
 def test_default_car_name(self):
     gm = Car()
     self.assertEqual(
         'General',
         gm.name,
         msg=
         'The car should be called `General` if no name was passed as an argument'
     )
Example #11
0
    def loadgame(self):
        """Loads information (height and width and location of exit) and a list
        of cars from a textfile and uses these to initialise the board. Information
        about cars from the textfile is used to create a list of cars on the board.
        """

        # opens text file
        with open(self.filename, "r") as f:

            # initialise width and height of board
            self.width = int(f.readline().strip())
            self.height = int(f.readline().strip())

            # make list of coordinates with id for each car
            for p in range(self.width * self.height):
                spot = [False, 0]
                self.coordinates.append(spot)

            f.readline()

            self.exitx = int(f.readline().strip())
            self.exity = int(f.readline().strip())

            f.readline()

            # creates cars until EOF
            while True:
                length = int(f.readline().strip())
                x = int(f.readline().strip())
                y = int(f.readline().strip())
                direction = f.readline().strip()
                end = f.readline()
                self.id = self.id + 1

                # adds car to list
                car = Car(length, x, y, direction, self.width, self.id)
                self.coordinates = car.update_coordinates(
                    self.coordinates, "set")
                self.cars.append(car)

                # if EOF, break
                if end == "":
                    break
Example #12
0
 def test_car_type(self):
     koenigsegg = Car('Koenigsegg', 'Agera R')
     self.assertTrue(koenigsegg.is_saloon(),
                     msg='The car type should be saloon if it is not a trailer')
Example #13
0
 def test_car_instance(self):
     honda = Car('Honda')
     self.assertIsInstance(
         honda,
         Car,
         msg='The object should be an instance of the `Car` class')
Example #14
0
 def test_car_type(self):
     koenigsegg = Car('Koenigsegg', 'Agera R')
     self.assertTrue(
         koenigsegg.is_saloon(),
         msg='The car type should be saloon if it is not a trailer')
Example #15
0
 def test_car_properties(self):
     toyota = Car('Toyota', 'Corolla')
     self.assertListEqual(
         ['Toyota', 'Corolla'], [toyota.name, toyota.model],
         msg='The car name and model should be a property of the car')
Example #16
0
 def test_object_type(self):
     honda = Car('Honda')
     self.assertTrue((type(honda) is Car),
                     msg='The object should be a type of `Car`')