|
5 | 5 |
|
6 | 6 | package fuzzystrmatch
|
7 | 7 |
|
8 |
| -import "testing" |
| 8 | +import ( |
| 9 | + "math" |
| 10 | + "testing" |
| 11 | +) |
9 | 12 |
|
10 | 13 | func TestLevenshteinDistance(t *testing.T) {
|
11 | 14 | tt := []struct {
|
@@ -482,3 +485,33 @@ func TestLevenshteinLessEqualDistanceWithCost(t *testing.T) {
|
482 | 485 | }
|
483 | 486 | }
|
484 | 487 | }
|
| 488 | + |
| 489 | +func TestLevenshtein_ExtremeValues(t *testing.T) { |
| 490 | + // Test all combinations of math.MinInt64 and math.MaxInt64 for integer |
| 491 | + // arguments. This ensures the function handles extreme values correctly |
| 492 | + // without panicking. |
| 493 | + extremeValues := []int{math.MinInt64, math.MaxInt64, 0, 1, -1, -6503603920424974249, -3160545599026710833, 3234088755759361354} |
| 494 | + testStrings := []string{"ab", "bc", "", "test"} |
| 495 | + |
| 496 | + for _, source := range testStrings { |
| 497 | + for _, target := range testStrings { |
| 498 | + for _, insCost := range extremeValues { |
| 499 | + for _, delCost := range extremeValues { |
| 500 | + for _, subCost := range extremeValues { |
| 501 | + for _, maxDist := range extremeValues { |
| 502 | + // Call the functions and ensure it doesn't panic. We don't check |
| 503 | + // the exact result since extreme values may cause integer |
| 504 | + // overflow, but we ensure no panic occurs. |
| 505 | + _ = LevenshteinLessEqualDistanceWithCost( |
| 506 | + source, target, insCost, delCost, subCost, maxDist, |
| 507 | + ) |
| 508 | + _ = LevenshteinDistanceWithCost( |
| 509 | + source, target, insCost, delCost, subCost, |
| 510 | + ) |
| 511 | + } |
| 512 | + } |
| 513 | + } |
| 514 | + } |
| 515 | + } |
| 516 | + } |
| 517 | +} |
0 commit comments