|
| 1 | +require_relative '../test_helper' |
| 2 | + |
| 3 | +class SummaryTest < Minitest::Test |
| 4 | + def test_split_sentences_basic |
| 5 | + text = 'Hello world. This is a test. How are you?' |
| 6 | + sentences = text.split_sentences |
| 7 | + |
| 8 | + assert_equal 3, sentences.size |
| 9 | + assert_equal 'Hello world.', sentences[0] |
| 10 | + assert_equal 'This is a test.', sentences[1] |
| 11 | + assert_equal 'How are you?', sentences[2] |
| 12 | + end |
| 13 | + |
| 14 | + def test_split_sentences_with_abbreviations |
| 15 | + text = 'Dr. Smith went to the store. He bought milk.' |
| 16 | + sentences = text.split_sentences |
| 17 | + |
| 18 | + assert_equal 2, sentences.size |
| 19 | + assert_equal 'Dr. Smith went to the store.', sentences[0] |
| 20 | + assert_equal 'He bought milk.', sentences[1] |
| 21 | + end |
| 22 | + |
| 23 | + def test_split_sentences_with_mr_mrs |
| 24 | + text = 'Mr. Jones met Mrs. Smith. They talked.' |
| 25 | + sentences = text.split_sentences |
| 26 | + |
| 27 | + assert_equal 2, sentences.size |
| 28 | + assert_equal 'Mr. Jones met Mrs. Smith.', sentences[0] |
| 29 | + assert_equal 'They talked.', sentences[1] |
| 30 | + end |
| 31 | + |
| 32 | + def test_split_sentences_with_decimals |
| 33 | + text = 'The price is $3.50 per unit. That is expensive.' |
| 34 | + sentences = text.split_sentences |
| 35 | + |
| 36 | + assert_equal 2, sentences.size |
| 37 | + assert_equal 'The price is $3.50 per unit.', sentences[0] |
| 38 | + assert_equal 'That is expensive.', sentences[1] |
| 39 | + end |
| 40 | + |
| 41 | + def test_split_sentences_with_exclamation |
| 42 | + text = 'Hello! How are you? I am fine.' |
| 43 | + sentences = text.split_sentences |
| 44 | + |
| 45 | + assert_equal 3, sentences.size |
| 46 | + assert_equal 'Hello!', sentences[0] |
| 47 | + assert_equal 'How are you?', sentences[1] |
| 48 | + assert_equal 'I am fine.', sentences[2] |
| 49 | + end |
| 50 | + |
| 51 | + def test_split_sentences_with_inc_corp |
| 52 | + text = 'Apple Inc. makes phones. Microsoft Corp. makes software.' |
| 53 | + sentences = text.split_sentences |
| 54 | + |
| 55 | + assert_equal 2, sentences.size |
| 56 | + assert_equal 'Apple Inc. makes phones.', sentences[0] |
| 57 | + assert_equal 'Microsoft Corp. makes software.', sentences[1] |
| 58 | + end |
| 59 | + |
| 60 | + def test_split_sentences_with_etc |
| 61 | + text = 'We need apples, oranges, etc. for the party. Please bring them.' |
| 62 | + sentences = text.split_sentences |
| 63 | + |
| 64 | + assert_equal 2, sentences.size |
| 65 | + assert_includes sentences[0], 'etc.' |
| 66 | + end |
| 67 | + |
| 68 | + def test_split_paragraphs_double_newline |
| 69 | + text = "First paragraph.\n\nSecond paragraph." |
| 70 | + paragraphs = text.split_paragraphs |
| 71 | + |
| 72 | + assert_equal 2, paragraphs.size |
| 73 | + assert_equal 'First paragraph.', paragraphs[0] |
| 74 | + assert_equal 'Second paragraph.', paragraphs[1] |
| 75 | + end |
| 76 | + |
| 77 | + def test_split_paragraphs_windows_line_endings |
| 78 | + text = "First paragraph.\r\n\r\nSecond paragraph." |
| 79 | + paragraphs = text.split_paragraphs |
| 80 | + |
| 81 | + assert_equal 2, paragraphs.size |
| 82 | + assert_equal 'First paragraph.', paragraphs[0] |
| 83 | + assert_equal 'Second paragraph.', paragraphs[1] |
| 84 | + end |
| 85 | + |
| 86 | + def test_split_paragraphs_multiple_newlines |
| 87 | + text = "First paragraph.\n\n\n\nSecond paragraph." |
| 88 | + paragraphs = text.split_paragraphs |
| 89 | + |
| 90 | + assert_equal 2, paragraphs.size |
| 91 | + end |
| 92 | + |
| 93 | + def test_split_paragraphs_mixed_line_endings |
| 94 | + text = "First.\r\n\r\nSecond.\n\nThird." |
| 95 | + paragraphs = text.split_paragraphs |
| 96 | + |
| 97 | + assert_equal 3, paragraphs.size |
| 98 | + end |
| 99 | + |
| 100 | + def test_summary_returns_string |
| 101 | + text = 'This is sentence one. This is sentence two. This is sentence three.' |
| 102 | + result = text.summary(2) |
| 103 | + |
| 104 | + assert_instance_of String, result |
| 105 | + end |
| 106 | + |
| 107 | + def test_paragraph_summary_returns_string |
| 108 | + text = "First paragraph with content.\n\nSecond paragraph with more content." |
| 109 | + result = text.paragraph_summary(1) |
| 110 | + |
| 111 | + assert_instance_of String, result |
| 112 | + end |
| 113 | +end |
0 commit comments