Пример #1
0
 def test_uniqueList3(self):
     tab = Table("test1", ['one', 'two', 'three', 'four'], unique=True)
     res1 = tab.use()
     self.assertEqual(res1, 'two')
     tab.clear()
     res2 = tab.use()
     self.assertEqual(res2, 'two')
Пример #2
0
 def test_createNoName(self):
     tab = Table(['one', 'two', 'three', 'four'])
     res1 = tab.use()
     self.assertEqual(res1, 'two')
     res2 = tab.use()
     self.assertEqual(res2, 'two')
     values = tab.results()
     values.sort()
     self.assertEqual(values, ['four', 'one', 'three', 'two'])
Пример #3
0
 def test_uniqueFull(self):
     tab = Table("test8", ['one', 'two', 'three', 'four'], unique=True)
     res1 = tab.use()
     self.assertEqual(res1, 'two')
     res2 = tab.use()
     self.assertEqual(res2, 'one')
     res3 = tab.use()
     self.assertEqual(res3, 'three')
     res4 = tab.use()
     self.assertEqual(res4, 'four')
Пример #4
0
 def test_uniqueFull2(self):
     tab = Table("test8", ['one', 'two', 'three', 'four'], unique=True)
     res1 = tab.use()
     self.assertEqual(res1, 'two')
     res2 = tab.use()
     self.assertEqual(res2, 'one')
     res3 = tab.use()
     self.assertEqual(res3, 'three')
     res4 = tab.use()
     self.assertEqual(res4, 'four')
     # Expect/want the exception here
     self.assertRaises(ValueError, tab.use)
Пример #5
0
 def test_createDict3(self):
     tab = Table("test1", {'roll': '2d2', '2': 'two', '3-4': 'threefour'})
     res1 = tab.use()
     self.assertEqual(res1, 'threefour')
     res2 = tab.roll()
     self.assertEqual(res2, 'threefour')
     values = tab.results()
     values.sort()
     self.assertEqual(values, ['threefour', 'two'])
Пример #6
0
 def test_createDict(self):
     tab = Table("test1", {'1': 'one', '2': 'two'})
     res1 = tab.use()
     self.assertEqual(res1, 'two')
     res2 = tab.roll()
     self.assertEqual(res2, 'two')
     values = tab.results()
     values.sort()
     self.assertEqual(values, ['one', 'two'])
Пример #7
0
 def test_uniqueList2(self):
     tab = Table("test1", ['one', 'two', 'three', 'four'], unique=False)
     res1 = tab.use()
     self.assertEqual(res1, 'two')
     res2 = tab.use()
     self.assertEqual(res2, 'two')
Пример #8
0
# in turn, and the discuss which type of table you should use in which
# situation.

# This first example creates a table out of a list.  Each item in the list has the
# same chance of being selected.

tab1 = Table('PlanetaryOcean',
             ['On Surface', 'Under A Thin Crust', 'Deep Underground'])

# this second example creates a table out of a python dictionary.  The first element
# is the roll, the second is the result for each "line" in the table.

tab2 = Table('Race', {'1-3': 'Human', '4-5': "Elf", '6': 'Dwarf'})

# and you can use these tables in the obvious ways:
print('Using the PlanetaryOcean table: %s' % tab1.use())
print('Using the Race table: %s' % tab2.roll())

# Rule 2: many functions support a "debug=True" option.  If you pass that
# option in, it will print out debugging information designed to help you
# figure out what is going on, and why it is happening.

# You can also do several other interesting things with tables:

# Get a list of all possible results:
print('Possible results for the first table: %s' % tab1.results())

# Set the dice that will be used, and get that later:

tab3 = Table('Race', {
    'roll': '2d4',