Fixed: Null Tag Handling

This commit is contained in:
bakerboy448 2025-09-05 09:41:27 -05:00
parent ffab40e923
commit 56480c7c0a
2 changed files with 26 additions and 2 deletions

View file

@ -163,5 +163,29 @@ public void test_raw_distance()
dist.RawDistance().Should().Be(2.25);
}
[Test]
public void test_add_string_null_handling()
{
var dist = new Distance();
dist.AddString("string", null, "target");
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { { "string", new List<double> { 1.0 } } });
dist.AddString("string2", "value", null);
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>>
{
{ "string", new List<double> { 1.0 } },
{ "string2", new List<double> { 1.0 } }
});
dist.AddString("string3", null, null);
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>>
{
{ "string", new List<double> { 1.0 } },
{ "string2", new List<double> { 1.0 } },
{ "string3", new List<double> { 0.0 } }
});
}
}
}

View file

@ -125,8 +125,8 @@ private static string Clean(string input)
public void AddString(string key, string value, string target)
{
// Adds a penaltly based on the distance between value and target
var cleanValue = Clean(value);
var cleanTarget = Clean(target);
var cleanValue = Clean(value ?? string.Empty);
var cleanTarget = Clean(target ?? string.Empty);
if (cleanValue.IsNullOrWhiteSpace() && cleanTarget.IsNotNullOrWhiteSpace())
{