person-service 0.5.0

Person Service - A person administration microservice that interoperates with the person-matcher crate
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
//! Match scoring calculations.
//!
//! This module turns the per-field scores from
//! [`crate::matching::algorithms`] into an overall match score for a
//! pair of persons. Two strategies live here:
//!
//! - [`ProbabilisticScorer`](crate::matching::scoring::ProbabilisticScorer) — a weighted average over the components
//!   that are *present on both records*, with the absent components
//!   dropped from both numerator and denominator (renormalization), so
//!   sparse records are not unfairly penalized. Tax-ID and document
//!   exact matches short-circuit to near-certain scores.
//! - [`DeterministicScorer`](crate::matching::scoring::DeterministicScorer) — rule-based points: a tax-ID / identifier
//!   / document exact match short-circuits to `1.0`; otherwise it awards
//!   one point each for strong name, DOB, and gender agreement (plus an
//!   optional address point) and divides by the points available.
//!
//! [`MatchQuality`] buckets a numeric score into definite / probable /
//! possible / unlikely for human-facing classification.

use crate::models::Person;
use crate::config::MatchingConfig;
use super::{MatchResult, MatchScoreBreakdown};
use super::algorithms::{
    name_matching, dob_matching, gender_matching,
    address_matching, identifier_matching,
    tax_id_matching, document_matching,
};

/// Weighted-average ("probabilistic") scoring strategy.
///
/// Combines fuzzy per-field scores into a single confidence value in
/// `[0.0, 1.0]` using the configured threshold to decide matches.
pub struct ProbabilisticScorer {
    /// Configuration for matching thresholds and weights
    config: MatchingConfig,
}

impl ProbabilisticScorer {
    /// Create a new probabilistic scorer from a [`MatchingConfig`].
    pub fn new(config: MatchingConfig) -> Self {
        Self { config }
    }

    /// Score a candidate against a reference person.
    ///
    /// Computes all seven component scores, short-circuits to `1.0` on a
    /// tax-ID exact match or `0.98` on a document exact match, and
    /// otherwise returns the weight-renormalized average over the
    /// components present on both records. The full
    /// [`MatchScoreBreakdown`] is always included.
    pub fn calculate_score(
        &self,
        person: &Person,
        candidate: &Person,
    ) -> MatchResult {
        // Calculate individual component scores
        let name_score = name_matching::match_names(&person.name, &candidate.name);

        let birth_date_score = dob_matching::match_birth_dates(
            person.birth_date,
            candidate.birth_date,
        );

        let gender_score = gender_matching::match_gender(
            person.gender,
            candidate.gender,
        );

        let address_score = address_matching::match_addresses(
            &person.addresses,
            &candidate.addresses,
        );

        let identifier_score = identifier_matching::match_identifiers(
            &person.identifiers,
            &candidate.identifiers,
        );

        let tax_id_score = tax_id_matching::match_tax_ids(person, candidate);

        let document_score = document_matching::match_documents(
            &person.documents,
            &candidate.documents,
        );

        // Tax ID exact match is a strong deterministic signal — short-circuit
        if tax_id_score >= 1.0 {
            return MatchResult {
                person: candidate.clone(),
                score: 1.0,
                breakdown: MatchScoreBreakdown {
                    name_score, birth_date_score, gender_score,
                    address_score, identifier_score, tax_id_score, document_score,
                },
            };
        }

        // Document number exact match is also a strong signal — short-circuit
        if document_score >= 1.0 {
            return MatchResult {
                person: candidate.clone(),
                score: 0.98,
                breakdown: MatchScoreBreakdown {
                    name_score, birth_date_score, gender_score,
                    address_score, identifier_score, tax_id_score, document_score,
                },
            };
        }

        // Weight factors for each component (probabilistic). When BOTH
        // sides lack the underlying data for a component we drop the
        // component from the sum AND its weight from the denominator
        // so the final score is the weighted average over the present
        // components rather than penalising absent ones. Two records
        // with identical name+DOB+gender (and no address / identifier /
        // tax_id / documents) therefore score 1.0, not 0.65.
        const NAME_WEIGHT: f64 = 0.30;
        const DOB_WEIGHT: f64 = 0.25;
        const GENDER_WEIGHT: f64 = 0.10;
        const ADDRESS_WEIGHT: f64 = 0.10;
        const IDENTIFIER_WEIGHT: f64 = 0.10;
        const TAX_ID_WEIGHT: f64 = 0.10;
        const DOCUMENT_WEIGHT: f64 = 0.05;

        let mut weighted_sum = 0.0_f64;
        let mut weight_sum = 0.0_f64;

        // Name is required, so it always contributes.
        weighted_sum += name_score * NAME_WEIGHT;
        weight_sum += NAME_WEIGHT;

        if person.birth_date.is_some() && candidate.birth_date.is_some() {
            weighted_sum += birth_date_score * DOB_WEIGHT;
            weight_sum += DOB_WEIGHT;
        }

        // Gender is always set (enum has Unknown), so it always contributes.
        weighted_sum += gender_score * GENDER_WEIGHT;
        weight_sum += GENDER_WEIGHT;

        if !person.addresses.is_empty() && !candidate.addresses.is_empty() {
            weighted_sum += address_score * ADDRESS_WEIGHT;
            weight_sum += ADDRESS_WEIGHT;
        }

        if !person.identifiers.is_empty() && !candidate.identifiers.is_empty() {
            weighted_sum += identifier_score * IDENTIFIER_WEIGHT;
            weight_sum += IDENTIFIER_WEIGHT;
        }

        if person.effective_tax_id().is_some() && candidate.effective_tax_id().is_some() {
            weighted_sum += tax_id_score * TAX_ID_WEIGHT;
            weight_sum += TAX_ID_WEIGHT;
        }

        if !person.documents.is_empty() && !candidate.documents.is_empty() {
            weighted_sum += document_score * DOCUMENT_WEIGHT;
            weight_sum += DOCUMENT_WEIGHT;
        }

        let total_score = if weight_sum > 0.0 { weighted_sum / weight_sum } else { 0.0 };

        let breakdown = MatchScoreBreakdown {
            name_score,
            birth_date_score,
            gender_score,
            address_score,
            identifier_score,
            tax_id_score,
            document_score,
        };

        MatchResult {
            person: candidate.clone(),
            score: total_score,
            breakdown,
        }
    }

    /// Return `true` when `score` meets the configured threshold.
    pub fn is_match(&self, score: f64) -> bool {
        score >= self.config.threshold_score
    }

    /// Bucket a numeric score into a [`MatchQuality`].
    ///
    /// `>= 0.95` is definite, `>= threshold` is probable, `>= 0.50` is
    /// possible, anything lower is unlikely.
    pub fn classify_match(&self, score: f64) -> MatchQuality {
        if score >= 0.95 {
            MatchQuality::Definite
        } else if score >= self.config.threshold_score {
            MatchQuality::Probable
        } else if score >= 0.50 {
            MatchQuality::Possible
        } else {
            MatchQuality::Unlikely
        }
    }
}

/// Rule-based ("deterministic") scoring strategy.
///
/// Awards discrete points for strong field agreement and short-circuits
/// to `1.0` on any exact identifier-class match.
pub struct DeterministicScorer {
    /// Configuration for matching (currently unused; reserved for
    /// future rule tuning, hence the leading underscore).
    _config: MatchingConfig,
}

impl DeterministicScorer {
    /// Create a new deterministic scorer from a [`MatchingConfig`].
    pub fn new(config: MatchingConfig) -> Self {
        Self { _config: config }
    }

    /// Score a candidate against a reference person using strict rules.
    ///
    /// Rule 0/1/1b: an exact tax-ID, identifier, or document match
    /// short-circuits to `1.0`. Otherwise Rule 2 awards one point each
    /// for name `>= 0.90`, DOB `>= 0.95`, and exact gender, and Rule 3
    /// adds an optional address point; the final score is points earned
    /// over points available.
    pub fn calculate_score(
        &self,
        person: &Person,
        candidate: &Person,
    ) -> MatchResult {
        let mut total_score = 0.0;
        let mut points_available = 0.0;

        // Rule 0: Tax ID exact match = definite match
        let tax_id_score = tax_id_matching::match_tax_ids(person, candidate);
        if tax_id_score >= 1.0 {
            return MatchResult {
                person: candidate.clone(),
                score: 1.0,
                breakdown: MatchScoreBreakdown {
                    name_score: 0.0, birth_date_score: 0.0, gender_score: 0.0,
                    address_score: 0.0, identifier_score: 0.0,
                    tax_id_score, document_score: 0.0,
                },
            };
        }

        // Rule 1: Exact identifier match = definite match
        let identifier_score = identifier_matching::match_identifiers(
            &person.identifiers,
            &candidate.identifiers,
        );

        if identifier_score >= 0.98 {
            return MatchResult {
                person: candidate.clone(),
                score: 1.0,
                breakdown: MatchScoreBreakdown {
                    name_score: 0.0, birth_date_score: 0.0, gender_score: 0.0,
                    address_score: 0.0, identifier_score,
                    tax_id_score, document_score: 0.0,
                },
            };
        }

        // Rule 1b: Document number exact match = definite match
        let document_score = document_matching::match_documents(
            &person.documents,
            &candidate.documents,
        );

        if document_score >= 1.0 {
            return MatchResult {
                person: candidate.clone(),
                score: 1.0,
                breakdown: MatchScoreBreakdown {
                    name_score: 0.0, birth_date_score: 0.0, gender_score: 0.0,
                    address_score: 0.0, identifier_score,
                    tax_id_score, document_score,
                },
            };
        }

        // Rule 2: Name + DOB + Gender must all match
        let name_score = name_matching::match_names(&person.name, &candidate.name);
        let dob_score = dob_matching::match_birth_dates(
            person.birth_date,
            candidate.birth_date,
        );
        let gender_score = gender_matching::match_gender(
            person.gender,
            candidate.gender,
        );

        points_available += 3.0;

        if name_score >= 0.90 {
            total_score += 1.0;
        }

        if dob_score >= 0.95 {
            total_score += 1.0;
        }

        if gender_score >= 1.0 {
            total_score += 1.0;
        }

        // Rule 3: Address is optional but adds confidence
        let address_score = address_matching::match_addresses(
            &person.addresses,
            &candidate.addresses,
        );

        if !person.addresses.is_empty() && !candidate.addresses.is_empty() {
            points_available += 1.0;
            if address_score >= 0.80 {
                total_score += 1.0;
            }
        }

        // Calculate final score as percentage of available points
        let final_score = if points_available > 0.0 {
            total_score / points_available
        } else {
            0.0
        };

        let breakdown = MatchScoreBreakdown {
            name_score,
            birth_date_score: dob_score,
            gender_score,
            address_score,
            identifier_score,
            tax_id_score,
            document_score,
        };

        MatchResult {
            person: candidate.clone(),
            score: final_score,
            breakdown,
        }
    }

    /// Return `true` when a deterministic score meets the `0.75` bar
    /// (at least three of the four rules satisfied).
    pub fn is_match(&self, score: f64) -> bool {
        score >= 0.75 // Require at least 3/4 rules to match
    }
}

/// Human-facing classification of a numeric match score.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MatchQuality {
    /// Definite match (score >= 0.95)
    Definite,
    /// Probable match (score >= threshold)
    Probable,
    /// Possible match (score >= 0.50)
    Possible,
    /// Unlikely match (score < 0.50)
    Unlikely,
}

impl MatchQuality {
    /// Lowercase string name (`"definite"`, `"probable"`, …) for API
    /// responses and review-queue records.
    pub fn as_str(&self) -> &'static str {
        match self {
            MatchQuality::Definite => "definite",
            MatchQuality::Probable => "probable",
            MatchQuality::Possible => "possible",
            MatchQuality::Unlikely => "unlikely",
        }
    }

    /// Return `true` for qualities that count as a match (definite or
    /// probable).
    pub fn is_match(&self) -> bool {
        matches!(self, MatchQuality::Definite | MatchQuality::Probable)
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::models::{HumanName, Gender};
    use jiff::civil::Date;

    /// Build a default config with an 0.85 probable threshold.
    fn create_test_config() -> MatchingConfig {
        MatchingConfig {
            threshold_score: 0.85,
            exact_match_score: 1.0,
            fuzzy_match_score: 0.8,
        }
    }

    /// Build a minimal male "John <name>" person with the given DOB.
    fn create_test_person(name: &str, dob: Option<Date>) -> Person {
        Person {
            id: uuid::Uuid::new_v4(),
            identifiers: vec![],
            active: true,
            name: HumanName {
                use_type: None,
                family: name.to_string(),
                given: vec!["John".to_string()],
                prefix: vec![],
                suffix: vec![],
            },
            additional_names: vec![],
            telecom: vec![],
            gender: Gender::Male,
            birth_date: dob,
            tax_id: None,
            documents: vec![],
            emergency_contacts: vec![],
            deceased: false,
            deceased_datetime: None,
            addresses: vec![],
            marital_status: None,
            multiple_birth: None,
            photo: vec![],
            managing_organization: None,
            links: vec![],
            created_at: jiff::Timestamp::now(),
            updated_at: jiff::Timestamp::now(),
        }
    }

    /// Identical name+DOB+gender renormalizes to ~1.0 (definite).
    #[test]
    fn test_exact_match_scores_high() {
        let config = create_test_config();
        let scorer = ProbabilisticScorer::new(config);

        let dob = Some(jiff::civil::date(1980, 1, 15));
        let person1 = create_test_person("Smith", dob);
        let person2 = create_test_person("Smith", dob);

        let result = scorer.calculate_score(&person1, &person2);

        // Per spec change 2026-06-03, weights renormalise over present
        // components. Identical name + DOB + gender (no address /
        // identifier / tax_id / document on either side) is
        // (1*0.30 + 1*0.25 + 1*0.10) / (0.30 + 0.25 + 0.10) = 1.0.
        assert!(
            result.score >= 0.99,
            "Exact match on name+DOB+gender should renormalise to 1.0, got {}",
            result.score,
        );
        assert!(scorer.is_match(result.score));
        assert_eq!(scorer.classify_match(result.score), MatchQuality::Definite);
    }

    /// Spelling variant + day-off DOB still scores in the probable band.
    #[test]
    fn test_fuzzy_match_scores_moderate() {
        let config = create_test_config();
        let scorer = ProbabilisticScorer::new(config);

        let dob1 = Some(jiff::civil::date(1980, 1, 15));
        let dob2 = Some(jiff::civil::date(1980, 1, 16)); // One day off

        let person1 = create_test_person("Smith", dob1);
        let person2 = create_test_person("Smyth", dob2); // Spelling variant

        let result = scorer.calculate_score(&person1, &person2);

        // Post-renormalisation: name ~0.93 (Jaro-Winkler) + DOB ~0.95
        // (day off by 1) + gender 1.0, weighted average over 0.65 of
        // weight, lands in the probable / certain band rather than the
        // possible band the old non-renormalised sum (~0.55) produced.
        assert!(result.score > 0.85, "Fuzzy near-match should score > 0.85, got {}", result.score);
        assert!(result.score < 1.0);
    }

    /// Unrelated name + far-apart DOB scores below 0.50.
    #[test]
    fn test_no_match_scores_low() {
        let config = create_test_config();
        let scorer = ProbabilisticScorer::new(config);

        let dob1 = Some(jiff::civil::date(1980, 1, 15));
        let dob2 = Some(jiff::civil::date(1990, 6, 20));

        let person1 = create_test_person("Smith", dob1);
        let person2 = create_test_person("Johnson", dob2);

        let result = scorer.calculate_score(&person1, &person2);

        assert!(result.score < 0.50, "Non-match should score < 0.50, got {}", result.score);
        assert!(!scorer.is_match(result.score));
    }

    /// Deterministic scorer meets its 0.75 bar on identical records.
    #[test]
    fn test_deterministic_exact_match() {
        let config = create_test_config();
        let scorer = DeterministicScorer::new(config);

        let dob = Some(jiff::civil::date(1980, 1, 15));
        let person1 = create_test_person("Smith", dob);
        let person2 = create_test_person("Smith", dob);

        let result = scorer.calculate_score(&person1, &person2);

        assert!(result.score >= 0.75, "Exact match should meet deterministic threshold");
        assert!(scorer.is_match(result.score));
    }

    /// Representative scores map to the expected quality buckets.
    #[test]
    fn test_match_quality_classification() {
        assert_eq!(ProbabilisticScorer::new(create_test_config())
            .classify_match(0.98), MatchQuality::Definite);

        assert_eq!(ProbabilisticScorer::new(create_test_config())
            .classify_match(0.87), MatchQuality::Probable);

        assert_eq!(ProbabilisticScorer::new(create_test_config())
            .classify_match(0.60), MatchQuality::Possible);

        assert_eq!(ProbabilisticScorer::new(create_test_config())
            .classify_match(0.30), MatchQuality::Unlikely);
    }

    /// Matching name+DOB+gender+address+identifier scores very high.
    #[test]
    fn test_probabilistic_all_fields_match() {
        let config = create_test_config();
        let scorer = ProbabilisticScorer::new(config);

        let dob = Some(jiff::civil::date(1980, 1, 15));
        let mut person1 = create_test_person("Smith", dob);
        let mut person2 = create_test_person("Smith", dob);

        // Add matching addresses
        let addr = crate::models::Address {
            use_type: None,
            line1: Some("123 Main St".into()),
            line2: None,
            city: Some("Springfield".into()),
            state: Some("IL".into()),
            postal_code: Some("62701".into()),
            country: None,
        };
        person1.addresses = vec![addr.clone()];
        person2.addresses = vec![addr];

        // Add matching identifiers
        let id = crate::models::Identifier::mrn("hospital-a".into(), "MRN-001".into());
        person1.identifiers = vec![id.clone()];
        person2.identifiers = vec![id];

        let result = scorer.calculate_score(&person1, &person2);
        assert!(result.score > 0.80, "All fields matching should score very high, got {}", result.score);
    }

    /// Divergent name+DOB+gender stays well below threshold.
    #[test]
    fn test_probabilistic_no_fields_match() {
        let config = create_test_config();
        let scorer = ProbabilisticScorer::new(config);

        let mut person1 = create_test_person("Smith", Some(jiff::civil::date(1980, 1, 15)));
        person1.gender = Gender::Male;
        let mut person2 = create_test_person("Johnson", Some(jiff::civil::date(1995, 8, 22)));
        person2.gender = Gender::Female;

        let result = scorer.calculate_score(&person1, &person2);
        // Post-renormalisation: low name (Smith vs Johnson), low DOB
        // (15 years apart), 0 gender — averaged over 0.65 of weight.
        // The result is still well below the 0.85 threshold, but the
        // renormalisation moves it up from the old ~0.10 to ~0.20.
        assert!(result.score < 0.40, "Unrelated records should score well below threshold, got {}", result.score);
        assert!(!scorer.is_match(result.score));
    }

    /// Same name but different DOB lands between 0.30 and 0.80.
    #[test]
    fn test_probabilistic_partial_match() {
        let config = create_test_config();
        let scorer = ProbabilisticScorer::new(config);

        // Same name but different DOB
        let person1 = create_test_person("Smith", Some(jiff::civil::date(1980, 1, 15)));
        let person2 = create_test_person("Smith", Some(jiff::civil::date(1990, 6, 20)));

        let result = scorer.calculate_score(&person1, &person2);
        assert!(result.score > 0.30, "Name match alone should contribute some score, got {}", result.score);
        assert!(result.score < 0.80, "Only name match should not score too high, got {}", result.score);
    }

    /// A shared tax ID short-circuits the deterministic scorer to 1.0.
    #[test]
    fn test_deterministic_tax_id_match_short_circuits() {
        let config = create_test_config();
        let scorer = DeterministicScorer::new(config);

        let mut person1 = create_test_person("Smith", Some(jiff::civil::date(1980, 1, 15)));
        person1.tax_id = Some("123-45-6789".into());
        let mut person2 = create_test_person("Jones", Some(jiff::civil::date(1995, 12, 1)));
        person2.tax_id = Some("123-45-6789".into());

        let result = scorer.calculate_score(&person1, &person2);
        assert_eq!(result.score, 1.0, "Tax ID match should short-circuit to 1.0");
        assert_eq!(result.breakdown.tax_id_score, 1.0);
    }

    /// A shared exact identifier short-circuits to 1.0.
    #[test]
    fn test_deterministic_identifier_match() {
        let config = create_test_config();
        let scorer = DeterministicScorer::new(config);

        let id = crate::models::Identifier::ssn("123-45-6789".into());
        let mut person1 = create_test_person("Smith", Some(jiff::civil::date(1980, 1, 15)));
        person1.identifiers = vec![id.clone()];
        let mut person2 = create_test_person("Jones", Some(jiff::civil::date(1995, 12, 1)));
        person2.identifiers = vec![id];

        let result = scorer.calculate_score(&person1, &person2);
        assert_eq!(result.score, 1.0, "Exact identifier match should short-circuit to 1.0");
    }

    /// The 0.95 definite/probable boundary is inclusive at 0.95.
    #[test]
    fn test_score_boundary_0_95() {
        let scorer = ProbabilisticScorer::new(create_test_config());
        assert_eq!(scorer.classify_match(0.95), MatchQuality::Definite);
        assert_eq!(scorer.classify_match(0.949), MatchQuality::Probable);
    }

    /// A 0.70 configured threshold is inclusive at exactly 0.70.
    #[test]
    fn test_score_boundary_0_70() {
        let config = MatchingConfig {
            threshold_score: 0.70,
            exact_match_score: 1.0,
            fuzzy_match_score: 0.8,
        };
        let scorer = ProbabilisticScorer::new(config);
        assert!(scorer.is_match(0.70), "Score at threshold should be a match");
        assert!(!scorer.is_match(0.69), "Score below threshold should not be a match");
        assert_eq!(scorer.classify_match(0.70), MatchQuality::Probable);
    }
}