-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] Improve the suite of tests. Use queues instead of stacks for th…
…e simulated player actions and the test collection.
- Loading branch information
Showing
3 changed files
with
106 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from collections import deque | ||
|
||
|
||
class Queue: | ||
def __init__(self, iterable=(), maxlen=None, name=''): | ||
self._container = deque(iterable=iterable, maxlen=maxlen) | ||
self.name = name | ||
|
||
def __iter__(self): | ||
return iter(self._container) | ||
|
||
@property | ||
def is_empty(self): | ||
return not self._container | ||
|
||
def push(self, item): | ||
self._container.append(item) | ||
|
||
def pop(self): | ||
return self._container.popleft() | ||
|
||
def peek(self): | ||
return self._container[0] if not self.is_empty else None | ||
|
||
def __len__(self): | ||
return len(self._container) | ||
|
||
def __str__(self): | ||
return f"Queue({repr(list(self._container))})" | ||
|
||
def __repr__(self): | ||
return f"Queue({repr(list(self._container))})" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from collections import deque | ||
|
||
|
||
class Stack: | ||
def __init__(self, iterable=(), maxlen=None, name='', num=0): | ||
self._container = deque(iterable=iterable, maxlen=maxlen) | ||
self.name = name | ||
self.num = num | ||
|
||
def __iter__(self): | ||
return iter(self._container) | ||
|
||
@property | ||
def is_empty(self): | ||
return not self._container | ||
|
||
def push(self, item): | ||
self._container.append(item) | ||
|
||
def pop(self): | ||
return self._container.pop() | ||
|
||
def peek(self): | ||
return self._container[-1] if not self.is_empty else None | ||
|
||
def __len__(self): | ||
return len(self._container) | ||
|
||
def __str__(self): | ||
return f"stack({repr(list(self._container))})" | ||
|
||
def __repr__(self): | ||
return f"stack({repr(list(self._container))})" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters