72 lines
2.8 KiB
Python
72 lines
2.8 KiB
Python
import unittest
|
|
import sys
|
|
import os.path
|
|
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
|
|
|
|
if sys.version_info[0] < 3:
|
|
raise "Must be using Python 3"
|
|
|
|
from lib.causal import Causal
|
|
|
|
# The main methods that we make use of in unit testing for Python are:
|
|
#
|
|
# assert: base assert allowing you to write your own assertions
|
|
# assertEqual(a, b): check a and b are equal
|
|
# assertNotEqual(a, b): check a and b are not equal
|
|
# assertIn(a, b): check that a is in the item b
|
|
# assertNotIn(a, b): check that a is not in the item b
|
|
# assertFalse(a): check that the value of a is False
|
|
# assertTrue(a): check the value of a is True
|
|
# assertIsInstance(a, TYPE): check that a is of type "TYPE"
|
|
# assertRaises(ERROR, a, args): check that when a is called with args that it raises ERROR
|
|
#
|
|
# There are more methods available to us, which you can view - see
|
|
# https://docs.python.org/2/library/unittest.html
|
|
|
|
|
|
class TestCausal(unittest.TestCase):
|
|
def setUp(self):
|
|
self.causal = Causal()
|
|
|
|
def test_init(self):
|
|
causal = Causal()
|
|
self.assertIsInstance(causal, Causal)
|
|
|
|
def test_description_properties(self):
|
|
self.causal.description = "blaat"
|
|
self.assertEqual(self.causal.description, "blaat")
|
|
|
|
def test_title_properties(self):
|
|
self.causal.title = "blaat"
|
|
self.assertEqual(self.causal.title, "blaat")
|
|
|
|
def test_prechac_properties(self):
|
|
self.causal.prechac = "blaat"
|
|
self.assertEqual(self.causal.prechac, "blaat")
|
|
|
|
def test_sequence_properties(self):
|
|
self.causal.sequence = "blaat"
|
|
self.assertEqual(self.causal.sequence, "blaat")
|
|
|
|
def test_fourhanded_properties(self):
|
|
self.causal.fourhanded = "7746666"
|
|
self.assertEqual(self.causal.fourhanded, "7746666")
|
|
self.assertRaises(Exception, self.causal.fourhanded, "blaat")
|
|
self.assertRaises(Exception, self.causal.fourhanded, 8.5)
|
|
self.assertRaises(Exception, self.causal.fourhanded, "7746666")
|
|
|
|
def test_isvalid_fourhanded(self):
|
|
self.assertEqual(self.causal.isvalid_fourhanded(7746666), True) # Jim's three count
|
|
self.assertEqual(self.causal.isvalid_fourhanded("7746666"), True) # Jim's three count
|
|
self.assertEqual(self.causal.isvalid_fourhanded("8746666"), False)
|
|
self.assertEqual(self.causal.isvalid_fourhanded("blaat"), False)
|
|
self.assertEqual(self.causal.isvalid_fourhanded(8.5), False)
|
|
|
|
def test_fourhanded_to_local(self):
|
|
self.assertRaises(Exception, self.causal.fourhanded_to_local, "blaat")
|
|
self.assertEqual(self.causal.fourhanded_to_local(7746666), "[A]7466[B]766") # Jim's three count
|
|
self.assertEqual(self.causal.fourhanded_to_local(772626), "[A]722/[B]766") # "Skip" 5c pzz/pss
|
|
self.assertEqual(self.causal.fourhanded_to_local(777726), "[A]772/[B]776") # "Jonix" 6c ppz/pps
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|