Ejemplo n.º 1
0
def test_shelter_enqueue_when_not_empty(animal_shelter):
    """The animal shelter should add an animal to the queue when the queue is empty."""

    animals = [Cat(), Cat(), Dog()]
    for animal in animals:
        animal_shelter.enqueue(animal)

    assert isinstance(animal_shelter.peek(), Cat)
Ejemplo n.º 2
0
def test_shelter_dequeue_when_not_empty_and_not_at_top(animal_shelter):
    """The animal shelter removes an animal from the queue when the queue isn't empty and the animal isn't at the front of the animal shelter."""

    animals = [Cat(), Cat(), Dog()]
    for animal in animals:
        animal_shelter.enqueue(animal)

    assert isinstance(animal_shelter.dequeue(Dog), Dog)
Ejemplo n.º 3
0
def test_AnimalShelter_enqueue_multiple():
    animal_queue = AnimalShelter()
    animal_queue.enqueue(Cat())
    animal_queue.enqueue(Cat())
    animal_queue.enqueue(Dog())
    expected = Cat()
    actual = animal_queue.peek()
    assert actual == expected
def test_dequeue_cat():
    shelter1 = AnimalShelter('shelter1')
    cat1 = Cat('cat1')
    cat2 = Cat('cat2')
    cat3 = Cat('cat3')
    shelter1.enqueue(cat1)
    shelter1.enqueue(cat2)
    shelter1.enqueue(cat3)
    assert shelter1.dequeue('cat').name == 'cat1'
def test_enqueue_cats_and_dogs():
    shelter2 = AnimalShelter('shelter2')
    dog1 = Dog('dog1')
    cat1 = Cat('cat1')
    dog2 = Dog('dog2')
    cat2 = Cat('cat2')
    shelter2.enqueue(dog1)
    shelter2.enqueue(cat1)
    shelter2.enqueue(dog2)
    shelter2.enqueue(cat2)
    assert shelter2
def test_shelter_enqueue():
    shelter = AnimalShelter()

    shelter.enqueue(Cat('1'))
    assert shelter.cats.front.name == '1'
    assert shelter.cats.rear.name == '1'
    shelter.enqueue(Dog('2'))
    assert shelter.dogs.rear.name == '2'
    shelter.enqueue(Cat('3'))
    assert shelter.cats.rear.name == '3'
    assert shelter.cats.front.name == '1'
Ejemplo n.º 7
0
def test_shelter_enqueue():
    shelter = AnimalShelter()

    shelter.enqueue(Cat("1"))
    assert shelter.queue1.front.value == "1"
    assert shelter.queue1.rear.value == "1"
    shelter.enqueue(Dog("2"))
    assert shelter.queue1.rear.value == "2"
    shelter.enqueue(Cat("3"))
    assert shelter.queue1.rear.value == "3"
    shelter.enqueue(Dog("4"))
    assert shelter.queue1.rear.value == "4"
    assert shelter.queue1.front.value == "1"
Ejemplo n.º 8
0
def test_shelter_enqueue_when_empty(animal_shelter):
    """The animal shelter should add an animal to the queue when the queue is empty."""

    assert isinstance(animal_shelter.peek(), EmptyStackException)
    cat = Cat()
    animal_shelter.enqueue(cat)
    assert isinstance(animal_shelter.peek(), Cat)
def test_shelter_dequeue():
    shelter = AnimalShelter()

    shelter.enqueue(Cat('1'))
    shelter.enqueue(Dog('2'))
    shelter.enqueue(Cat('3'))
    shelter.enqueue(Cat('4'))
    shelter.enqueue(Dog('5'))

    taken = shelter.dequeue('cat')
    assert taken.type == 'cat'
    assert taken.name == '1'

    taken = shelter.dequeue('cat')
    assert taken.type == 'cat'
    assert taken.name == '3'

    taken = shelter.dequeue('dog')
    assert taken.type == 'dog'
    assert taken.name == '2'
    assert shelter.dogs.front.name == '5'
Ejemplo n.º 10
0
def test_shelter_dequeue():
    shelter = AnimalShelter()

    shelter.enqueue(Cat("1"))
    shelter.enqueue(Dog("2"))
    shelter.enqueue(Cat("3"))
    shelter.enqueue(Cat("a"))
    shelter.enqueue(Dog("4"))

    pet_adopted = shelter.dequeue('cat')
    assert pet_adopted.type == 'cat'
    assert pet_adopted.value == '1'

    pet_adopted = shelter.dequeue('cat')
    assert pet_adopted.type == 'cat'
    assert pet_adopted.value == '3'

    pet_adopted = shelter.dequeue('dog')
    assert shelter.queue1.front.value == "a"
    assert pet_adopted.type == 'dog'
    assert pet_adopted.value == '2'
Ejemplo n.º 11
0
def test_add_remove_multi_cat(shelter):
    shelter.enqueue(Cat("eric"))
    shelter.enqueue(Cat("fred"))
    assert shelter.dequeue("cat").name == "eric"
    assert shelter.dequeue("cat").name == "fred"
Ejemplo n.º 12
0
def test_add_remove_one_cat(shelter):
    shelter.enqueue(Dog("chester"))
    shelter.enqueue(Cat("doggo"))
    assert shelter.dequeue("cat").name == "doggo"
Ejemplo n.º 13
0
def test_add_remove_one_dog(shelter):
    shelter.enqueue(Dog("alvin"))
    shelter.enqueue(Cat("barb"))
    assert shelter.dequeue("dog").name == "alvin"
Ejemplo n.º 14
0
def test_dog():
    assert Cat("Karma")
def test_dog():
    assert Cat('Cat')
Ejemplo n.º 16
0
def test_queue_empty_dequeue():
    animal_queue = AnimalShelter()
    with pytest.raises(EmptyStackException):
        assert animal_queue.dequeue(Cat())
Ejemplo n.º 17
0
def test_shelter_dequeue_not_in_list2():
    shelter = AnimalShelter()
    shelter.enqueue(Cat("1"))
    shelter.enqueue(Dog("2"))
    pet_adopted = shelter.dequeue('parrot')
    assert pet_adopted == None
def test_shelter_dequeue_not_in_list():
    shelter = AnimalShelter()
    shelter.enqueue(Cat('1'))
    shelter.enqueue(Cat('2'))
    pet = shelter.dequeue('dog')
    assert pet == None
def test_cat():
    cat = Cat("Tangerin")
    assert cat.name == 'Tangerin'
    assert cat.type == 'cat'
    assert cat.next == None
def test_add_remove_multi_cat(shelter):
    shelter.enqueue(Cat('Cat'))
    shelter.enqueue(Cat('Cat2'))
    assert shelter.dequeue('cat').name == 'Cat'
    assert shelter.dequeue('cat').name == 'Cat2'
def test_add_remove_one_cat(shelter):
    shelter.enqueue(Dog('Dog'))
    shelter.enqueue(Cat('Cat'))
    assert shelter.dequeue('cat').name == 'Cat'
Ejemplo n.º 22
0
def test_cat():
    cat = Cat("Frodo")
    assert cat.value == 'Frodo'
    assert cat.type == 'cat'
    assert cat.next == None
def test_empty_shelter_enqueue(empty_shelter):
    empty_shelter.enqueue(Cat())
    assert empty_shelter.front.val == 'cat'
Ejemplo n.º 24
0
def test_class_exists():
    AnimalShelter()
    Animal(AnimalType.CAT)
    Cat()
    Dog()
def test_enqueue_small(small_shelter):
    small_shelter.enqueue(Cat())
    assert small_shelter.back.val == 'cat'
def test_cat():
    cat = Cat()
    assert cat
Ejemplo n.º 27
0
def test_shelter_dequeue_capital():
    shelter = AnimalShelter()
    shelter.enqueue(Cat("1"))
    shelter.enqueue(Dog("2"))
    pet_adopted = shelter.dequeue('Dog')
    assert pet_adopted.value == '2'
def small_shelter():
    """Create a short, alternating shelter queue."""
    return shelter([Dog(), Cat(), Dog(), Cat()])
Ejemplo n.º 29
0
def test_creating_cat_object():
    assert Cat().name == 'Ima cat'