import unittest
import sys
import os

sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from hash_table import HashTable


class TestHashTable(unittest.TestCase):
    def setUp(self):
        self.ht = HashTable(10)
    
    def test_insert_and_search(self):
        self.ht.insert("Alice", "123")
        self.ht.insert("Bob", "234")
        
        self.assertEqual(self.ht.search("Alice"), "123")
        self.assertEqual(self.ht.search("Bob"), "234")
    
    def test_update(self):
        self.ht.insert("Alice", "123")
        self.ht.insert("Alice", "456")
        
        self.assertEqual(self.ht.search("Alice"), "456")
    
    def test_delete(self):
        self.ht.insert("Alice", "123")
        self.assertTrue(self.ht.delete("Alice"))
        self.assertIsNone(self.ht.search("Alice"))
    
    def test_size(self):
        self.assertEqual(self.ht.get_size(), 0)
        self.ht.insert("Alice", "123")
        self.assertEqual(self.ht.get_size(), 1)
    
    def test_resize(self):
        for i in range(20):
            self.ht.insert(f"User_{i}", "123")
        
        self.assertGreater(self.ht.capacity, 10)
        self.assertEqual(self.ht.get_size(), 20)


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