Пример #1
0
    def test_request_dice_table_construction_all_dice(self):
        all_dice = [
            Die(die_size=2),
            ModDie(2, modifier=-1),
            WeightedDie(dictionary_input={
                3: 4,
                5: 6,
                7: 8,
                9: 0
            }),
            ModWeightedDie({
                1: 2,
                3: 4
            }, 0),
            StrongDie(input_die=Die(2), multiplier=2),
            Exploding(Die(2), explosions=1),
            ExplodingOn(Die(3), explodes_on=(1, 2)),
            Modifier(modifier=-100),
            BestOfDicePool(Die(2), 2, 1),
            WorstOfDicePool(Die(2), 2, 1),
            UpperMidOfDicePool(Die(2), 2, 1),
            LowerMidOfDicePool(Die(2), 2, 1)
        ]

        for die in all_dice:
            self.handler.request_dice_table_construction(
                '2 * {!r}'.format(die))
            self.assertEqual(self.handler.get_table(),
                             DiceTable.new().add_die(die, 2))
Пример #2
0
    def test_make_dict_simple_table(self):
        answer = make_dict(DiceTable.new().add_die(Die(4)))
        expected = {
            'name':
            '<DiceTable containing [1D4]>',
            'diceStr':
            'Die(4): 1',
            'data': {
                'x': (1, 2, 3, 4),
                'y': (25.0, 25.0, 25.0, 25.0)
            },
            'tableString':
            '1: 1\n2: 1\n3: 1\n4: 1\n',
            'forSciNum': [{
                'roll': 1,
                'mantissa': '1.00000',
                'exponent': '0'
            }, {
                'roll': 2,
                'mantissa': '1.00000',
                'exponent': '0'
            }, {
                'roll': 3,
                'mantissa': '1.00000',
                'exponent': '0'
            }, {
                'roll': 4,
                'mantissa': '1.00000',
                'exponent': '0'
            }],
            'range': (1, 4),
            'mean':
            2.5,
            'stddev':
            1.118,
            'roller': {
                'height':
                "4",
                'aliases': [{
                    'primary': "4",
                    'alternate': "4",
                    'primaryHeight': "4"
                }, {
                    'primary': "3",
                    'alternate': "3",
                    'primaryHeight': "4"
                }, {
                    'primary': "2",
                    'alternate': "2",
                    'primaryHeight': "4"
                }, {
                    'primary': "1",
                    'alternate': "1",
                    'primaryHeight': "4"
                }]
            }
        }

        self.assertEqual(answer, expected)
Пример #3
0
    def test_make_dict_large_number_table(self):
        table = DiceTable({1: 1, 2: 9**351}, DiceRecord.new())
        answer = make_dict(table)
        expected = {
            'data': {
                'x': (1, 2),
                'y': (0.0, 100.0)
            },
            'forSciNum': [{
                'roll': 1,
                'mantissa': '1.00000',
                'exponent': '0'
            }, {
                'roll': 2,
                'mantissa': '8.69202',
                'exponent': '334'
            }],
            'mean':
            2.0,
            'range': (1, 2),
            'name':
            '<DiceTable containing []>',
            'diceStr':
            '',
            'stddev':
            0.0,
            'tableString':
            '1: 1\n2: 8.692e+334\n',
            'roller': {
                'height':
                ('8692021926532582239431197828370635593634075173099158789854434049807997760319275071636088'
                 '5895145922991572345585185250800940116508114750525076655926616148114182143549026229853337'
                 '9940869208919850517403157109776051593152797345404989883632793071982398710942373198113120'
                 '40403122389178667907944352945294284623021821750094845717881664249886010'
                 ),
                'aliases': [{
                    'primary': "1",
                    "alternate": "2",
                    "primaryHeight": "2"
                }, {
                    "primary":
                    "2",
                    "alternate":
                    "2",
                    "primaryHeight":
                    ("8692021926532582239431197828370635593634075173099158789854434049807997760319"
                     "2750716360885895145922991572345585185250800940116508114750525076655926616148"
                     "1141821435490262298533379940869208919850517403157109776051593152797345404989"
                     "8836327930719823987109423731981131204040312238917866790794435294529428462302"
                     "1821750094845717881664249886010")
                }]
            }
        }

        self.assertEqual(answer, expected)
Пример #4
0
    def test_request_dice_table_construction_with_all_allowed_delimiters(self):
        allowed = "!\"#$%&'*+./;<>?@\\^`|~\t\n\r"

        for index, num_delimiter in enumerate(allowed):
            pairs_delimiter = allowed[index - 1]
            request_str = f'2{num_delimiter}Die(2){pairs_delimiter}Die(3)'
            expected = DiceTable.new().add_die(Die(2), 2).add_die(Die(3))

            self.handler.request_dice_table_construction(
                request_str,
                num_delimiter=num_delimiter,
                pairs_delimiter=pairs_delimiter)
            self.assertEqual(self.handler.get_table(), expected)
Пример #5
0
 def test_make_dict_can_handle_gaps(self):
     table = DiceTable.new().add_die(WeightedDie({1: 1, 3: 1}))
     answer = make_dict(table)
     expected = {
         'name':
         '<DiceTable containing [1D3  W:2]>',
         'diceStr':
         'WeightedDie({1: 1, 2: 0, 3: 1}): 1',
         'data': {
             'x': (1, 2, 3),
             'y': (50.0, 0.0, 50.0)
         },
         'tableString':
         '1: 1\n2: 0\n3: 1\n',
         'forSciNum': [{
             'roll': 1,
             'mantissa': '1.00000',
             'exponent': '0'
         }, {
             'roll': 2,
             'mantissa': '0',
             'exponent': '0'
         }, {
             'roll': 3,
             'mantissa': '1.00000',
             'exponent': '0'
         }],
         'range': (1, 3),
         'mean':
         2,
         'stddev':
         1.0,
         'roller': {
             'height':
             "2",
             'aliases': [{
                 'primary': "3",
                 'alternate': "3",
                 'primaryHeight': "2"
             }, {
                 'primary': "1",
                 'alternate': "1",
                 'primaryHeight': "2"
             }]
         }
     }
     self.assertEqual(answer, expected)
Пример #6
0
def make_dict(dice_table: DiceTable):
    calc = EventsCalculations(dice_table)
    out = dict()
    out['diceStr'] = '\n'.join([
        '{!r}: {}'.format(die, number)
        for die, number in dice_table.get_list()
    ])
    out['name'] = repr(dice_table)

    x_axis, y_axis = calc.percentage_axes()
    out['data'] = {'x': x_axis, 'y': y_axis}
    out['tableString'] = calc.full_table_string()

    lines = calc.full_table_string(6, -1).split('\n')
    for_scinum = [_get_json(el) for el in lines if el]

    out['forSciNum'] = for_scinum

    out['range'] = calc.info.events_range()
    out['mean'] = round(calc.mean(), 3)
    out['stddev'] = calc.stddev(3)

    out['roller'] = _get_roller_data(dice_table)
    return out
Пример #7
0
 def _make_table(self, record: DiceRecord):
     table = DiceTable.new()
     for die, num in record.get_dict().items():
         table = table.add_die(die, num)
     self._table = table
Пример #8
0
 def test_request_dice_table_construction_leading_and_trailing_whitespace(
         self):
     self.handler.request_dice_table_construction(
         '   2  *  Die( 5 )   &   1  *  Die( 4 )   ')
     self.assertEqual(self.handler.get_table(),
                      DiceTable.new().add_die(Die(5), 2).add_die(Die(4)))
Пример #9
0
 def test_request_dice_table_multiple_dice_with_number(self):
     self.handler.request_dice_table_construction('2*Die(3) & 2*Die(2)')
     self.assertEqual(self.handler.get_table(),
                      DiceTable.new().add_die(Die(2), 2).add_die(Die(3), 2))
Пример #10
0
 def test_request_dice_table_single_die_no_number(self):
     self.handler.request_dice_table_construction('Die(3)')
     self.assertEqual(self.handler.get_table(),
                      DiceTable.new().add_die(Die(3), 1))
Пример #11
0
 def test_request_dice_table_construction_mixed_case(self):
     request = 'dIe(DiE_sIzE=3)'
     self.handler.request_dice_table_construction(request)
     self.assertEqual(self.handler.get_table(),
                      DiceTable.new().add_die(Die(3)))
Пример #12
0
 def test_request_dice_table_only_whitespace(self):
     self.handler.request_dice_table_construction('   ')
     self.assertEqual(self.handler.get_table(), DiceTable.new())
Пример #13
0
 def test_request_dice_table_empty_string(self):
     self.handler.request_dice_table_construction('')
     self.assertEqual(self.handler.get_table(), DiceTable.new())
Пример #14
0
 def test_get_table(self):
     self.assertEqual(self.handler.get_table(), DiceTable.new())
     expected = DiceTable.new().add_die(Die(6), 2)
     self.handler.request_dice_table_construction('2*Die(6)')
     self.assertEqual(self.handler.get_table(), expected)
Пример #15
0
    def test_make_dict_complex_table(self):
        table = DiceTable.new().add_die(WeightedDie({
            1: 1,
            2: 99
        }), 3).add_die(Die(3), 4)
        answer = make_dict(table)
        expected = {
            'name':
            '<DiceTable containing [3D2  W:100, 4D3]>',
            'diceStr':
            'WeightedDie({1: 1, 2: 99}): 3\nDie(3): 4',
            'data': {
                'x': (7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18),
                'y': (1.234567901234568e-06, 0.0003716049382716049,
                      0.03777901234567901, 1.3467864197530863,
                      5.16049012345679, 12.566786419753084, 19.861979012345678,
                      23.34457160493827, 19.53086790123457, 12.124566666666665,
                      4.8279, 1.1978999999999997)
            },
            'tableString':
            (' 7: 1\n' + ' 8: 301\n' + ' 9: 30,601\n' + '10: 1,090,897\n' +
             '11: 4,179,997\n' + '12: 1.018e+7\n' + '13: 1.609e+7\n' +
             '14: 1.891e+7\n' + '15: 1.582e+7\n' + '16: 9,820,899\n' +
             '17: 3,910,599\n' + '18: 970,299\n'),
            'forSciNum': [{
                'roll': 7,
                'mantissa': '1.00000',
                'exponent': '0'
            }, {
                'roll': 8,
                'mantissa': '3.01000',
                'exponent': '2'
            }, {
                'roll': 9,
                'mantissa': '3.06010',
                'exponent': '4'
            }, {
                'roll': 10,
                'mantissa': '1.09090',
                'exponent': '6'
            }, {
                'roll': 11,
                'mantissa': '4.18000',
                'exponent': '6'
            }, {
                'roll': 12,
                'mantissa': '1.01791',
                'exponent': '7'
            }, {
                'roll': 13,
                'mantissa': '1.60882',
                'exponent': '7'
            }, {
                'roll': 14,
                'mantissa': '1.89091',
                'exponent': '7'
            }, {
                'roll': 15,
                'mantissa': '1.58200',
                'exponent': '7'
            }, {
                'roll': 16,
                'mantissa': '9.82090',
                'exponent': '6'
            }, {
                'roll': 17,
                'mantissa': '3.91060',
                'exponent': '6'
            }, {
                'roll': 18,
                'mantissa': '9.70299',
                'exponent': '5'
            }],
            'range': (7, 18),
            'mean':
            13.97,
            'stddev':
            1.642,
            'roller': {
                'aliases': [{
                    'alternate': '16',
                    'primary': '18',
                    'primaryHeight': '11643588'
                }, {
                    'alternate': '15',
                    'primary': '16',
                    'primaryHeight': '48494376'
                }, {
                    'alternate': '15',
                    'primary': '17',
                    'primaryHeight': '46927188'
                }, {
                    'alternate': '15',
                    'primary': '11',
                    'primaryHeight': '50159964'
                }, {
                    'alternate': '15',
                    'primary': '10',
                    'primaryHeight': '13090764'
                }, {
                    'alternate': '14',
                    'primary': '15',
                    'primaryHeight': '24512328'
                }, {
                    'alternate': '14',
                    'primary': '9',
                    'primaryHeight': '367212'
                }, {
                    'alternate': '14',
                    'primary': '8',
                    'primaryHeight': '3612'
                }, {
                    'alternate': '13',
                    'primary': '14',
                    'primaryHeight': '8792388'
                }, {
                    'alternate': '13',
                    'primary': '7',
                    'primaryHeight': '12'
                }, {
                    'alternate': '12',
                    'primary': '13',
                    'primaryHeight': '39850836'
                }, {
                    'alternate': '12',
                    'primary': '12',
                    'primaryHeight': '81000000'
                }],
                'height':
                '81000000',
            },
        }

        self.assertEqual(answer, expected)
Пример #16
0
 def __init__(self, max_dice_value=12000) -> None:
     self._table = DiceTable.new()
     self._parser = Parser(ignore_case=True)
     self._max_dice_value = max_dice_value
Пример #17
0
 def test_request_dice_table_construction_with_kwargs(self):
     self.handler.request_dice_table_construction(
         'ModDie(die_size=2, modifier=3)')
     self.assertEqual(self.handler.get_table(),
                      DiceTable.new().add_die(ModDie(2, 3)))