71 lines
2.3 KiB
Python
71 lines
2.3 KiB
Python
|
import unittest
|
||
|
|
||
|
from oop import Tu
|
||
|
class TextProcessor(Tu):
|
||
|
def __init__(self):
|
||
|
super().__init__()
|
||
|
|
||
|
|
||
|
|
||
|
class TestQueryBridgeWords(unittest.TestCase):
|
||
|
def setUp(self):
|
||
|
# Initialize a graph for testing
|
||
|
self.graph = {
|
||
|
'a': {'b': 1, 'c': 2},
|
||
|
'b': {'c': 1, 'd': 2},
|
||
|
'c': {'d': 1},
|
||
|
'x': {},
|
||
|
'z': {}
|
||
|
}
|
||
|
self.processor = TextProcessor()
|
||
|
self.processor.generate_directed_dict(self.processor.read_text_file("1.txt"))
|
||
|
self.processor.generate_directed_graph()
|
||
|
|
||
|
def test_valid_bridge_words_exist(self):
|
||
|
# Valid equivalence class: bridge words exist
|
||
|
result = self.processor.queryBridgeWords('the', 'floor')
|
||
|
self.assertIn('forest', result)
|
||
|
|
||
|
def test_valid_bridge_words_not_exist(self):
|
||
|
# Valid equivalence class: no bridge words
|
||
|
result = self.processor.queryBridgeWords('on', 'the')
|
||
|
self.assertEqual(result, [])
|
||
|
|
||
|
def test_invalid_word1_not_in_graph(self):
|
||
|
# Invalid equivalence class: word1 not in graph
|
||
|
result = self.processor.queryBridgeWords('an', 'a')
|
||
|
self.assertEqual(result, [])
|
||
|
|
||
|
def test_invalid_word2_not_in_graph(self):
|
||
|
# Invalid equivalence class: word2 not in graph
|
||
|
result = self.processor.queryBridgeWords('a', 'an')
|
||
|
self.assertEqual(result, [])
|
||
|
|
||
|
def test_invalid_both_words_not_in_graph(self):
|
||
|
# Invalid equivalence class: both words not in graph
|
||
|
result = self.processor.queryBridgeWords('an', 'sought')
|
||
|
self.assertEqual(result, [])
|
||
|
|
||
|
def test_edge_case_min_word(self):
|
||
|
# Edge case: minimum word
|
||
|
result = self.processor.queryBridgeWords('a', 'b')
|
||
|
self.assertEqual(result, [])
|
||
|
|
||
|
def test_edge_case_max_word(self):
|
||
|
# Edge case: maximum word
|
||
|
result = self.processor.queryBridgeWords('x', 'z')
|
||
|
self.assertEqual(result, [])
|
||
|
|
||
|
def test_edge_case_no_bridge_words(self):
|
||
|
# Edge case: no bridge words
|
||
|
result = self.processor.queryBridgeWords('new', 'worlds')
|
||
|
self.assertEqual(result, [])
|
||
|
|
||
|
def test_edge_case_single_bridge_word(self):
|
||
|
# Edge case: single bridge word
|
||
|
result = self.processor.queryBridgeWords('the', 'floor')
|
||
|
self.assertIn('forest', result)
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
unittest.main()
|