예제 #1
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)
예제 #2
0
    def test_make_dict_mean_and_stddev_rounding(self):
        table = DetailedDiceTable.new().add_die(WeightedDie({1: 1, 2: 2}))
        answer = make_dict(table)
        self.assertEqual(table.calc.mean(), 1.6666666666666667)
        self.assertEqual(answer['mean'], 1.667)

        self.assertEqual(table.calc.stddev(3), 0.471)
        self.assertEqual(answer['stddev'], 0.471)
예제 #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_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)
예제 #5
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)