You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

182 lines
5.8 KiB

using Sog;
using Sog.Service;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace Game
{
//敏感词测试
class DirtyTestUtils
{
public static void OnTestALL(string filename)
{
TraceLog.Trace("DirtyTestUtils.OnTestALL start........");
for(int i = 0; i < 10; i++)
{
OnTest(filename, 1000, false);
}
for (int i = 0; i < 10; i++)
{
OnTest(filename, 10000, false);
}
for (int i = 0; i < 10; i++)
{
OnTest(filename, 100000, false);
}
//for (int i = 0; i < 10; i++)
//{
// OnTest(filename, 1000000, false);
//}
}
public static void OnTestALL2()
{
TraceLog.Trace("DirtyTestUtils.OnTestALL2 start........");
string path = "../cfg/sog/";
//OnTest(path + "暴恐词库.txt", 10000, true);
//OnTest(path + "反动词库.txt", 10000, true);
//OnTest(path + "民生词库.txt", 10000, true);
//OnTest(path + "其他词库.txt", 10000, true);
//OnTest(path + "色情词库.txt", 10000, true);
//OnTest(path + "贪腐词库.txt", 10000, true);
OnTest(path + "暴恐词库.txt", 10000, false);
OnTest(path + "反动词库.txt", 10000, false);
OnTest(path + "民生词库.txt", 10000, false);
OnTest(path + "其他词库.txt", 10000, false);
OnTest(path + "色情词库.txt", 10000, false);
OnTest(path + "贪腐词库.txt", 10000, false);
}
private static void OnTest(string filename, int count = 10000, bool bDetail = true)
{
DirtyService.Instance.InitFromFile(filename);
DirtyServiceAc.Instance.InitFromFile(filename);
List<string> dirtyList = new List<string>();
InitDirtyList(ref dirtyList, filename);
TraceLog.Trace("DirtyTestUtils.OnTest name {0} count {1}", filename, dirtyList.Count);
List<string> testList = new List<string>();
InitTestList(ref dirtyList, ref testList, count);
var time = GameServerUtils.GetApp().Time;
var start = AppTime.GetNowSysMs();
TraceLog.Trace("DirtyTestUtils.OnTest DirtyService start count {0}............", count);
for(int i = 0; i < testList.Count; i++)
{
if(bDetail)
{
TraceLog.Trace("index {0} text {1}", i, testList[i]);
}
string outMessage;
if (DirtyService.Instance.ReplaceDirtyText(testList[i], out outMessage))
{
if(bDetail)
{
TraceLog.Trace("index {0} dirty {1}", i, outMessage);
}
}
else
{
TraceLog.Error("DirtyService error : {0}", testList[i]);
}
}
var end = AppTime.GetNowSysMs();
TraceLog.Trace("DirtyTestUtils.OnTest DirtyService end............ ms {0}", end - start);
start = AppTime.GetNowSysMs();
TraceLog.Trace("DirtyTestUtils.OnTest DirtyServiceAc start count {0}............", count);
for (int i = 0; i < testList.Count; i++)
{
if(bDetail)
{
TraceLog.Trace("index {0} text {1}", i, testList[i]);
}
string outMessage;
if (DirtyServiceAc.Instance.ReplaceDirtyText(testList[i], out outMessage))
{
if(bDetail)
{
TraceLog.Trace("index {0} dirty {1}", i, outMessage);
}
}
else
{
TraceLog.Error("DirtyServiceAc error : ", testList[i]);
}
}
end = AppTime.GetNowSysMs();
TraceLog.Trace("DirtyTestUtils.OnTest DirtyServiceAc end............ ms {0}", end - start);
}
private static void InitDirtyList(ref List<string> dirtyList, string filename)
{
if (!File.Exists(filename))
{
TraceLog.Error("DirtyService.InitFromFile file {0} not exists", filename);
return;
}
string[] allline = File.ReadAllLines(filename);
foreach (var line in allline)
{
if (string.IsNullOrEmpty(line))
{
continue;
}
if (string.IsNullOrWhiteSpace(line))
{
continue;
}
if (line.Length < 2)
{
continue;
}
string lowLine = line.ToLower();
dirtyList.Add(lowLine);
}
}
private static void InitTestList(ref List<string> dirtyList, ref List<string> testList, int count = 10000)
{
var rand = GameServerUtils.GetApp().Rand;
List<string> s = new List<string> { "", "AA", "BB" };
while(count > 0)
{
StringBuilder builder = new StringBuilder();
int time = 3;
while(time > 0)
{
int idx = rand.Next(dirtyList.Count);
builder.Append(dirtyList[idx]);
idx = rand.Next(s.Count);
builder.Append(s[idx]);
time--;
}
testList.Add(builder.ToString());
count--;
}
}
}
}