import unittest
import math
import cat
from august8 import *
import bottle
import drunk

class TestAugust8(unittest.TestCase):
    def test_talk(self):
        cat1 = cat.create('Cat', 4)
        cat2 = cat.create('Kitteh', 3)

        self.assertEqual(cat.talk(cat1), 'Cat the 4 legged cat says meow!')
        self.assertEqual(cat.talk(cat2), 'Kitteh the 3 legged cat says meow!')

    def test_sum_lists(self):
        self.assertEqual(sum_lists([1, 2, 3], [4, 5, 6]), [5, 7, 9])
        self.assertEqual(
            sum_lists([10, 20, 30, 40], [1, 2, 3, 4]),
            [11, 22, 33, 44])

    def test_sum_of_list(self):
        self.assertEqual(sum_of_list([1, 2, 3, 4]), 10)

    def test_selection_sort(self):
        self.assertEqual(
            selection_sort([87, 37, 59, 68, 44, 25]),
            [25, 37, 44, 59, 68, 87])

    def test_bottle(self):
        b1 = bottle.create()
        self.assertFalse(bottle.is_open(b1))
        self.assertEqual(bottle.fill_level(b1), 100)

        bottle.open(b1)
        self.assertTrue(bottle.is_open(b1))
        bottle.close(b1)
        self.assertFalse(bottle.is_open(b1))

        self.assertEqual(bottle.remove_liquid(b1, 5),0)
        self.assertEqual(bottle.fill_level(b1), 100)

        bottle.open(b1)
        self.assertEqual(bottle.remove_liquid(b1, 5), 5)
        self.assertEqual(bottle.fill_level(b1), 95)
        self.assertFalse(bottle.is_empty(b1))

    def test_drunk(self):
        drunk_guy = drunk.create()
        self.assertEqual(drunk_guy, {'bac' : 0.0})

        b1 = bottle.create()

        """
        If the drunk's BAC is at or above 0.25, then he's too drunk to realize
        when he's trying to drink from a closed bottle.  Otherwise he'll open
        the bottle and drink 5 units from it.  Every 5 units drank increases his
        BAC by 0.01
        """
        drunk.swig(drunk_guy, b1)
        self.assertTrue(bottle.is_open(b1))
        self.assertEqual(bottle.fill_level(b1), 95)
        self.assertEqual(drunk_guy['bac'], 0.01)
        
if __name__ == '__main__':
    try:
        unittest.main()
    except SystemExit:
        pass
