Menu

[r2323]: / trunk / Tests / Src / DUnit / TestUUtils.pas  Maximize  Restore  History

Download this file

115 lines (96 with data), 3.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
{
Delphi DUnit Test Case for the UUtils Unit
------------------------------------------
$Rev$
$Date$
}
unit TestUUtils;
interface
uses
// DUnit
TestFramework,
// Project
UUtils;
type
// Test methods for some routines in interface of UUtils
TTestRoutines = class(TTestCase)
published
procedure TestFloatToInt;
procedure TestIsBaseFileName;
procedure TestIsHexDigit;
procedure TestIsValidDriveLetter;
end;
implementation
uses
// Delphi
SysUtils;
{ TTestRoutines }
procedure TTestRoutines.TestFloatToInt;
begin
CheckEquals(42, FloatToInt(42.0), 'Test 1');
CheckEquals(42, FloatToInt(41.9999999), 'Test 2');
CheckEquals(42, FloatToInt(42.0000001), 'Test 3');
CheckEquals(42, FloatToInt(41.5), 'Test 4');
CheckEquals(41, FloatToInt(41.4999999), 'Test 5');
CheckEquals(-42, FloatToInt(-42.0), 'Test 6');
CheckEquals(-42, FloatToInt(-41.9999999), 'Test 7');
CheckEquals(-42, FloatToInt(-42.0000001), 'Test 8');
CheckEquals(-42, FloatToInt(-41.5), 'Test 9');
CheckEquals(-41, FloatToInt(-41.4999999), 'Test 10');
CheckEquals(0, FloatToInt(0.0), 'Test 11');
CheckEquals(0, FloatToInt(0.4999999), 'Test 12');
CheckEquals(1, FloatToInt(0.5), 'Test 13');
CheckEquals(0, FloatToInt(-0.2), 'Test 14');
CheckEquals(0, FloatToInt(-0.4999999), 'Test 15');
CheckEquals(-1, FloatToInt(-0.5), 'Test 16');
CheckEquals(-1, FloatToInt(-1.499999), 'Test 17');
CheckEquals(1234567, FloatToInt(1234566.5), 'Test 18');
CheckEquals(1234566, FloatToInt(1234566.499999), 'Test 19');
CheckEquals(-1234567, FloatToInt(-1234566.5), 'Test 20');
CheckEquals(-1234566, FloatToInt(-1234566.499999), 'Test 21');
CheckEquals(-1234567, FloatToInt(-1234567.0), 'Test 22');
CheckEquals(1234568, FloatToInt(1234567.5), 'Test 23');
CheckEquals(1234567, FloatToInt(1234567.499999), 'Test 24');
CheckEquals(-1234567, FloatToInt(-1234567.499999), 'Test 25');
CheckEquals(-1234568, FloatToInt(-1234567.5), 'Test 26');
end;
procedure TTestRoutines.TestIsBaseFileName;
begin
CheckTrue(IsBaseFileName('Foo'), 'Test 1');
CheckTrue(IsBaseFileName('Foo.bar'), 'Test 2');
CheckTrue(IsBaseFileName('Foo.bar.txt'), 'Test 3');
CheckFalse(IsBaseFileName('C:\Foo.bar'), 'Test4');
CheckFalse(IsBaseFileName('C:\Foo\Bar.txt'), 'Test5');
CheckFalse(IsBaseFileName('Foo\Bar'), 'Test 6');
CheckFalse(IsBaseFileName('Foo\Bar.txt'), 'Test 7');
CheckFalse(IsBaseFileName('\\Foo\Bar\42.txt'), 'Test 8');
CheckFalse(IsBaseFileName(''), 'Test 9');
end;
procedure TTestRoutines.TestIsHexDigit;
const
GoodChars = '1234567890ABCDEFabcdef';
BadChars = 'ghijklmnopqrstuvwxyzGHIJKLMNOPQRSTUVWXYZ |-_=+][{}@:><'#13#10#0#9;
var
Idx: Integer;
begin
for Idx := 1 to Length(GoodChars) do
CheckTrue(IsHexDigit(GoodChars[Idx]), 'Good Test ' + IntToStr(Idx));
for Idx := 1 to Length(BadChars) do
CheckFalse(IsHexDigit(BadChars[Idx]), 'Bad Test ' + IntToStr(Idx));
end;
procedure TTestRoutines.TestIsValidDriveLetter;
const
GoodChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
BadChars = '1234567890 |-_=+][{}@:><'#13#10#0#9;
var
Idx: Integer;
begin
for Idx := 1 to Length(GoodChars) do
CheckTrue(IsValidDriveLetter(GoodChars[Idx]), 'Good Test ' + IntToStr(Idx));
for Idx := 1 to Length(BadChars) do
CheckFalse(IsValidDriveLetter(BadChars[Idx]), 'Bad Test ' + IntToStr(Idx));
end;
initialization
// Register any test cases with the test runner
RegisterTest(TTestRoutines.Suite);
end.
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.