31 lines
1.4 KiB
Python
31 lines
1.4 KiB
Python
|
import unittest
|
||
|
from mtg import *
|
||
|
|
||
|
class TestManaMath(unittest.TestCase):
|
||
|
def test_add_mana(self):
|
||
|
self.assertEquals('RR', str(Mana('r') + Mana('r')))
|
||
|
def test_subtract_mana(self):
|
||
|
self.assertEquals('R', str(Mana('rr') - Mana('r')))
|
||
|
def test_subtract_mana_insufficient(self):
|
||
|
self.assertRaises(Exception, lambda: Mana('r') - Mana('rr'))
|
||
|
self.assertRaises(Exception, lambda: Mana('r') - Mana('g'))
|
||
|
|
||
|
class TestManaCostMath(unittest.TestCase):
|
||
|
def test_add_manacost(self):
|
||
|
self.assertEquals('3R', str(ManaCost('2R') + ManaCost('1')))
|
||
|
def test_subtract_manacost(self):
|
||
|
self.assertEquals('1G', str(ManaCost('4GR') - ManaCost('3R')))
|
||
|
def test_subtract_manacost_from_mana(self):
|
||
|
result = Mana('UUBWWR') - ManaCost('1RW')
|
||
|
# Can't check the exact string, since there's no way of knowing which
|
||
|
# colors will be used for the additional mana requirement
|
||
|
self.assertEquals(3, result.converted())
|
||
|
self.assertEquals(0, result.mana['R'])
|
||
|
self.assertEquals(1, result.mana['W'])
|
||
|
def test_subtract_manacost_from_mana_insufficient_addtl(self):
|
||
|
self.assertRaises(Exception, lambda: Mana('RRW'), ManaCost('3R'))
|
||
|
def test_subtract_manacost_from_mana_insufficient_color(self):
|
||
|
self.assertRaises(Exception, lambda: Mana('RRW'), ManaCost('2U'))
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
unittest.main()
|