-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix[chat_bubble]: always place bubble at the end of the sentence (#38)
* fix[chat_bubble]: always place bubble at the end of the sentence * fix[chat_bubble]: remove extra print statements * fix[chat_bubble]: refactor code to optimum aglo for finding index * fix(chat_bubble): adding test cases for chat method * fix(chat_bubble): adding test cases for chat method * fix(chat_bubble): adding test cases for chat method
- Loading branch information
1 parent
44e1e1f
commit 00e255d
Showing
5 changed files
with
263 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import unittest | ||
|
||
from app.utils import find_following_sentence_ending | ||
|
||
|
||
class TestFindFollowingSentenceEnding(unittest.TestCase): | ||
def test_basic_case(self): | ||
sentence_endings = [10, 20, 30, 40] | ||
index = 15 | ||
expected = 20 # Closest ending greater than 15 is 20 | ||
self.assertEqual(find_following_sentence_ending(sentence_endings, index), expected) | ||
|
||
def test_no_greater_ending(self): | ||
sentence_endings = [10, 20, 30] | ||
index = 35 | ||
expected = 35 # No greater ending than 35, so it returns the index itself | ||
self.assertEqual(find_following_sentence_ending(sentence_endings, index), expected) | ||
|
||
def test_at_ending_boundary(self): | ||
sentence_endings = [10, 20, 30, 40] | ||
index = 30 | ||
expected = 40 # The next greater ending after 30 is 40 | ||
self.assertEqual(find_following_sentence_ending(sentence_endings, index), expected) | ||
|
||
def test_first_sentence(self): | ||
sentence_endings = [10, 20, 30, 40] | ||
index = 5 | ||
expected = 10 # The closest ending greater than 5 is 10 | ||
self.assertEqual(find_following_sentence_ending(sentence_endings, index), expected) | ||
|
||
def test_empty_sentence_endings(self): | ||
sentence_endings = [] | ||
index = 5 | ||
expected = 5 # No sentence endings, so return the index itself | ||
self.assertEqual(find_following_sentence_ending(sentence_endings, index), expected) | ||
|
||
def test_same_index_as_last_ending(self): | ||
sentence_endings = [10, 20, 30] | ||
index = 30 | ||
expected = 30 # At the last sentence ending, return the index itself | ||
self.assertEqual(find_following_sentence_ending(sentence_endings, index), expected) | ||
|
||
# Run the tests | ||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import unittest | ||
|
||
from app.utils import find_sentence_endings | ||
|
||
|
||
class TestFindSentenceEndings(unittest.TestCase): | ||
def test_basic_sentences(self): | ||
text = "This is a sentence. This is another one!" | ||
expected = [20, 40, len(text)] # Sentence endings at ".", "!", and the last index | ||
self.assertEqual(find_sentence_endings(text), expected) | ||
|
||
def test_text_without_punctuation(self): | ||
text = "This is a sentence without punctuation" | ||
expected = [len(text)] # Only the last index is expected | ||
self.assertEqual(find_sentence_endings(text), expected) | ||
|
||
def test_multiple_punctuation(self): | ||
text = "Is this working? Yes! It seems so." | ||
expected = [17, 22, 34, len(text)] # Endings after "?", "!", ".", and the last index | ||
self.assertEqual(find_sentence_endings(text), expected) | ||
|
||
def test_trailing_whitespace(self): | ||
text = "Trailing whitespace should be ignored. " | ||
expected = [39, len(text)] # End at the period and the final index | ||
self.assertEqual(find_sentence_endings(text), expected) | ||
|
||
def test_punctuation_in_middle_of_text(self): | ||
text = "Sentence. Followed by an abbreviation e.g. and another sentence." | ||
expected = [10, 43, 64, len(text)] # Endings after ".", abbreviation ".", and sentence "." | ||
self.assertEqual(find_sentence_endings(text), expected) | ||
|
||
def test_empty_string(self): | ||
text = "" | ||
expected = [0] # Empty string should only have the 0th index as an "ending" | ||
self.assertEqual(find_sentence_endings(text), expected) | ||
|
||
# Run the tests | ||
if __name__ == "__main__": | ||
unittest.main() |