Skip to content

Commit b3f55ca

Browse files
committed
Rename and challenge 12 draft
1 parent 6e80b18 commit b3f55ca

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+192
-6
lines changed

Diff for: README.md

+4-4
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Diff for: python/stack_queue_animal_shelter/README.md

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
from stacks_and_queues.queue import Queue
2+
3+
# 800 297 6877
4+
5+
# have the queue that holds the official list, then a temp queue
6+
# need both an enqueue and dequeue method
7+
# consider dequeueing the whole object instead
8+
9+
class AnimalShelter(Queue):
10+
def __init_(self, shelter_queue=Queue(), temp_queue=Queue(), reset_queue=Queue()):
11+
self.shelter_queue = shelter_queue
12+
self.temp_queue = temp_queue
13+
self.reset_queue = reset_queue
14+
15+
def __repr__(self):
16+
node = self.shelter_queue.front
17+
nodes = []
18+
while node is not None:
19+
nodes.append(str(node.data))
20+
node = node.next
21+
return " -> ".join(nodes)
22+
23+
def __iter__(self):
24+
current_node = self.shelter_queue.front
25+
while current_node is not None:
26+
yield current_node
27+
current_node = current_node.next
28+
29+
def enqueue(self, animal: tuple[str, str]) -> None:
30+
31+
node = Animal(animal)
32+
if self.head is None:
33+
self.head = node
34+
self.front = node
35+
self.back = node
36+
node.next = None
37+
38+
else:
39+
self.back.next = node
40+
self.back = node
41+
node.next = None
42+
43+
44+
class Animal:
45+
def __init__(self, species=str, name=str, _next=None):
46+
self.species = species
47+
self.name = name
48+
self.next = _next
49+
50+
def __repr__(self):
51+
return self
52+
53+
54+
class Dog(Animal):
55+
def __init__(self):
56+
super().__init__()
57+
self.species = "dog"
58+
self.name = ""
59+
60+
61+
class Cat(Animal):
62+
def __init__(self):
63+
super().__init__()
64+
self.species = "cat"
65+
self.name = ""
66+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import pytest
2+
from stack_queue_animal_shelter.stack_queue_animal_shelter import AnimalShelter, Dog, Cat
3+
4+
5+
@pytest.mark.skip("TODO")
6+
def test_single_cat():
7+
shelter = AnimalShelter()
8+
cat = Cat()
9+
shelter.enqueue(cat)
10+
actual = shelter.dequeue("cat")
11+
expected = cat
12+
assert actual == expected
13+
14+
15+
@pytest.mark.skip("TODO")
16+
def test_single_dog():
17+
shelter = AnimalShelter()
18+
dog = Dog()
19+
shelter.enqueue(dog)
20+
actual = shelter.dequeue("dog")
21+
expected = dog
22+
assert actual == expected
23+
24+
25+
@pytest.mark.skip("TODO")
26+
def test_dog_preferred_but_cat_in_front():
27+
shelter = AnimalShelter()
28+
cat = Cat()
29+
dog = Dog()
30+
shelter.enqueue(cat)
31+
shelter.enqueue(dog)
32+
actual = shelter.dequeue("dog")
33+
expected = dog
34+
assert actual == expected
35+
36+
37+
@pytest.mark.skip("TODO")
38+
def test_dog_then_cat():
39+
shelter = AnimalShelter()
40+
cat = Cat()
41+
dog = Dog()
42+
shelter.enqueue(dog)
43+
shelter.enqueue(cat)
44+
shelter.dequeue("dog")
45+
actual = shelter.dequeue("cat")
46+
expected = cat
47+
assert actual == expected
48+
49+
50+
@pytest.mark.skip("TODO")
51+
def test_bad_pref():
52+
shelter = AnimalShelter()
53+
cat = Cat()
54+
dog = Dog()
55+
shelter.enqueue(dog)
56+
shelter.enqueue(cat)
57+
shelter.dequeue("dog")
58+
actual = shelter.dequeue("lizard")
59+
expected = None
60+
assert expected == actual

Diff for: python/stacks_and_queues/__init__.py

Whitespace-only changes.

Diff for: working-directory/stacks_and_queues/queue.py renamed to python/stacks_and_queues/queue.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def __init__(self, head: Any = None, back: Any = None):
1212
self.max_size = 8
1313

1414
def __iter__(self):
15-
current_node = self.top
15+
current_node = self.front
1616
while current_node is not None:
1717
yield current_node
1818
current_node = current_node.next
@@ -45,7 +45,8 @@ def dequeue(self) -> Any:
4545
dead_node.next = None
4646
self.size -= 1
4747

48-
return dead_node.data
48+
# return dead_node.data
49+
return dead_node
4950

5051
def peek(self) -> Any:
5152
if self.head is None:
File renamed without changes.

0 commit comments

Comments
 (0)