2010-06-16 18:42:22 +00:00
|
|
|
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'))
|
|
|
|
|
2010-09-02 13:47:09 +00:00
|
|
|
class TestManaCost(unittest.TestCase):
|
|
|
|
def test_uncolored(self):
|
|
|
|
self.assertEquals('3', str(ManaCost('3')))
|
|
|
|
def test_colored(self):
|
|
|
|
self.assertEquals('RU', str(ManaCost('RU')))
|
|
|
|
def test_combined(self):
|
|
|
|
self.assertEquals('3RR', str(ManaCost('3RR')))
|
|
|
|
def test_mana(self):
|
|
|
|
self.assertEquals('BBW', str(ManaCost(Mana('BBW'))))
|
|
|
|
def test_hybrid_monocolor(self):
|
|
|
|
self.assertEquals('(1/U)', str(ManaCost('(1/U)')))
|
|
|
|
def test_hybrid_multicolor(self):
|
|
|
|
self.assertEquals('(W/R)', str(ManaCost('(W/R)')))
|
|
|
|
def test_snow(self):
|
|
|
|
self.assertEquals('S', str(ManaCost('S')))
|
|
|
|
|
2010-06-16 18:42:22 +00:00
|
|
|
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):
|
2010-08-31 14:28:50 +00:00
|
|
|
self.assertRaises(Exception, lambda: Mana('RRW') - ManaCost('3R'))
|
2010-06-16 18:42:22 +00:00
|
|
|
def test_subtract_manacost_from_mana_insufficient_color(self):
|
2010-08-31 14:28:50 +00:00
|
|
|
self.assertRaises(Exception, lambda: Mana('RRW') - ManaCost('2U'))
|
2010-06-16 18:42:22 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2010-08-31 14:28:50 +00:00
|
|
|
unittest.main()
|