This repository was archived by the owner on Jun 18, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpile.py
More file actions
55 lines (44 loc) · 1.46 KB
/
Copy pathpile.py
File metadata and controls
55 lines (44 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Sion Fandrick
import random
class PileGen:
"""A simple Pile Generator class"""
def __init__(self):
self.pile_list = list()
def create(self, pile):
"""Create the pile to then be drawn from"""
self.pile_list = pile
def read(self):
"""Return the contents of the pile as a list"""
return list(self.pile_list)
def update(self, option_old, option_new=""):
"""Change option in pile, if option_new is blank will delete entry"""
if option_old == option_new:
return
self.pile_list.remove(option_old)
if option_new != "":
self.pile_list.append(option_new)
def get(self, keep=None):
"""Get an option from the Pile, optionally choosing to delete"""
result = random.choice(self.pile_list)
if keep is None:
self.update(result)
return str(result)
if __name__ == '__main__':
pile = PileGen()
pile.create(['a', 'b', 'c'])
assert len(pile.read()) == 3, "Mismatch in size"
for x in range(len(pile.read())):
pile.get(keep=True)
assert len(pile.read()) == 3, "Mismatch in size, after getting with keep set"
start = len(pile.read())
pile.get()
assert len(pile.read()) == 2, "Size not decreasing properly"
old = pile.read()
pile.create(['x', 'y', 'z'])
assert old != pile.read(), "Pile is being created incorrectly"
old = pile.read()
old.sort()
pile.update('x', option_new='1')
new = pile.read()
new.sort()
assert old[0] != new[0], "Update failed with new value %s vs %s" % (old, new)