示例#1
0
 def test_raise_error_town(self):
     with self.assertRaises(ValueError, msg="Ups should raise error") as context:
         car1 = Car(200.50, "Sedan", "BENTLEY", "47af87f3-3a96-422f-b357-237e4b3684a9", 50000.00)
         car2 = Car(250.40, "Truck", "BMW", "47af87f3-3a96-422f-b357-237e4b3684a9", 20000.00)
         garage = Garage("MISTAKE", 3, [car1, car2], uuid.uuid4())
         self.assertTrue("Incorrect garage town" in context.exception.args)
         self.fail()
示例#2
0
 def test_garage_town(self):
     car1 = Car(200.50, "Sedan", "BENTLEY", "47af87f3-3a96-422f-b357-237e4b3684a9", 50000.00)
     car2 = Car(250.40, "Truck", "BMW", "47af87f3-3a96-422f-b357-237e4b3684a9", 20000.00)
     garage1 = Garage("Amsterdam", 3, [car1, car2], uuid.uuid4())
     expected = "Amsterdam"
     actual = garage1.town
     self.assertEqual(actual, expected, msg=f"Town should be one of {constants.CARS_TYPES}")
示例#3
0
 def test_garage_cars(self):
     car1 = Car(200.50, "Sedan", "BENTLEY", "47af87f3-3a96-422f-b357-237e4b3684a9", 50000.00)
     car2 = Car(250.40, "Truck", "BMW", "47af87f3-3a96-422f-b357-237e4b3684a9", 20000.00)
     garage1 = Garage("Amsterdam", 3, [car1, car2], uuid.uuid4())
     expected = [car1, car2]
     actual = garage1.cars
     self.assertEqual(actual, expected)
示例#4
0
 def test_remove_car(self):
     car1 = Car(200.50, "Sedan", "BENTLEY", "47af87f3-3a96-422f-b357-237e4b3684a9", 50000.00)
     car2 = Car(250.40, "Truck", "BMW", "47af87f3-3a96-422f-b357-237e4b3684a9", 20000.00)
     garage = Garage("Amsterdam", 3, [car1, car2], uuid.uuid4())
     garage.remove_car(car2)
     actual = len(garage.cars)
     expected = 1
     self.assertEqual(actual, expected)
示例#5
0
 def test_places(self):
     car1 = Car(200.50, "Sedan", "BENTLEY", "47af87f3-3a96-422f-b357-237e4b3684a9", 50000.00)
     car2 = Car(250.40, "Truck", "BMW", "47af87f3-3a96-422f-b357-237e4b3684a9", 20000.00)
     garage = Garage("Amsterdam", 3, [car1, car2], uuid.uuid4())
     expected = 3
     actual = garage.places
     self.assertEqual(actual, expected)
     self.assertIsInstance(actual, int)
示例#6
0
 def test_equal(self):
     car1 = Car(400.50, "Sedan", "BENTLEY", "47af87f3-3a96-422f-b357-237e4b3684a9", 50000.00)
     car2 = Car(400.50, "Van", "Bugatti", "47af87f3-3a96-422f-b357-237e4b3684a9", 10000.00)
     garage1 = Garage("Amsterdam", 3, [car1], uuid.uuid4())
     garage2 = Garage("Kiev", 3, [car2], uuid.uuid4())
     Tom   = Collectioner("Tom", uuid.uuid4(), [garage1])
     Teddy = Collectioner("Teddy", uuid.uuid4(), [garage2])
     actual_Tom = Tom.hit_hat
     actual_Teddy = Teddy.hit_hat
     self.assertEqual(actual_Tom, actual_Teddy)
示例#7
0
 def test_greater_then(self):
     car1 = Car(200.50, "Sedan", "BENTLEY", "47af87f3-3a96-422f-b357-237e4b3684a9", 50000.00)
     car2 = Car(400.60, "Van", "Bugatti", "47af87f3-3a96-422f-b357-237e4b3684a9", 10000.00)
     garage1 = Garage("Amsterdam", 3, [car1], uuid.uuid4())
     garage2 = Garage("Kiev", 3, [car2], uuid.uuid4())
     Tom = Collectioner("Tom", uuid.uuid4(), [garage1])
     Jerom = Collectioner("Jerom", uuid.uuid4(), [garage2])
     actual_Tom = Tom.hit_hat
     actual_Jerom = Jerom.hit_hat
     self.assertGreater(actual_Tom, actual_Jerom)
示例#8
0
 def test_add_car_no_free_places(self):
     car1 = Car(200.50, "Sedan", "BENTLEY", "47af87f3-3a96-422f-b357-237e4b3684a9", 50000.00)
     car2 = Car(250.40, "Truck", "BMW", "47af87f3-3a96-422f-b357-237e4b3684a9", 20000.00)
     car3 = Car(400.60, "Van", "Bugatti", "47af87f3-3a96-422f-b357-237e4b3684a9", 10000.00)
     car4 = Car(500.90, "Sedan", "Buick", "47af87f3-3a96-422f-b357-237e4b3684a9", 70000.00)
     garage1 = Garage("Amsterdam", 3, [car1, car2], uuid.uuid4())
     garage2 = Garage("Kiev", 3, [car3], uuid.uuid4())
     Tom = Collectioner("Tom", uuid.uuid4(), [garage1, garage2])
     with self.assertRaises(ValueError, msg="Should raise error") as context:
         Tom.add_car(car4)
     self.assertTrue('There are no free places in the specified garage' in context.exception.args)
示例#9
0
 def test_car_count(self):
     car1 = Car(200.50, "Sedan", "BENTLEY", "47af87f3-3a96-422f-b357-237e4b3684a9", 50000.00)
     car2 = Car(250.40, "Truck", "BMW", "47af87f3-3a96-422f-b357-237e4b3684a9", 20000.00)
     car3 = Car(400.60, "Van", "Bugatti", "47af87f3-3a96-422f-b357-237e4b3684a9", 10000.00)
     car4 = Car(500.90, "Sedan", "Buick", "47af87f3-3a96-422f-b357-237e4b3684a9", 70000.00)
     garage1 = Garage("Amsterdam", 3, [car1, car2], uuid.uuid4())
     garage2 = Garage("Kiev", 3, [car3, car4], uuid.uuid4())
     Tom = Collectioner("Tom", uuid.uuid4(), [garage1, garage2])
     actual = Tom.cars_count
     expected = 4
     self.assertEqual(actual, expected)
示例#10
0
 def test_str(self):
     car1 = Car(200.50, "Sedan", "BENTLEY", "47af87f3-3a96-422f-b357-237e4b3684a9", 50000.00)
     car2 = Car(250.40, "Truck", "BMW", "47af87f3-3a96-422f-b357-237e4b3684a9", 20000.00)
     garage = Garage("Amsterdam", 3, [car1, car2], uuid.uuid4())
     actual = str(garage)
     expected = "Town = Amsterdam " \
                "Cars:" \
                "[200.5, 'Sedan', 'BENTLEY', '47af87f3-3a96-422f-b357-237e4b3684a9', 50000.0]" \
                "[250.4, 'Truck', 'BMW', '47af87f3-3a96-422f-b357-237e4b3684a9', 20000.0]" \
                "Maximum places in garage = 3" \
                "Garage owner = c5929fab-7c54-4f51-8ffc-23cb389c197c"
     self.assertEqual(actual, expected)
示例#11
0
    def reset(self):
        self.steps = 0
        self.current_reward = 0
        self.total_game += 1

        self.car = Car()
        self.obstacles = []
        self.bunkers = []
        
        l = list(itertools.product(range(self.height), range(self.width)))
        random.shuffle(l)
        i = 0
        n = 0
        while n < self.num_of_obstacles + self.num_of_bunkers:
            r, c = l[i]
            if (r == 0 and c == 0) or (r == self.height - 1 and c == self.width - 1):
                pass
            else:
                if n < self.num_of_obstacles:
                    self.obstacles.append(Obstacle(r, c))
                else:
                    self.bunkers.append(Bunker(r, c))
                n += 1
            i += 1

        return self._get_state()
 def test_without_bind(self):
     person = Person('Sam', 20, True)
     car = Car('Honda', 'Civic')
     distance = 90
     pair = (person, car, distance)
     age_check_result = person_is_of_age(pair)
     if isinstance(age_check_result, Success):
         print(age_check_result.msg)
         license_check_result = person_is_licensed(pair)
         if isinstance(license_check_result, Success):
             print(license_check_result.msg)
             wheel_check_result = car_has_wheels(pair)
             if isinstance(wheel_check_result, Success):
                 print(wheel_check_result.msg)
                 drive_result = drive(pair)
                 if isinstance(drive_result, Success):
                     print(drive_result.msg)
                     self.assertIsInstance(drive_result, Success)
                 else:
                     print(drive_result.msg)
                     self.assertIsInstance(drive_result, Success)
             else:
                 print(wheel_check_result.msg)
                 self.assertIsInstance(wheel_check_result, Success)
         else:
             print(license_check_result.msg)
             self.assertIsInstance(license_check_result, Success)
     else:
         print(age_check_result.msg)
         self.assertIsInstance(age_check_result, Success)
示例#13
0
 def test_count_garages(self):
     car1 = Car(200.50, "Sedan", "BENTLEY", "47af87f3-3a96-422f-b357-237e4b3684a9", 50000.00)
     garage1 = Garage("Amsterdam", 3, [car1], uuid.uuid4())
     Tom = Collectioner("Tom", uuid.uuid4(), [garage1])
     Ralf = Collectioner("Tom", uuid.uuid4(), [])
     self.assertEqual(Tom.garages_count, 3)
     self.assertEqual(Ralf.garages_count, 1)
示例#14
0
 def test_add_first_car(self):
     car1 = Car(200.50, "Sedan", "BENTLEY", "47af87f3-3a96-422f-b357-237e4b3684a9", 50000.00)
     garage = Garage("Amsterdam", 3, [], uuid.uuid4())
     garage.add_car(car1)
     actual = garage.cars
     expected = [car1]
     self.assertEqual(actual, expected)
 def test_workflow(self):
     person = Person('Sam', 20, True)
     car = Car('Honda', 'Civic')
     car.wheels = 4
     distance = 90
     result = workflow(unit((person, car, distance)), person_is_of_age,
                       person_is_licensed, car_has_wheels, drive)
     self.assertIsInstance(result, Success)
def shiftplanning(sim):

    while True:
        if tick_to_time(sim.env.now) in drivers:
            print(f"{tick_to_time(sim.env.now)} drives starting to work")
            ob = Car(sim, tick_to_time(sim.env.now), 2, 10)
            sim.car_list.append(ob)  #important

        yield sim.env.timeout(1)
示例#17
0
 def test_str(self):
     car = Car(200.32, "Sedan", "BENTLEY", "47af87f3-3a96-422f-b357-237e4b3684a9", 50000.00)
     actual = str(car)
     expected = f"Car price = 200.32, " \
         f"car type = Sedan, " \
         f"car number = 47af87f3-3a96-422f-b357-237e4b3684a9, " \
         f"producer = BENTLEY, " \
         f"mileage = 50000.0 km"
     self.assertEqual(actual, expected)
示例#18
0
 def test_less_equal_then(self):
     car1 = Car(200.50, "Sedan", "BENTLEY", "47af87f3-3a96-422f-b357-237e4b3684a9", 50000.00)
     car2 = Car(250.40, "Truck", "BMW", "47af87f3-3a96-422f-b357-237e4b3684a9", 20000.00)
     car3 = Car(400.60, "Van", "Bugatti", "47af87f3-3a96-422f-b357-237e4b3684a9", 10000.00)
     car4 = Car(500.90, "Sedan", "Buick", "47af87f3-3a96-422f-b357-237e4b3684a9", 70000.00)
     garage1 = Garage("Amsterdam", 3, [car1, car2], uuid.uuid4())
     garage2 = Garage("Kiev", 3, [car3, car4], uuid.uuid4())
     Tom = Collectioner("Tom", uuid.uuid4(), [garage1])
     Denny = Collectioner("Tom", uuid.uuid4(), [garage1])
     Jerom = Collectioner("Jerom", uuid.uuid4(), [garage2])
     actual_Tom = Tom.hit_hat
     actual_Denny = Denny.hit_hat
     actual_Jerom = Jerom.hit_hat
     expected_Tom = 450.90
     expected_Jerom = 901.50
     self.assertEqual(actual_Tom, expected_Tom)
     self.assertEqual(actual_Jerom, expected_Jerom)
     self.assertLess(actual_Tom, actual_Jerom)
     self.assertLessEqual(actual_Tom, actual_Denny)
示例#19
0
 def test_str(self):
     car1 = Car(400.50, "Sedan", "BENTLEY", "47af87f3-3a96-422f-b357-237e4b3684a9", 50000.00)
     garage1 = Garage("Amsterdam", 3, [car1], uuid.uuid4())
     Tom = Collectioner("Tom", uuid.uuid4(), [garage1])
     actual = str(Tom)
     expected = """ Name = Tom 
                 Garages & cars: 
                 ['Amsterdam', 3, 200.5, 'Sedan', 'BENTLEY', '47af87f3-3a96-422f-b357-237e4b3684a9', 50000.0, UUID('4f36a82b-599f-4378-b0e8-5c57d324e15b')] 
                 Garage owner = b7549015-ccaa-4b6d-afa7-0751cf176caa"""
     self.assertEqual(actual, expected)
 def test_without_workflow(self):
     person = Person('Sam', 20, True)
     car = Car('Honda', 'Civic')
     distance = 90
     result = \
         bind(
             bind(
                 bind(
                     bind(
                         unit((person, car, distance)),
                         person_is_of_age)
                     , person_is_licensed)
                 , car_has_wheels)
             , drive)
     self.assertIsInstance(result, Success)
示例#21
0
    def inputFileParse(self):
        with open(self.filepath) as fp:
            line = fp.readline()
            words = line.split()
            self.time = int(words[0])
            numIntersection = int(words[1])
            numStreet = int(words[2])
            numCars = int(words[3])
            score = int(words[4])
            cnt = 1
            line = fp.readline()
            cnt = 2
            for x in range(numStreet):
                words = line.split()
                temp = Road(words[2], int(words[3]))
                if words[0] not in self.IntersectionList.keys():
                    self.IntersectionList[words[0]] = Intersection(words[0])
                self.IntersectionList[words[0]].addOutRoad(temp)

                if words[1] not in self.IntersectionList.keys():
                    self.IntersectionList[words[1]] = Intersection(words[1])
                self.IntersectionList[words[1]].addInRoad(temp)

                temp.addFromAndToIntersection(self.IntersectionList[words[0]],
                                              self.IntersectionList[words[1]])
                self.RoadList[words[2]] = temp
                #
                line = fp.readline()
                cnt = cnt + 1

            for x in range(numCars):
                words = line.split()
                num = int(words[0])
                temp2 = []
                for j in range(num):
                    temp2.append(self.RoadList[words[j + 1]])
                Car(temp2)
                line = fp.readline()
示例#22
0
clock = pygame.time.Clock()
basicfont = pygame.font.SysFont(None, 12)


#GROUPS OF SPRITES
allSpritesList = pygame.sprite.Group()
carList = pygame.sprite.Group()
enemyCarList = pygame.sprite.Group()
lasersList = pygame.sprite.Group()
enemyLasersList = pygame.sprite.Group()


#HOW CAR LOOKS IN GAME
widthOfCar = 65
heightOfCar = 80
playerCar = Car(widthOfCar, heightOfCar, 445, 520, carList, 25, 1)
carList.add(playerCar)
allSpritesList.add(playerCar)


#First Enemy Car
widthOfCar = 120
heightOfCar = 80
howOftenCarShoots = random.randrange(4, 8)
enemyCar = EnemyCar(widthOfCar, heightOfCar, howOftenCarShoots)
randomX = random.randrange(200, 700)
randomY = random.randrange(20, 50)
enemyCar.rect.x = randomX
enemyCar.rect.y = randomY
enemyCarList.add(enemyCar)
allSpritesList.add(enemyCar)
示例#23
0
文件: test.py 项目: ih19708/REP4
#!/usr/bin/env python3

from objects import Car
from model import BridgeSystem
from animation import animate_model

cars = [
    Car(1, 1, 1),
    Car(2, 1, 1),
    Car(3, 1, 1),
    Car(4, 1, 1),
    Car(5, 1, 1),
    Car(6, 1, 1),
    Car(1, -1, 1),
    Car(2, -1, 1),
    Car(3, -1, 1),
    Car(4, -1, 1),
    Car(5, -1, 1),
    Car(6, -1, 1)
]

model = BridgeSystem(10, cars)

animate_model(model)
示例#24
0
pygame.mixer.init()
window = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT), WINDOW_SURFACE)
pygame.display.set_caption('Driving Game Prototype')

road_image = pygame.image.load('track.png')
background = pygame.transform.smoothscale(road_image,
                                          (WINDOW_WIDTH, WINDOW_HEIGHT))
car_image = pygame.image.load('car_image.png').convert_alpha()

car_size = car_image.get_size()
smaller_car = pygame.transform.scale(
    car_image, (int(car_size[0] / 7), int(car_size[1] / 7)))

car_spawn_x = WINDOW_WIDTH // 5
car_spawn_y = WINDOW_HEIGHT // 5
car1 = Car(smaller_car, car_spawn_x, car_spawn_y)
#car1 = Car(car_image, WINDOW_WIDTH//2, WINDOW_HEIGHT//2)

car_sprites = pygame.sprite.Group()
car_sprites.add(car1)

clock = pygame.time.Clock()
done = False
while not done:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True
        elif event.type == pygame.VIDEORESIZE:
            WINDOW_WIDTH = event.w
            WINDOW_HEIGHT = event.h
            window = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT),
示例#25
0
def test_car_error_message():
    with pytest.raises(ValueError) as ve:
        my_car = Car("Ducati", "Monster", 2019)
    assert str(ve.value) == "Ducati does not make cars!"
示例#26
0
 def test_greater_then_equal(self):
     car1 = Car(100.32, "Sedan", "BENTLEY", "47af87f3-3a96-422f-b357-237e4b3684a9", 50000.00)
     car2 = Car(200.32, "Sedan", "BENTLEY", "47af87f3-3a96-422f-b357-237e4b3684a9", 50000.00)
     car3 = Car(200.32, "Sedan", "BENTLEY", "47af87f3-3a96-422f-b357-237e4b3684a9", 50000.00)
     self.assertGreaterEqual(car2.price, car1.price)
     self.assertGreaterEqual(car2.price, car3.price)
示例#27
0
def test_car_error_raised():
    with pytest.raises(ValueError):
        my_car = Car("Ducati", "Monster", 2019)
示例#28
0
 def test_less_then(self):
     car1 = Car(100.32, "Sedan", "BENTLEY", "47af87f3-3a96-422f-b357-237e4b3684a9", 50000.00)
     car2 = Car(200.32, "Sedan", "BENTLEY", "47af87f3-3a96-422f-b357-237e4b3684a9", 50000.00)
     self.assertLess(car1.price, car2.price)
示例#29
0
screen.blit(bg, (0, 0))
screen.set_alpha(None)



# иконка
img = pygame.image.load('static/img/car.png').convert_alpha()
pygame.display.set_icon(img)

# fps
clock = pygame.time.Clock()
pygame.display.update()

# здесь определяются константы, классы и функции
x = 5
car = Car(200, 750, 'static/img/car.png')
car2 = Car(643, 750, 'static/img/car2.png')
speed = 10
left = False
right = False
up = False
down = False
left2 = False
right2 = False
up2 = False
down2 = False
coins =  pygame.sprite.Group()
blocks = pygame.sprite.Group()
pygame.font.init()
font = pygame.font.SysFont('Comic Sans MS', 30)
f = 0
示例#30
0
 def test_car_price(self):
     car = Car(200.32, "Sedan", "BENTLEY", "47af87f3-3a96-422f-b357-237e4b3684a9", 50000.00)
     self.assertIsInstance(car.price, float, msg="Price value should be float")
     self.assertGreater(car.price, 0, msg="Negative value")