| ... | ... |
@@ -87,6 +87,15 @@ int test_positions_3(){
|
| 87 | 87 |
return 0; |
| 88 | 88 |
} |
| 89 | 89 |
|
| 90 |
+int test_positions_4(){
|
|
| 91 |
+ size_t positions[2]; |
|
| 92 |
+ match_positions("as", "examples.txt", positions);
|
|
| 93 |
+ assert(positions[0] == 2); |
|
| 94 |
+ assert(positions[1] == 7); |
|
| 95 |
+ |
|
| 96 |
+ return 0; |
|
| 97 |
+} |
|
| 98 |
+ |
|
| 90 | 99 |
int test_positions_exact(){
|
| 91 | 100 |
size_t positions[3]; |
| 92 | 101 |
match_positions("foo", "foo", positions);
|
| ... | ... |
@@ -110,6 +119,7 @@ int main(int argc, char *argv[]){
|
| 110 | 119 |
runtest(test_positions_1); |
| 111 | 120 |
runtest(test_positions_2); |
| 112 | 121 |
runtest(test_positions_3); |
| 122 |
+ runtest(test_positions_4); |
|
| 113 | 123 |
runtest(test_positions_exact); |
| 114 | 124 |
|
| 115 | 125 |
summary(); |
| ... | ... |
@@ -103,7 +103,7 @@ double calculate_score(const char *needle, const char *haystack, size_t *positio |
| 103 | 103 |
|
| 104 | 104 |
for(int i = 0; i < n; i++){
|
| 105 | 105 |
for(int j = 0; j < m; j++){
|
| 106 |
- score_t score = j ? SCORE_MIN : 0; |
|
| 106 |
+ score_t score = (j || i) ? SCORE_MIN : 0; |
|
| 107 | 107 |
int match = tolower(needle[i]) == tolower(haystack[j]); |
| 108 | 108 |
D[i][j] = SCORE_MIN; |
| 109 | 109 |
if(match){
|