-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
94 additions
and
0 deletions.
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
Tests/IsIdentifiableTests/Rules/PartPatternFilterRuleTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
using IsIdentifiable.Failures; | ||
using IsIdentifiable.Rules; | ||
using MongoDB.Driver.Linq; | ||
using NUnit.Framework; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace IsIdentifiable.Tests.Rules; | ||
|
||
internal class PartPatternFilterRuleTests | ||
{ | ||
private static IEnumerable<string> GetForamenMonroParts() | ||
{ | ||
var parts = new List<string>(); | ||
foreach (var prefix in new[] { "foramen", "foramina" }) | ||
{ | ||
foreach (var join in new[] { "of", "" }) | ||
{ | ||
foreach (var name in new[] { "monro", "monroe" }) | ||
{ | ||
parts.Add(string.Join(" ", (new[] { prefix, join, name }).Where(x => !string.IsNullOrEmpty(x)))); | ||
} | ||
} | ||
} | ||
return parts; | ||
} | ||
|
||
[TestCaseSource(nameof(GetForamenMonroParts))] | ||
public void ForamenMonro(string valuePart) | ||
{ | ||
// Arrange | ||
var rule = new PartPatternFilterRule() | ||
{ | ||
IfPartPattern = "^Monroe?$", | ||
WordBefore = "(foramen|foramina)( of)?", | ||
IfColumn = "TextValue", | ||
As = FailureClassification.Person, | ||
Action = RuleAction.Ignore, | ||
}; | ||
var name = valuePart.Split()[^1]; | ||
var problemValue = $"Mr {name} has an issue with his {valuePart}"; | ||
var validFailurePart = new FailurePart(name, FailureClassification.Person, 3); | ||
var problemOffset = problemValue.LastIndexOf(" ") + 1; | ||
var filteredFailurePart = new FailurePart(name, FailureClassification.Person, problemOffset); | ||
|
||
// Act | ||
var coversValidFailurePart = rule.Covers(validFailurePart, problemValue); | ||
var coversFilteredFailurePart = rule.Covers(filteredFailurePart, problemValue); | ||
|
||
// Assert | ||
Assert.False(coversValidFailurePart); | ||
Assert.True(coversFilteredFailurePart); | ||
} | ||
|
||
private static IEnumerable<string> GetHodgkinLymphomaParts() | ||
{ | ||
var parts = new List<string>(); | ||
foreach (var name in new[] { "hodgkin", "hodgkins", "hodgkin's" }) | ||
{ | ||
foreach (var postfix in new[] { "lymphoma", "disease" }) | ||
{ | ||
parts.Add(string.Join(" ", (new[] { name, postfix }).Where(x => !string.IsNullOrEmpty(x)))); | ||
} | ||
} | ||
return parts; | ||
} | ||
|
||
[TestCaseSource(nameof(GetHodgkinLymphomaParts))] | ||
public void HodgkinLymphoma(string valuePart) | ||
{ | ||
// Arrange | ||
var rule = new PartPatternFilterRule() | ||
{ | ||
Action = RuleAction.Ignore, | ||
As = FailureClassification.Person, | ||
IfColumn = "TextValue", | ||
IfPartPattern = "^Hodgkin(s|'s)?$", | ||
WordAfter = "(lymphoma|disease|<br>lymphoma)", | ||
}; | ||
var name = valuePart.Split()[0]; | ||
var problemValue = $"Mr {name} possibly has {valuePart}"; | ||
var validFailurePart = new FailurePart(name, FailureClassification.Person, 3); | ||
var problemOffset = problemValue.IndexOf($"has {name}") + 4; | ||
var filteredFailurePart = new FailurePart(name, FailureClassification.Person, problemOffset); | ||
|
||
// Act | ||
var coversValidFailurePart = rule.Covers(validFailurePart, problemValue); | ||
var coversFilteredFailurePart = rule.Covers(filteredFailurePart, problemValue); | ||
|
||
// Assert | ||
Assert.False(coversValidFailurePart); | ||
Assert.True(coversFilteredFailurePart); | ||
} | ||
} |