|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | + |
| 3 | +import compareValues from "./compareValues.js"; |
| 4 | + |
| 5 | +describe("compareValues()", () => { |
| 6 | + // Ratio of 0.5714285714285714, not a match given the default threshold 0.9 |
| 7 | + const resultWithDefaultThreshold = compareValues("kitten", "sitting"); |
| 8 | + it("returns an object with the expected keys", () => { |
| 9 | + const keys = Object.keys(resultWithDefaultThreshold); |
| 10 | + expect(keys.length).toBe(5); |
| 11 | + expect(keys.includes("comparisonValue1")).toBeTruthy(); |
| 12 | + expect(keys.includes("comparisonValue2")).toBeTruthy(); |
| 13 | + expect(keys.includes("threshold")).toBeTruthy(); |
| 14 | + expect(keys.includes("ratio")).toBeTruthy(); |
| 15 | + expect(keys.includes("isMatch")).toBeTruthy(); |
| 16 | + }); |
| 17 | + it("reports the default threshold value used when one isn't passed", () => { |
| 18 | + expect(resultWithDefaultThreshold.threshold).toBe(0.9); |
| 19 | + }); |
| 20 | + it("reports the Levenshtein ratio of the values being compared", () => { |
| 21 | + expect(resultWithDefaultThreshold.ratio.toFixed(2)).toBe("0.57"); |
| 22 | + }); |
| 23 | + it("reports an accurate boolean isMatch for the values being compared", () => { |
| 24 | + expect(resultWithDefaultThreshold.isMatch).toBeFalsy(); |
| 25 | + }); |
| 26 | + |
| 27 | + // Ratio of 0.5714285714285714, a match given the specific threshold 0.5 |
| 28 | + const resultWithSpecificThreshold = compareValues("kitten", "sitting", 0.5); |
| 29 | + it("reports the specified threshold value used when one is passed", () => { |
| 30 | + expect(resultWithSpecificThreshold.threshold).toBe(0.5); |
| 31 | + }); |
| 32 | + it("reports an accurate boolean isMatch for the values being compared with a low enough threshold", () => { |
| 33 | + expect(resultWithSpecificThreshold.isMatch).toBeTruthy(); |
| 34 | + }); |
| 35 | + |
| 36 | + // Specific BC Parks names with known match booleans |
| 37 | + const resultParks1 = compareValues("Aa Tlein Teix’i", "A Téix'gi Aan Tlein"); |
| 38 | + it("is not a match for: Aa Tlein Teix’i, A Téix'gi Aan Tlein", () => { |
| 39 | + expect(resultParks1.isMatch).toBeFalsy(); |
| 40 | + }); |
| 41 | + const resultParks2 = compareValues("Hakai LÚxvbálís", "Hakai Lúxvbálís"); |
| 42 | + it("is a match for: Hakai LÚxvbálís, Hakai Lúxvbálís", () => { |
| 43 | + expect(resultParks2.isMatch).toBeTruthy(); |
| 44 | + }); |
| 45 | + const resultsParks3 = compareValues("Ẁaẁley", "Ẁaẁaƛ"); |
| 46 | + it("is not a match for: Ẁaẁley, Ẁaẁaƛ", () => { |
| 47 | + expect(resultsParks3.isMatch).toBeFalsy(); |
| 48 | + }); |
| 49 | + const resultsParks4 = compareValues("Xʷakʷəᕈnaxdəᕈma", "Xʷak̓ʷəʔnaxdəʔma"); |
| 50 | + it("is not a match for: Xʷakʷəᕈnaxdəᕈma, Xʷak̓ʷəʔnaxdəʔma", () => { |
| 51 | + expect(resultsParks4.isMatch).toBeFalsy(); |
| 52 | + }); |
| 53 | + const resultsPark5 = compareValues("ɂNacinuxʷ", "ʔNacinuxʷ"); |
| 54 | + it("is a match for: ɂNacinuxʷ, ʔNacinuxʷ", () => { |
| 55 | + expect(resultsPark5.isMatch).toBeTruthy(); |
| 56 | + }); |
| 57 | + |
| 58 | + it("whitespace is trimmed as expected", () => { |
| 59 | + const result = compareValues("dog", " dog "); |
| 60 | + expect(result.comparisonValue1).toBe("dog"); |
| 61 | + expect(result.comparisonValue2).toBe("dog"); |
| 62 | + expect(result.ratio).toBe(1); |
| 63 | + expect(result.isMatch).toBeTruthy(); |
| 64 | + }); |
| 65 | +}); |
0 commit comments