1
0
mirror of synced 2024-12-22 09:13:07 +01:00

Removed: binary tree implementation, too buggy

Fixed: Settings, to use new hash class
This commit is contained in:
Mark van Renswoude 2005-07-01 08:50:41 +00:00
parent c0c2052093
commit 227442ca52
6 changed files with 18 additions and 1339 deletions

View File

@ -1,142 +0,0 @@
unit UTrees;
interface
uses
TestFramework,
X2UtTrees;
type
TBinaryTreeTest = class(TTestCase)
private
FMemory: Integer;
FTree: TX2BinaryTree;
protected
// If we test the memory usage in SetUp and TearDown, the values are off.
// Instead, we manually call these functions to ensure our code is the only
// one that gets screened...
procedure CustomSetUp();
procedure CustomTearDown();
procedure CheckTree(const AValue: String);
published
procedure Insert();
procedure Delete();
procedure Clear();
end;
implementation
uses
SysUtils;
{ TBinaryTreeTest }
procedure TBinaryTreeTest.CustomSetUp;
begin
FMemory := AllocMemSize;
FTree := TX2BinaryTree.Create();
FTree.Insert(10);
FTree.Insert(25);
FTree.Insert(5);
FTree.Insert(8);
FTree.Insert(16);
FTree.Insert(1);
end;
procedure TBinaryTreeTest.CustomTearDown;
begin
FreeAndNil(FTree);
CheckEquals(0, AllocMemSize - FMemory, 'Memory leak');
end;
procedure TBinaryTreeTest.CheckTree;
var
sTree: String;
begin
sTree := '';
FTree.First();
while not FTree.Eof do
begin
sTree := sTree + Format('-%d', [FTree.CurrentKey]);
FTree.Next();
end;
if Length(sTree) = 0 then
Check(Length(AValue) = 0, 'Tree is empty')
else
begin
System.Delete(sTree, 1, 1);
CheckEquals(AValue, sTree, 'Tree content is invalid')
end;
end;
procedure TBinaryTreeTest.Insert;
begin
CustomSetUp();
// In these tests we also assume that iterating through the tree is done
// from top to bottom, left to right:
//
// 10
// 5 25
// 1 8 16
CheckTree('10-5-1-8-25-16');
CustomTearDown();
end;
procedure TBinaryTreeTest.Delete;
begin
CustomSetUp();
// 10
// 5 25
// 1 16
FTree.Delete(8);
CheckTree('10-5-1-25-16');
// 16
// 5 25
// 1
FTree.Delete(10);
CheckTree('16-5-1-25');
// 16
// 1 25
FTree.Delete(5);
CheckTree('16-1-25');
// 16
// 1
FTree.Delete(25);
CheckTree('16-1');
// 1
FTree.Delete(16);
CheckTree('1');
FTree.Delete(1);
CheckTree('');
CustomTearDown();
end;
procedure TBinaryTreeTest.Clear;
begin
CustomSetUp();
FTree.Clear();
CheckTree('');
CustomTearDown();
end;
initialization
RegisterTest('Trees.BinaryTree', TBinaryTreeTest.Suite);
end.

File diff suppressed because it is too large Load Diff

View File

@ -147,7 +147,7 @@ type
procedure DeleteSection(); virtual; abstract; procedure DeleteSection(); virtual; abstract;
//:$ Deletes the specified value. //:$ Deletes the specified value.
procedure DeleteValue(const AName: String); virtual; abstract; procedure DeleteValue(const AName: String); virtual;
//:$ Validates the specified value using the defined callback method //:$ Validates the specified value using the defined callback method
@ -163,7 +163,7 @@ type
} }
TX2SettingsFactory = class(TObject) TX2SettingsFactory = class(TObject)
private private
FDefines: TX2ObjectHash; FDefines: TX2SOHash;
protected protected
function GetSection(const ASection: String): TX2Settings; virtual; abstract; function GetSection(const ASection: String): TX2Settings; virtual; abstract;
function GetDefine(const ASection, AName: String): TX2SettingsDefine; virtual; function GetDefine(const ASection, AName: String): TX2SettingsDefine; virtual;
@ -512,6 +512,19 @@ begin
InternalWriteString(AName, vValue); InternalWriteString(AName, vValue);
end; end;
procedure TX2Settings.DeleteValue(const AName: String);
var
pDefine: TX2SettingsDefine;
begin
pDefine := FFactory.GetDefine(FSection, AName);
if Assigned(pDefine) then
begin
pDefine.Cached := False;
pDefine.Value := Unassigned;
end;
end;
function TX2Settings.ValidateValue; function TX2Settings.ValidateValue;
var var
@ -567,7 +580,7 @@ constructor TX2SettingsFactory.Create;
begin begin
inherited; inherited;
FDefines := TX2ObjectHash.Create(); FDefines := TX2SOHash.Create(True);
end; end;
destructor TX2SettingsFactory.Destroy; destructor TX2SettingsFactory.Destroy;

View File

@ -277,6 +277,7 @@ end;
procedure TX2INISettings.DeleteValue; procedure TX2INISettings.DeleteValue;
begin begin
inherited;
FData.DeleteKey(FSection, AName); FData.DeleteKey(FSection, AName);
end; end;

View File

@ -266,6 +266,7 @@ end;
procedure TX2RegistrySettings.DeleteValue; procedure TX2RegistrySettings.DeleteValue;
begin begin
inherited;
if OpenRead() then if OpenRead() then
if FData.ValueExists(AName) then if FData.ValueExists(AName) then
FData.DeleteValue(AName); FData.DeleteValue(AName);