Always accept empty string as meaning zero is TryRomanToInt, fixes intermittent errors in tromantoint test

git-svn-id: trunk@40537 -
This commit is contained in:
pierre 2018-12-13 10:21:58 +00:00
parent f7efca92ec
commit f8563772c5
2 changed files with 17 additions and 3 deletions

View File

@ -2427,7 +2427,12 @@ begin
Result := True;
Exit;
end;
if (Len = 0) then Exit;
if (Len = 0) then
begin
Result:=true;
N:=0;
Exit;
end;
i := 1;
N := 0;
Terminated := False;

View File

@ -14,10 +14,16 @@ procedure RomanToIntTest(const testRoman: string;
var
test: integer;
begin
test := RomanToInt(testRoman);
try
test := RomanToInt(testRoman);
except
{ make sure that if an exception is generated,
the error is raised }
test:=expectation-1;
end;
if test <> expectation then
begin
writeln('Testing strUtils/RomanToInt: Test with ', testRoman, ' failed.');
writeln('Testing strUtils/RomanToInt: Test with "', testRoman, '" failed.');
writeln('Returned number: ', test);
writeln('Expected number: ', expectation);
exitCode := 1;
@ -30,6 +36,9 @@ var
testInteger: integer;
begin
{ Check that empty string is accepted as zero vvalue }
RomanToIntTest('',0);
for i := 1 to 2000 do
begin
testInteger := i;