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)
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)
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'
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"
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'
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'
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"
def test_add_remove_one_cat(shelter): shelter.enqueue(Dog("chester")) shelter.enqueue(Cat("doggo")) assert shelter.dequeue("cat").name == "doggo"
def test_add_remove_one_dog(shelter): shelter.enqueue(Dog("alvin")) shelter.enqueue(Cat("barb")) assert shelter.dequeue("dog").name == "alvin"
def test_dog(): assert Cat("Karma")
def test_dog(): assert Cat('Cat')
def test_queue_empty_dequeue(): animal_queue = AnimalShelter() with pytest.raises(EmptyStackException): assert animal_queue.dequeue(Cat())
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'
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'
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
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()])
def test_creating_cat_object(): assert Cat().name == 'Ima cat'