class TrivialInsertBeachLineTestCase(unittest.TestCase):
    def setUp(self):
        self.b = BeachLine(arc=False)
        self.testvalue = 5
        self.b.insert(self.testvalue)

    def tearDown(self):
        del self.b

    def test_insert_singular(self):
        """ Test insertion works on a trivial case """
        self.assertFalse(self.b.isEmpty())
        self.assertIsInstance(self.b.root, Node)
        self.assertEqual(self.b.root.value, self.testvalue)
        self.assertEqual(len(self.b.nodes), 1)
        self.assertEqual(len(self.b.arcs_added), 1)

    def test_trivial_search(self):
        """ Check trivial root only search works """
        node, side = self.b.search(self.testvalue)
        self.assertIsInstance(node, Node)
        self.assertIsInstance(side, Centre)
        self.assertEqual(self.b.root, node)
        self.assertEqual(self.b.root, self.b.nodes[0])

    def test_root_is_black(self):
        """ Assert that the root is changed from red to black correctly """
        self.assertFalse(self.b.root.red)

    def test_empty_successor_and_predecessor(self):
        """ Check the successor/predecessor are empty in the trivial case """
        node, side = self.b.search(self.testvalue)
        self.assertEqual(node.get_predecessor(), NilNode)
        self.assertEqual(node.get_successor(), NilNode)
class BeachLineTests(unittest.TestCase):
    """ Tests for Simple Valued Beachlines (not arc-based) """
    def setUp(self):
        self.b = BeachLine(arc=False)

    def tearDown(self):
        del self.b

    def test_init(self):
        """ Check initial creation """
        self.assertIsInstance(self.b, BeachLine)
        self.assertFalse(self.b.arc)
        self.assertEqual(self.b.root, NilNode)
        self.assertEqual(len(self.b.nodes), 0)
        self.assertEqual(len(self.b.arcs_added), 0)

    def test_isEmptyOnInit(self):
        """ Check the beachline is empty on initial creation """
        self.assertTrue(self.b.isEmpty())
        self.assertEqual(len(self.b.get_chain()), 0)

    def test_minmax_on_empty_beachline(self):
        """ Check that min and max respond appropriately on an empty beachline """
        #todo: make these raise exceptions
        self.assertEqual(self.b.min(), None)
        self.assertEqual(self.b.max(), None)