Ejemplo n.º 1
0
class TestTableActions(unittest.TestCase):
    def setUp(self):
        # Dice roller always returns this number, so we know what the results should be.
        Rpggen.testData = 2
        #logging.basicConfig(level=logging.DEBUG)
        self.allTables = []
        self.tab1 = Table("test1", ['one', 'two', 'three', 'four'])
        self.allTables.append(self.tab1)
        self.tab2 = Table("test2", {'1': 'one', '2': 'two'})
        self.allTables.append(self.tab2)
        self.tab3 = Table("test3", {
            'roll': '1d4',
            '1-2': 'two',
            '3-4': 'four'
        })
        self.allTables.append(self.tab3)

    def test_names(self):
        values = Table.names()
        self.assertEqual(values, 'test1, test2, test3')

    def test_results1(self):
        results = self.tab1.results()
        results.sort()
        self.assertEqual(results, ['four', 'one', 'three', 'two'])
Ejemplo n.º 2
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'])
Ejemplo n.º 3
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'])
Ejemplo n.º 4
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'])
Ejemplo n.º 5
0
 def test_createDict2(self):
    tab = Table("test1", {'roll': '1d4', '1-2':'two', '3-4': 'four'})
    res1 = Rpggen.finduse('test1')
    self.assertEqual(res1,'two')
    res2 = Rpggen.finduse('test1')
    self.assertEqual(res2,'two')
    values = tab.results()
    values.sort()
    self.assertEqual(values,['four','two'])
Ejemplo n.º 6
0
 def test_createList(self):
    tab = Table("test1", ['one','two','three','four'])
    res1 = Rpggen.finduse('test1')
    self.assertEqual(res1,'two')
    res2 = Rpggen.finduse('test1')
    self.assertEqual(res2,'two')
    values = tab.results()
    values.sort()
    self.assertEqual(values,['four','one','three','two'])      
Ejemplo n.º 7
0
# 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',
    '2-5': 'Human',
    '6': "Elf",
    '7': 'Dwarf',
    '8': 'Halfling'
})
print('Print the dice roll used in the second Race table: %s' % tab3.dice)
print('And print out all possible results from that table: %s' %
      tab3.results())

# Another way to create a table is by reading in an "lt" file.