test heihe shaominmax
This commit is contained in:
parent
6c411c416b
commit
a0ef3f0818
6
oop.py
6
oop.py
|
@ -161,7 +161,11 @@ class Tu:
|
|||
word1 = self.input_check(word1)
|
||||
word2 = self.input_check(word2)
|
||||
bridge_words = self.find_bridge_words(word1, word2)
|
||||
self.print_bridge_words(bridge_words, word1, word2)
|
||||
if bridge_words:
|
||||
self.print_bridge_words(bridge_words, word1, word2)
|
||||
return bridge_words
|
||||
else:
|
||||
return bridge_words
|
||||
|
||||
def insert_bridge_words(self, text):
|
||||
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
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()
|
Loading…
Reference in New Issue