unit xxHash32NormalTest;
interface
uses
DUnitX.TestFramework,
System.SysUtils,
System.Classes,
Vcl.Forms,
xxHash32;
type
[TestFixture]
TxxHash32NormalTest = class(TObject)
protected Const
DictionaryPath = 'Res\xxHash32_Dict.txt';
class var FStringList: TStringList;
public
[Setup]
procedure Setup;
[TearDown]
procedure TearDown;
(* &&&&&&&&&&&&&&&&&&&&&&& xxHash32 Test &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *)
[Test]
procedure xxHashTest32NoRefCountedANSI();
[Test]
procedure xxHashTest32RefCountedANSI();
[Test]
procedure xxHash32SimpleANSI();
[Test]
procedure xxHash32SimpleANSIPointerVersion();
end;
implementation
procedure TxxHash32NormalTest.Setup;
var
ExePath, SubbedPath, FixedPath: String;
begin
ExePath := Application.ExeName;
SubbedPath := ExtractFileDir(ExtractFileDir(ExtractFileDir(ExePath)));
SubbedPath := StringReplace(SubbedPath, 'xxHash.Test', '', [rfReplaceAll]);
FixedPath := SubbedPath + DictionaryPath;
if not FileExists(FixedPath) then
raise Exception.Create('Dictionary File not Found in ' + FixedPath);
FStringList := TStringList.Create;
try
FStringList.LoadFromFile(FixedPath, TEncoding.ANSI);
except
raise Exception.Create('Error Loading Dictionary File');
end;
end;
procedure TxxHash32NormalTest.TearDown;
begin
FStringList.Free;
end;
(* &&&&&&&&&&&&&&&&&&&&&&& xxHash32 Test &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *)
procedure TxxHash32NormalTest.xxHashTest32NoRefCountedANSI();
var
tempByteArray: TArray<Byte>;
tempStr: String;
hash: TxxHash32;
loopCount: Integer;
tempStrArray: TArray<String>;
tempString: String;
begin
for loopCount := 0 to FStringList.Count - 1 do
begin
tempString := FStringList.Strings[loopCount];
tempStrArray := tempString.Split([':'], None);
tempByteArray := TEncoding.ANSI.GetBytes(tempStrArray[0]);
hash := TxxHash32.Create;
try
hash.Init(); // Initialize with Seed else (0) is used by default
hash.Update(tempByteArray[Low(tempByteArray)], Length(tempByteArray));
tempStr := UIntToStr(hash.Digest);
finally
hash.Free;
end;
Assert.AreEqual(tempStr, tempStrArray[1],
Format('Assertion was called with Hash of %s and Plain Value %s',
[tempStrArray[0], tempStrArray[1]]));
end;
end;
procedure TxxHash32NormalTest.xxHashTest32RefCountedANSI();
var
tempByteArray: TArray<Byte>;
tempStr: String;
hash: IIxxHash32;
loopCount: Integer;
tempStrArray: TArray<String>;
tempString: String;
begin
for loopCount := 0 to FStringList.Count - 1 do
begin
tempString := FStringList.Strings[loopCount];
tempStrArray := tempString.Split([':'], None);
tempByteArray := TEncoding.ANSI.GetBytes(tempStrArray[0]);
hash := TxxHash32.Create;
hash.Init(); // Initialize with Seed else (0) is used by default
hash.Update(tempByteArray[Low(tempByteArray)], Length(tempByteArray));
tempStr := UIntToStr(hash.Digest);
Assert.AreEqual(tempStr, tempStrArray[1],
Format('Assertion was called with Hash of %s and Plain Value %s',
[tempStrArray[0], tempStrArray[1]]));
end;
end;
procedure TxxHash32NormalTest.xxHash32SimpleANSI();
var
tempByteArray: TArray<Byte>;
tempStr: String;
loopCount: Integer;
tempStrArray: TArray<String>;
tempString: String;
begin
for loopCount := 0 to FStringList.Count - 1 do
begin
tempString := FStringList.Strings[loopCount];
tempStrArray := tempString.Split([':'], None);
tempByteArray := TEncoding.ANSI.GetBytes(tempStrArray[0]);
tempStr := UIntToStr(TxxHash32.CalculateHash32(tempByteArray
[Low(tempByteArray)], Length(tempByteArray)));
Assert.AreEqual(tempStr, tempStrArray[1],
Format('Assertion was called with Hash of %s and Plain Value %s',
[tempStrArray[0], tempStrArray[1]]));
end;
end;
procedure TxxHash32NormalTest.xxHash32SimpleANSIPointerVersion();
var
tempByteArray: TArray<Byte>;
tempStr: String;
loopCount: Integer;
tempStrArray: TArray<String>;
tempString: String;
begin
for loopCount := 0 to FStringList.Count - 1 do
begin
tempString := FStringList.Strings[loopCount];
tempStrArray := tempString.Split([':'], None);
tempByteArray := TEncoding.ANSI.GetBytes(tempStrArray[0]);
tempStr := UIntToStr(TxxHash32.CalculateHash32(Pointer(tempByteArray)^,
Length(tempByteArray)));
Assert.AreEqual(tempStr, tempStrArray[1],
Format('Assertion was called with Hash of %s and Plain Value %s',
[tempStrArray[0], tempStrArray[1]]));
end;
end;
initialization
TDUnitX.RegisterTestFixture(TxxHash32NormalTest);
end.
delphi 單元測試
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
- 文/潘曉璐 我一進(jìn)店門格仲,熙熙樓的掌柜王于貴愁眉苦臉地迎上來押袍,“玉大人,你說我怎么就攤上這事抓狭〔。” “怎么了?”我有些...
- 文/不壞的土叔 我叫張陵否过,是天一觀的道長午笛。 經(jīng)常有香客問我,道長苗桂,這世上最難降的妖魔是什么药磺? 我笑而不...
- 正文 為了忘掉前任,我火速辦了婚禮煤伟,結(jié)果婚禮上癌佩,老公的妹妹穿的比我還像新娘。我一直安慰自己便锨,他們只是感情好围辙,可當(dāng)我...
- 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪淑趾。 梳的紋絲不亂的頭發(fā)上慷蠕,一...
- 文/蒼蘭香墨 我猛地睜開眼包斑,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了策精?” 一聲冷哼從身側(cè)響起舰始,我...
- 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎咽袜,沒想到半個月后丸卷,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
- 正文 獨(dú)居荒郊野嶺守林人離奇死亡询刹,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
- 正文 我和宋清朗相戀三年谜嫉,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片凹联。...
- 正文 年R本政府宣布澳淑,位于F島的核電站比原,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏杠巡。R本人自食惡果不足惜量窘,卻給世界環(huán)境...
- 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望氢拥。 院中可真熱鬧蚌铜,春花似錦、人聲如沸嫩海。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽叁怪。三九已至造壮,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間骂束,已是汗流浹背耳璧。 一陣腳步聲響...
- 正文 我出身青樓,卻偏偏與公主長得像混驰,于是被迫代替她去往敵國和親攀隔。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
推薦閱讀更多精彩內(nèi)容
- 系列教程 在Android Studio中進(jìn)行單元測試和UI測試 - 1.概述 在Android Studio中進(jìn)...
- 系列教程 在Android Studio中進(jìn)行單元測試和UI測試 - 1.概述 在Android Studio中進(jìn)...
- 系列教程 在Android Studio中進(jìn)行單元測試和UI測試 - 1.概述 在Android Studio中進(jìn)...
- 本節(jié)將涵蓋Angular常用的組件單元測試方法愚争,例如:Router映皆、Component、Directive轰枝、Pip...