From a0ef3f08180d3dcbaf3846265c32cfc7cb1789c5 Mon Sep 17 00:00:00 2001 From: qasw-987 <143506929+qasw-987@users.noreply.github.com> Date: Mon, 3 Jun 2024 17:38:15 +0800 Subject: [PATCH] test heihe shaominmax --- oop.py | 6 ++++- test.py | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 test.py diff --git a/oop.py b/oop.py index 7d1c754..711d94e 100644 --- a/oop.py +++ b/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): diff --git a/test.py b/test.py new file mode 100644 index 0000000..5cc9070 --- /dev/null +++ b/test.py @@ -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()