import unittest

from double_hash import DoubleHash
from hashable_string import HashableString


class Test(unittest.TestCase):
    '''
    This PyUnit test tests the DoubleHash class.
    
    @author: oseppala, santtu
    
    '''


    def setUp(self):
        '''
        Sets up the initial state for all the test cases. Note the hash size -
        this is used in the test_insert-method.
        '''
        # Hash sizes smaller than 11 might not work correctly
        self.hash_to_test = DoubleHash(11)

    def test_next_prime(self):
        '''
        Tests whether the prime number generator implemented inside DoubleHash is
        working properly. The tests in Web-CAT might use bigger numbers still.
        '''
        self.assertEqual(41, self.hash_to_test.next_prime(19),
                "Next prime from 19 which is at least twice as big should be 41.")
        self.assertEqual(999959, self.hash_to_test.next_prime(499979), 
                     "Next prime from 499979 which is at least twice as big should be 999959.")

    def test_insert(self):
        '''
        A very simple test that peeks inside the class and checks that everything
        is working properly. 
        '''

        item1 = HashableString("Esimerkki_A", 16)

        self.hash_to_test.insert(item1)
        self.assertEqual(item1, self.hash_to_test.table[5], "Item went to wrong position")
        self.assertEqual(1, self.hash_to_test.item_count, 'item_count not updated')

# own tests here
        

if __name__ == "__main__":
    unittest.main()
    
