def coinage(self, tab: dict, elecplat: str) -> 'Money': '''Return a random Money object based to tab probabilities. tab has to be as following: {coin_type: (prob_coin, dice_string, multiplier), ...} coin_type: copper, silver, gold, electrum, platinum prob_coin: probability (0-100) that coin type is present in the hoard dice_string: string to build the dice to random create multiplier: the number to multiply the result of dice_string elecplat: 'electrum' or 'platinum'. Whatever else to choose randomly >>> m = Mint() >>> g = m.coinage({'copper': (100, '1d10', 1000), 'silver': (100, '1d6', 1000), 'gold': (25, '1d6', 100), 'electrum': (25, '1d4', 10), 'platinum': (25, '1d4', 10)}, elecplat='platinum') >>> type(g) <class 'items.treasure.Money'> ''' m = {} for c in DD_CURRENCIES: if self.throw() < tab[c][0]: # if 1d100 < prob_coin m[c] = self.throw_this(tab[c][1]) * tab[c][2] else: m[c] = 0 if elecplat == 'electrum': m['platinum'] = 0 elif elecplat == 'platinum': m['electrum'] = 0 else: if self.throw_this('1d2') == 1: m['platinum'] = 0 else: m['electrum'] = 0 return Money(m)
def setUp(self): self.m1 = Money() # empty constructor self.m2 = Money(WALLET1) # complete dict self.m3 = Money({'gold': 28}) # partial dict self.m4 = Money(TUPLE_COINS) # tuple self.m5 = Money(LIST_COINS) # list self.m6 = Money(**WALLET2)# complete kwargs self.m7 = Money(copper=50, gold=8) # partial kwargs
def setUp(self): self.m1 = Money() # empty constructor self.m2 = Money(WALLET1) # complete dict self.m3 = Money({'gold': 28}) # partial dict self.m4 = Money(TUPLE_COINS) # tuple self.m5 = Money(LIST_COINS) # list self.m6 = Money(**WALLET2) # complete kwargs self.m7 = Money(copper=50, gold=8) # partial kwargs
class TestMoney(unittest.TestCase): def setUp(self): self.m1 = Money() # empty constructor self.m2 = Money(WALLET1) # complete dict self.m3 = Money({'gold': 28}) # partial dict self.m4 = Money(TUPLE_COINS) # tuple self.m5 = Money(LIST_COINS) # list self.m6 = Money(**WALLET2) # complete kwargs self.m7 = Money(copper=50, gold=8) # partial kwargs def test_coins(self): for c in DD_CURRENCIES: self.assertEqual(self.m1.coins(c), 0) for c in self.m2.coins().keys(): self.assertEqual(self.m2.coins(c), WALLET1[c]) self.assertEqual(self.m3.coins('copper'), 0) self.assertEqual(self.m3.coins('silver'), 0) self.assertEqual(self.m3.coins('electrum'), 0) self.assertEqual(self.m3.coins('gold'), 28) self.assertEqual(self.m3.coins('platinum'), 0) for c, v in zip(DD_CURRENCIES, TUPLE_COINS): self.assertEqual(self.m4.coins(c), v) for c, v in zip(DD_CURRENCIES, LIST_COINS): self.assertEqual(self.m5.coins(c), v) for c, v in WALLET2.items(): self.assertEqual(self.m6.coins(c), v) self.assertEqual(self.m7.coins('copper'), 50) self.assertEqual(self.m7.coins('silver'), 0) self.assertEqual(self.m7.coins('electrum'), 0) self.assertEqual(self.m7.coins('gold'), 8) self.assertEqual(self.m7.coins('platinum'), 0) def test_value(self): self.assertEqual(self.m1.value, 0.0) self.assertEqual(self.m2.value, WALLET1_VALUE) self.assertEqual(self.m3.value, 28.0) def test_weight(self): self.assertEqual(self.m1.weight, 0.0) self.assertEqual(self.m3.weight, 28 * COIN_WEIGHT) self.assertEqual(self.m5.weight, sum(LIST_COINS) * COIN_WEIGHT)
class TestMoney(unittest.TestCase): def setUp(self): self.m1 = Money() # empty constructor self.m2 = Money(WALLET1) # complete dict self.m3 = Money({'gold': 28}) # partial dict self.m4 = Money(TUPLE_COINS) # tuple self.m5 = Money(LIST_COINS) # list self.m6 = Money(**WALLET2)# complete kwargs self.m7 = Money(copper=50, gold=8) # partial kwargs def test_coins(self): for c in DD_CURRENCIES: self.assertEqual(self.m1.coins(c), 0) for c in self.m2.coins().keys(): self.assertEqual(self.m2.coins(c), WALLET1[c]) self.assertEqual(self.m3.coins('copper'), 0) self.assertEqual(self.m3.coins('silver'), 0) self.assertEqual(self.m3.coins('electrum'), 0) self.assertEqual(self.m3.coins('gold'), 28) self.assertEqual(self.m3.coins('platinum'), 0) for c, v in zip(DD_CURRENCIES, TUPLE_COINS): self.assertEqual(self.m4.coins(c), v) for c, v in zip(DD_CURRENCIES, LIST_COINS): self.assertEqual(self.m5.coins(c), v) for c, v in WALLET2.items(): self.assertEqual(self.m6.coins(c), v) self.assertEqual(self.m7.coins('copper'), 50) self.assertEqual(self.m7.coins('silver'), 0) self.assertEqual(self.m7.coins('electrum'), 0) self.assertEqual(self.m7.coins('gold'), 8) self.assertEqual(self.m7.coins('platinum'), 0) def test_value(self): self.assertEqual(self.m1.value, 0.0) self.assertEqual(self.m2.value, WALLET1_VALUE) self.assertEqual(self.m3.value, 28.0) def test_weight(self): self.assertEqual(self.m1.weight, 0.0) self.assertEqual(self.m3.weight, 28 * COIN_WEIGHT) self.assertEqual(self.m5.weight, sum(LIST_COINS) * COIN_WEIGHT)