fix: Fixes and optimizes NameVerification and ProfanityProtection (#2153)
### Summary Significantly improves the performance of NameVerification & ProfanityProtection: ```cs | Method | Mean | Error | StdDev | |--------------- |----------:|----------:|----------:| | ValidateName | 728.34 ns | 13.244 ns | 11.059 ns | | ValidateNameSV | 26.62 ns | 0.233 ns | 0.207 ns | ```
This commit is contained in:
parent
0ce2a62a76
commit
a94814a7ef
9 changed files with 624 additions and 440 deletions
|
|
@ -0,0 +1,53 @@
|
|||
using Server.Misc;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests;
|
||||
|
||||
public class ProfanityProtectionTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("Hello world")]
|
||||
[InlineData("This is a normal conversation")]
|
||||
[InlineData("I would like to trade with you")]
|
||||
public void Speech_WithoutProfanity_PassesValidation(string speech)
|
||||
{
|
||||
Assert.False(ProfanityProtection.ContainsProfanity(speech));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Speech_Empty_PassesValidation()
|
||||
{
|
||||
Assert.False(ProfanityProtection.ContainsProfanity(""));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("I'm going to class tomorrow")] // contains "ass" but in "class"
|
||||
[InlineData("This assignment is hard")] // contains "ass" but in "assignment"
|
||||
[InlineData("That's a nice cocktail")] // contains "cock" but in "cocktail"
|
||||
public void Speech_WithWordsThatLookLikeProfanity_PassesValidation(string speech)
|
||||
{
|
||||
Assert.False(ProfanityProtection.ContainsProfanity(speech));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("This is ass")]
|
||||
[InlineData("What the fuck")]
|
||||
[InlineData("You're a bitch")]
|
||||
public void Speech_WithProfanity_FailsValidation(string speech)
|
||||
{
|
||||
Assert.True(ProfanityProtection.ContainsProfanity(speech));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("ass")] // standalone profanity
|
||||
[InlineData("an ass joke")] // profanity with word boundaries
|
||||
[InlineData("ass.")] // profanity followed by punctuation
|
||||
public void ContainsDisallowedWord_DetectsProfanityWithBoundaries(string speech)
|
||||
{
|
||||
Assert.True(NameVerification.ContainsDisallowedWord(
|
||||
speech,
|
||||
ProfanityProtection.Disallowed,
|
||||
ProfanityProtection.DisallowedSearchValues
|
||||
));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue