mtg/test.py

47 lines
2 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 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')))
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()