|
| 1 | +CLASS ltcl_word_count DEFINITION FOR TESTING RISK LEVEL HARMLESS DURATION SHORT FINAL. |
| 2 | + |
| 3 | + PRIVATE SECTION. |
| 4 | + |
| 5 | + DATA cut TYPE REF TO zcl_word_count. |
| 6 | + METHODS setup. |
| 7 | + METHODS test_one_word FOR TESTING RAISING cx_static_check. |
| 8 | + METHODS test_three_words FOR TESTING RAISING cx_static_check. |
| 9 | + METHODS test_five_words_multiple FOR TESTING RAISING cx_static_check. |
| 10 | + METHODS test_three_words_comma FOR TESTING RAISING cx_static_check. |
| 11 | + METHODS test_three_words_linebreak FOR TESTING RAISING cx_static_check. |
| 12 | + METHODS test_special_character FOR TESTING RAISING cx_static_check. |
| 13 | + METHODS test_words_number_comma FOR TESTING RAISING cx_static_check. |
| 14 | + METHODS test_case_insensitive FOR TESTING RAISING cx_static_check. |
| 15 | + METHODS test_colon_apostrophe FOR TESTING RAISING cx_static_check. |
| 16 | + METHODS test_apostrophe FOR TESTING RAISING cx_static_check. |
| 17 | + METHODS test_comma_apostroph FOR TESTING RAISING cx_static_check. |
| 18 | + METHODS test_whitespaces FOR TESTING RAISING cx_static_check. |
| 19 | + METHODS test_comma_linebreaks FOR TESTING RAISING cx_static_check. |
| 20 | + |
| 21 | + |
| 22 | +ENDCLASS. |
| 23 | + |
| 24 | +CLASS ltcl_word_count IMPLEMENTATION. |
| 25 | + |
| 26 | + METHOD setup. |
| 27 | + cut = NEW zcl_word_count( ). |
| 28 | + ENDMETHOD. |
| 29 | + |
| 30 | + |
| 31 | + METHOD test_one_word. |
| 32 | + DATA(exp) = VALUE zcl_word_count=>return_table( |
| 33 | + ( word = 'word' count = 1 ) ). |
| 34 | + DATA(act) = cut->count_words( 'word' ). |
| 35 | + |
| 36 | + SORT exp BY word. |
| 37 | + SORT act BY word. |
| 38 | + cl_abap_unit_assert=>assert_equals( |
| 39 | + act = act |
| 40 | + exp = exp ). |
| 41 | + ENDMETHOD. |
| 42 | + |
| 43 | + METHOD test_three_words. |
| 44 | + DATA(exp) = VALUE zcl_word_count=>return_table( |
| 45 | + ( word = 'one' count = 1 ) |
| 46 | + ( word = 'of' count = 1 ) |
| 47 | + ( word = 'each' count = 1 ) ). |
| 48 | + DATA(act) = cut->count_words( 'one of each' ). |
| 49 | + |
| 50 | + SORT exp BY word. |
| 51 | + SORT act BY word. |
| 52 | + cl_abap_unit_assert=>assert_equals( |
| 53 | + act = act |
| 54 | + exp = exp ). |
| 55 | + ENDMETHOD. |
| 56 | + |
| 57 | + METHOD test_five_words_multiple. |
| 58 | + DATA(exp) = VALUE zcl_word_count=>return_table( |
| 59 | + ( word = 'one' count = 1 ) |
| 60 | + ( word = 'fish' count = 4 ) |
| 61 | + ( word = 'two' count = 1 ) |
| 62 | + ( word = 'red' count = 1 ) |
| 63 | + ( word = 'blue' count = 1 ) ). |
| 64 | + DATA(act) = cut->count_words( 'one fish two fish red fish blue fish' ). |
| 65 | + |
| 66 | + SORT exp BY word. |
| 67 | + SORT act BY word. |
| 68 | + cl_abap_unit_assert=>assert_equals( |
| 69 | + act = act |
| 70 | + exp = exp ). |
| 71 | + ENDMETHOD. |
| 72 | + |
| 73 | + METHOD test_three_words_comma. |
| 74 | + DATA(exp) = VALUE zcl_word_count=>return_table( |
| 75 | + ( word = 'one' count = 1 ) |
| 76 | + ( word = 'three' count = 1 ) |
| 77 | + ( word = 'two' count = 1 ) ). |
| 78 | + DATA(act) = cut->count_words( 'one,two,three' ). |
| 79 | + |
| 80 | + SORT exp BY word. |
| 81 | + SORT act BY word. |
| 82 | + cl_abap_unit_assert=>assert_equals( |
| 83 | + act = act |
| 84 | + exp = exp ). |
| 85 | + ENDMETHOD. |
| 86 | + |
| 87 | + METHOD test_three_words_linebreak. |
| 88 | + DATA(exp) = VALUE zcl_word_count=>return_table( |
| 89 | + ( word = 'one' count = 1 ) |
| 90 | + ( word = 'three' count = 1 ) |
| 91 | + ( word = 'two' count = 1 ) ). |
| 92 | + DATA(act) = cut->count_words( 'one,\ntwo,\nthree' ). |
| 93 | + |
| 94 | + SORT exp BY word. |
| 95 | + SORT act BY word. |
| 96 | + cl_abap_unit_assert=>assert_equals( |
| 97 | + act = act |
| 98 | + exp = exp ). |
| 99 | + ENDMETHOD. |
| 100 | + |
| 101 | + METHOD test_special_character. |
| 102 | + DATA(exp) = VALUE zcl_word_count=>return_table( |
| 103 | + ( word = 'car' count = 1 ) |
| 104 | + ( word = 'carpet' count = 1 ) |
| 105 | + ( word = 'as' count = 1 ) |
| 106 | + ( word = 'java' count = 1 ) |
| 107 | + ( word = 'javascript' count = 1 ) ). |
| 108 | + DATA(act) = cut->count_words( 'car: carpet as java: javascript!!&@$%^&' ). |
| 109 | + |
| 110 | + SORT exp BY word. |
| 111 | + SORT act BY word. |
| 112 | + cl_abap_unit_assert=>assert_equals( |
| 113 | + act = act |
| 114 | + exp = exp ). |
| 115 | + ENDMETHOD. |
| 116 | + |
| 117 | + METHOD test_words_number_comma. |
| 118 | + DATA(exp) = VALUE zcl_word_count=>return_table( |
| 119 | + ( word = 'testing' count = 2 ) |
| 120 | + ( word = '1' count = 1 ) |
| 121 | + ( word = '2' count = 1 ) ). |
| 122 | + DATA(act) = cut->count_words( 'testing, 1, 2 testing' ). |
| 123 | + |
| 124 | + SORT exp BY word. |
| 125 | + SORT act BY word. |
| 126 | + cl_abap_unit_assert=>assert_equals( |
| 127 | + act = act |
| 128 | + exp = exp ). |
| 129 | + ENDMETHOD. |
| 130 | + |
| 131 | + METHOD test_case_insensitive. |
| 132 | + DATA(exp) = VALUE zcl_word_count=>return_table( |
| 133 | + ( word = 'go' count = 3 ) |
| 134 | + ( word = 'stop' count = 2 ) ). |
| 135 | + DATA(act) = cut->count_words( 'go Go GO Stop stop' ). |
| 136 | + |
| 137 | + SORT exp BY word. |
| 138 | + SORT act BY word. |
| 139 | + cl_abap_unit_assert=>assert_equals( |
| 140 | + act = act |
| 141 | + exp = exp ). |
| 142 | + ENDMETHOD. |
| 143 | + |
| 144 | + METHOD test_colon_apostrophe. |
| 145 | + DATA(exp) = VALUE zcl_word_count=>return_table( |
| 146 | + ( word = 'first' count = 1 ) |
| 147 | + ( word = 'dont' count = 2 ) |
| 148 | + ( word = 'laugh' count = 1 ) |
| 149 | + ( word = 'then' count = 1 ) |
| 150 | + ( word = 'cry' count = 1 ) ). |
| 151 | + DATA(act) = cut->count_words( `First: don't laugh. Then: don't cry.` ). |
| 152 | + |
| 153 | + SORT exp BY word. |
| 154 | + SORT act BY word. |
| 155 | + cl_abap_unit_assert=>assert_equals( |
| 156 | + act = act |
| 157 | + exp = exp ). |
| 158 | + ENDMETHOD. |
| 159 | + |
| 160 | + METHOD test_apostrophe. |
| 161 | + DATA(exp) = VALUE zcl_word_count=>return_table( |
| 162 | + ( word = 'joe' count = 1 ) |
| 163 | + ( word = 'cant' count = 1 ) |
| 164 | + ( word = 'tell' count = 1 ) |
| 165 | + ( word = 'between' count = 1 ) |
| 166 | + ( word = 'large' count = 2 ) |
| 167 | + ( word = 'and' count = 1 ) ). |
| 168 | + DATA(act) = cut->count_words( `Joe can't tell between 'large' and large.` ). |
| 169 | + |
| 170 | + SORT exp BY word. |
| 171 | + SORT act BY word. |
| 172 | + cl_abap_unit_assert=>assert_equals( |
| 173 | + act = act |
| 174 | + exp = exp ). |
| 175 | + ENDMETHOD. |
| 176 | + |
| 177 | + METHOD test_comma_apostroph. |
| 178 | + DATA(exp) = VALUE zcl_word_count=>return_table( |
| 179 | + ( word = 'joe' count = 1 ) |
| 180 | + ( word = 'cant' count = 1 ) |
| 181 | + ( word = 'tell' count = 1 ) |
| 182 | + ( word = 'between' count = 1 ) |
| 183 | + ( word = 'app' count = 1 ) |
| 184 | + ( word = 'apple' count = 1 ) |
| 185 | + ( word = 'and' count = 1 ) |
| 186 | + ( word = 'a' count = 1 ) ). |
| 187 | + DATA(act) = cut->count_words( `Joe can't tell between app, apple and a.'` ). |
| 188 | + |
| 189 | + SORT exp BY word. |
| 190 | + SORT act BY word. |
| 191 | + cl_abap_unit_assert=>assert_equals( |
| 192 | + act = act |
| 193 | + exp = exp ). |
| 194 | + ENDMETHOD. |
| 195 | + |
| 196 | + METHOD test_whitespaces. |
| 197 | + DATA(exp) = VALUE zcl_word_count=>return_table( |
| 198 | + ( word = 'multiple' count = 1 ) |
| 199 | + ( word = 'whitespaces' count = 1 ) ). |
| 200 | + DATA(act) = cut->count_words( ` multiple whitespaces` ). |
| 201 | + |
| 202 | + SORT exp BY word. |
| 203 | + SORT act BY word. |
| 204 | + cl_abap_unit_assert=>assert_equals( |
| 205 | + act = act |
| 206 | + exp = exp ). |
| 207 | + ENDMETHOD. |
| 208 | + |
| 209 | + METHOD test_comma_linebreaks. |
| 210 | + DATA(exp) = VALUE zcl_word_count=>return_table( |
| 211 | + ( word = 'one' count = 1 ) |
| 212 | + ( word = 'three' count = 1 ) |
| 213 | + ( word = 'two' count = 1 ) ). |
| 214 | + DATA(act) = cut->count_words( `,\n,one,\n ,two \n 'three'` ). |
| 215 | + |
| 216 | + SORT exp BY word. |
| 217 | + SORT act BY word. |
| 218 | + cl_abap_unit_assert=>assert_equals( |
| 219 | + act = act |
| 220 | + exp = exp ). |
| 221 | + ENDMETHOD. |
| 222 | + |
| 223 | + |
| 224 | +ENDCLASS. |
0 commit comments