[JEDI.NET-commits] nunit/source Jedi.System.Strings.NUnit.pas,1.2,1.3
Status: Pre-Alpha
Brought to you by:
jedi_mbe
From: Marcel B. <jed...@us...> - 2005-03-04 14:48:58
|
Update of /cvsroot/jedidotnet/nunit/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28177/nunit/source Modified Files: Jedi.System.Strings.NUnit.pas Log Message: * Updated/extended test-sets for IntToHex and HexToInt * Added test-sets for IntToBin, IntToOct, BinToInt and OctToInt Index: Jedi.System.Strings.NUnit.pas =================================================================== RCS file: /cvsroot/jedidotnet/nunit/source/Jedi.System.Strings.NUnit.pas,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Jedi.System.Strings.NUnit.pas 22 Jan 2005 15:12:37 -0000 1.2 --- Jedi.System.Strings.NUnit.pas 4 Mar 2005 14:48:38 -0000 1.3 *************** *** 181,223 **** [TestFixture] NumericConversions = class ! {$REGION 'IntToHex test constants'} strict protected ! const IntHex1Input = 255; ! const IntHex1Output = 'ff'; ! const IntHex1OutputByte = 'ff'; ! const IntHex1OutputFixed = '000000ff'; ! const IntHex2Input = 256; ! const IntHex2Output = '100'; ! const IntHex2OutputByte = '0100'; ! const IntHex2OutputFixed = '00000100'; ! const IntHex3Input = -1; ! const IntHex3Output = 'ffffffff'; ! const IntHex3OutputByte = 'ffffffff'; ! const IntHex3OutputFixed = 'ffffffff'; ! {$ENDREGION} ! {$REGION 'HexToInt test constants'} strict protected ! const HexInt1Input = 'ff'; ! const HexInt1InputMax = 'ffghijk'; ! const HexInt1CountMax = 2; ! const HexInt1InputLeads = '0000ffghjkl'; ! const HexInt1CountLeads = 6; ! const HexInt1Value = 255; ! const HexInt2Input = '100'; ! const HexInt2InputMax = '100ghijk'; ! const HexInt2CountMax = 3; ! const HexInt2InputLeads = '0000100ghjkl'; ! const HexInt2CountLeads = 7; ! const HexInt2Value = 256; ! const HexInt3Input = 'ffffFFFF'; ! const HexInt3InputMax = 'ffFFfFffghijk'; ! const HexInt3CountMax = 8; ! const HexInt3InputLeads = '0000ffFFFffFghjkl'; ! const HexInt3CountLeads = 12; ! const HexInt3Value = -1; {$ENDREGION} public [Test] procedure HexToInt; [Test] procedure IntToHex; end; --- 181,239 ---- [TestFixture] NumericConversions = class ! {$REGION 'IntTo* test constants'} strict protected ! const IntByteSize1 = 0; ! const IntByteSize2 = 255; ! const IntWordSize1 = 256; ! const IntWordSize2 = 65535; ! const IntLongSize1 = 65536; ! const IntLongSize2 = -1; strict protected ! const IntByteSize1Bin: string = '00000000'; ! const IntByteSize1BinShortest: string = '0'; ! const IntByteSize2Bin: string = '11111111'; ! const IntByteSize2BinShortest: string = '11111111'; ! const IntWordSize1Bin: string = '0000000100000000'; ! const IntWordSize1BinShortest: string = '100000000'; ! const IntWordSize2Bin: string = '1111111111111111'; ! const IntWordSize2BinShortest: string = '1111111111111111'; ! const IntLongSize1Bin: string = '00000000000000010000000000000000'; ! const IntLongSize1BinShortest: string = '10000000000000000'; ! const IntLongSize2Bin: string = '11111111111111111111111111111111'; ! const IntLongSize2BinShortest: string = '11111111111111111111111111111111'; ! strict protected ! const IntByteSize1Hex: string = '00'; ! const IntByteSize1HexShortest: string = '0'; ! const IntByteSize2Hex: string = 'ff'; ! const IntByteSize2HexShortest: string = 'ff'; ! const IntWordSize1Hex: string = '0100'; ! const IntWordSize1HexShortest: string = '100'; ! const IntWordSize2Hex: string = 'ffff'; ! const IntWordSize2HexShortest: string = 'ffff'; ! const IntLongSize1Hex: string = '00010000'; ! const IntLongSize1HexShortest: string = '10000'; ! const IntLongSize2Hex: string = 'ffffffff'; ! const IntLongSize2HexShortest: string = 'ffffffff'; ! strict protected ! const IntByteSize1Oct: string = '000'; ! const IntByteSize1OctShortest: string = '0'; ! const IntByteSize2Oct: string = '377'; ! const IntByteSize2OctShortest: string = '377'; ! const IntWordSize1Oct: string = '000400'; ! const IntWordSize1OctShortest: string = '400'; ! const IntWordSize2Oct: string = '177777'; ! const IntWordSize2OctShortest: string = '177777'; ! const IntLongSize1Oct: string = '00000200000'; ! const IntLongSize1OctShortest: string = '200000'; ! const IntLongSize2Oct: string = '37777777777'; ! const IntLongSize2OctShortest: string = '37777777777'; {$ENDREGION} public + [Test] procedure BinToInt; [Test] procedure HexToInt; + [Test] procedure OctToInt; + [Test] procedure IntToBin; [Test] procedure IntToHex; + [Test] procedure IntToOct; end; *************** *** 279,361 **** {$REGION 'NumericConversions'} ! procedure NumericConversions.HexToInt; var digitsUsed: Integer; begin ! Assert.AreEqual( ! HexInt1Value, ! StringUtils.HexToInt(HexInt1Input), ! 'Test1, complete string'); ! Assert.AreEqual( ! HexInt1Value, ! StringUtils.HexToInt(HexInt1InputMax, HexInt1CountMax, False, digitsUsed), ! 'Test1, limit string.'); ! Assert.AreEqual( ! HexInt1CountMax, ! digitsUsed, ! 'Test1 digit count.'); ! Assert.AreEqual( ! HexInt1Value, ! StringUtils.HexToInt(HexInt1InputLeads, HexInt1CountMax, True, digitsUsed), ! 'Test1, limit string, ignore leading zeroes.'); ! Assert.AreEqual( ! HexInt1CountLeads, ! digitsUsed, ! 'Test1 digit count, ignoring leading zeroes.'); Assert.AreEqual( ! HexInt2Value, ! StringUtils.HexToInt(HexInt2Input), ! 'Test2, complete string'); ! Assert.AreEqual( ! HexInt2Value, ! StringUtils.HexToInt(HexInt2InputMax, HexInt2CountMax, False, digitsUsed), ! 'Test2, limit string.'); Assert.AreEqual( ! HexInt2CountMax, ! digitsUsed, ! 'Test2 digit count.'); Assert.AreEqual( ! HexInt2Value, ! StringUtils.HexToInt(HexInt2InputLeads, HexInt2CountMax, True, digitsUsed), ! 'Test2, limit string, ignore leading zeroes.'); Assert.AreEqual( ! HexInt2CountLeads, ! digitsUsed, ! 'Test2 digit count, ignoring leading zeroes.'); Assert.AreEqual( ! HexInt3Value, ! StringUtils.HexToInt(HexInt3Input), ! 'Test3, complete string'); Assert.AreEqual( ! HexInt3Value, ! StringUtils.HexToInt(HexInt3InputMax, HexInt3CountMax, False, digitsUsed), ! 'Test3, limit string.'); Assert.AreEqual( ! HexInt3CountMax, ! digitsUsed, ! 'Test3 digit count.'); Assert.AreEqual( ! HexInt3Value, ! StringUtils.HexToInt(HexInt3InputLeads, HexInt3CountMax, True, digitsUsed), ! 'Test3, limit string, ignore leading zeroes.'); Assert.AreEqual( ! HexInt3CountLeads, ! digitsUsed, ! 'Test3 digit count, ignoring leading zeroes.'); end; procedure NumericConversions.IntToHex; begin ! Assert.AreEqual(IntHex1Output, StringUtils.IntToHex(IntHex1Input), 'Test1, shortest.'); ! Assert.AreEqual(IntHex1OutputByte, StringUtils.IntToHex(IntHex1Input, True), 'Test1, shortest byte size.'); ! Assert.AreEqual(IntHex1OutputFixed, StringUtils.IntToHex(IntHex1Input, 8), 'Test1, fixed byte size.'); ! Assert.AreEqual(IntHex2Output, StringUtils.IntToHex(IntHex2Input), 'Test2, shortest.'); ! Assert.AreEqual(IntHex2OutputByte, StringUtils.IntToHex(IntHex2Input, True), 'Test2, shortest byte size.'); ! Assert.AreEqual(IntHex2OutputFixed, StringUtils.IntToHex(IntHex2Input, 8), 'Test2, fixed byte size.'); ! Assert.AreEqual(IntHex3Output, StringUtils.IntToHex(IntHex3Input), 'Test3, shortest.'); ! Assert.AreEqual(IntHex3OutputByte, StringUtils.IntToHex(IntHex3Input, True), 'Test3, shortest byte size.'); ! Assert.AreEqual(IntHex3OutputFixed, StringUtils.IntToHex(IntHex3Input, 8), 'Test3, fixed byte size.'); end; {$ENDREGION} --- 295,470 ---- {$REGION 'NumericConversions'} ! procedure NumericConversions.BinToInt; var + maxDigits: Integer; digitsUsed: Integer; begin ! Assert.AreEqual(IntByteSize1, StringUtils.BinToInt(IntByteSize1BinShortest), 'IntByteSize1 shortest'); ! Assert.AreEqual(IntByteSize1, StringUtils.BinToInt(IntByteSize1Bin), 'IntByteSize1'); ! Assert.AreEqual(IntByteSize2, StringUtils.BinToInt(IntByteSize2BinShortest), 'IntByteSize2 shortest'); ! Assert.AreEqual(IntByteSize2, StringUtils.BinToInt(IntByteSize2Bin), 'IntByteSize2'); + Assert.AreEqual(IntWordSize1, StringUtils.BinToInt(IntWordSize1BinShortest), 'IntWordSize1 shortest'); + Assert.AreEqual(IntWordSize1, StringUtils.BinToInt(IntWordSize1Bin), 'IntWordSize1'); + Assert.AreEqual(IntWordSize2, StringUtils.BinToInt(IntWordSize2BinShortest), 'IntWordSize2 shortest'); + Assert.AreEqual(IntWordSize2, StringUtils.BinToInt(IntWordSize2Bin), 'IntWordSize2'); + + Assert.AreEqual(IntLongSize1, StringUtils.BinToInt(IntLongSize1BinShortest), 'IntLongSize1 shortest'); + Assert.AreEqual(IntLongSize1, StringUtils.BinToInt(IntLongSize1Bin), 'IntLongSize1'); + Assert.AreEqual(IntLongSize2, StringUtils.BinToInt(IntLongSize2BinShortest), 'IntLongSize2 shortest'); + Assert.AreEqual(IntLongSize2, StringUtils.BinToInt(IntLongSize2Bin), 'IntLongSize2'); + + maxDigits := IntByteSize2BinShortest.Length; Assert.AreEqual( ! IntByteSize2, ! StringUtils.BinToInt(IntByteSize2BinShortest + '1', maxDigits, False, digitsUsed), ! 'IntByteSize1 limited conversion'); ! Assert.AreEqual(maxDigits, digitsUsed, 'IntByteSize2 limited digits used'); ! Assert.AreEqual( ! IntByteSize2, ! StringUtils.BinToInt('000' + IntByteSize2BinShortest + '1', maxDigits, True, digitsUsed), ! 'IntByteSize2 limited (ignore leading zeroes) conversion'); ! Assert.AreEqual(maxDigits + 3, digitsUsed, 'IntByteSize2 limited (ignore leading zeroes) digits used'); ! Assert.AreEqual( ! IntByteSize2, ! StringUtils.BinToInt(IntByteSize2BinShortest + '2', digitsUsed), ! 'IntByteSize2 invalid character conversion'); ! Assert.AreEqual(maxDigits, digitsUsed, 'IntByteSize2 invalid character digits used'); ! end; ! ! procedure NumericConversions.HexToInt; ! var ! maxDigits: Integer; ! digitsUsed: Integer; ! begin ! Assert.AreEqual(IntByteSize1, StringUtils.HexToInt(IntByteSize1HexShortest), 'IntByteSize1 shortest'); ! Assert.AreEqual(IntByteSize1, StringUtils.HexToInt(IntByteSize1Hex), 'IntByteSize1'); ! Assert.AreEqual(IntByteSize2, StringUtils.HexToInt(IntByteSize2HexShortest), 'IntByteSize2 shortest'); ! Assert.AreEqual(IntByteSize2, StringUtils.HexToInt(IntByteSize2Hex), 'IntByteSize2'); ! ! Assert.AreEqual(IntWordSize1, StringUtils.HexToInt(IntWordSize1HexShortest), 'IntWordSize1 shortest'); ! Assert.AreEqual(IntWordSize1, StringUtils.HexToInt(IntWordSize1Hex), 'IntWordSize1'); ! Assert.AreEqual(IntWordSize2, StringUtils.HexToInt(IntWordSize2HexShortest), 'IntWordSize2 shortest'); ! Assert.AreEqual(IntWordSize2, StringUtils.HexToInt(IntWordSize2Hex), 'IntWordSize2'); ! ! Assert.AreEqual(IntLongSize1, StringUtils.HexToInt(IntLongSize1HexShortest), 'IntLongSize1 shortest'); ! Assert.AreEqual(IntLongSize1, StringUtils.HexToInt(IntLongSize1Hex), 'IntLongSize1'); ! Assert.AreEqual(IntLongSize2, StringUtils.HexToInt(IntLongSize2HexShortest), 'IntLongSize2 shortest'); ! Assert.AreEqual(IntLongSize2, StringUtils.HexToInt(IntLongSize2Hex), 'IntLongSize2'); ! ! maxDigits := IntByteSize2HexShortest.Length; Assert.AreEqual( ! IntByteSize2, ! StringUtils.HexToInt(IntByteSize2HexShortest + 'f', maxDigits, False, digitsUsed), ! 'IntByteSize1 limited conversion'); ! Assert.AreEqual(maxDigits, digitsUsed, 'IntByteSize2 limited digits used'); Assert.AreEqual( ! IntByteSize2, ! StringUtils.HexToInt('000' + IntByteSize2HexShortest + 'F', maxDigits, True, digitsUsed), ! 'IntByteSize2 limited (ignore leading zeroes) conversion'); ! Assert.AreEqual(maxDigits + 3, digitsUsed, 'IntByteSize2 limited (ignore leading zeroes) digits used'); ! Assert.AreEqual( ! IntByteSize2, ! StringUtils.HexToInt(IntByteSize2HexShortest + 'g', digitsUsed), ! 'IntByteSize2 invalid character conversion'); ! Assert.AreEqual(maxDigits, digitsUsed, 'IntByteSize2 invalid character digits used'); ! end; ! ! procedure NumericConversions.OctToInt; ! var ! maxDigits: Integer; ! digitsUsed: Integer; ! begin ! Assert.AreEqual(IntByteSize1, StringUtils.OctToInt(IntByteSize1OctShortest), 'IntByteSize1 shortest'); ! Assert.AreEqual(IntByteSize1, StringUtils.OctToInt(IntByteSize1Oct), 'IntByteSize1'); ! Assert.AreEqual(IntByteSize2, StringUtils.OctToInt(IntByteSize2OctShortest), 'IntByteSize2 shortest'); ! Assert.AreEqual(IntByteSize2, StringUtils.OctToInt(IntByteSize2Oct), 'IntByteSize2'); ! ! Assert.AreEqual(IntWordSize1, StringUtils.OctToInt(IntWordSize1OctShortest), 'IntWordSize1 shortest'); ! Assert.AreEqual(IntWordSize1, StringUtils.OctToInt(IntWordSize1Oct), 'IntWordSize1'); ! Assert.AreEqual(IntWordSize2, StringUtils.OctToInt(IntWordSize2OctShortest), 'IntWordSize2 shortest'); ! Assert.AreEqual(IntWordSize2, StringUtils.OctToInt(IntWordSize2Oct), 'IntWordSize2'); ! ! Assert.AreEqual(IntLongSize1, StringUtils.OctToInt(IntLongSize1OctShortest), 'IntLongSize1 shortest'); ! Assert.AreEqual(IntLongSize1, StringUtils.OctToInt(IntLongSize1Oct), 'IntLongSize1'); ! Assert.AreEqual(IntLongSize2, StringUtils.OctToInt(IntLongSize2OctShortest), 'IntLongSize2 shortest'); ! Assert.AreEqual(IntLongSize2, StringUtils.OctToInt(IntLongSize2Oct), 'IntLongSize2'); ! ! maxDigits := IntByteSize2OctShortest.Length; Assert.AreEqual( ! IntByteSize2, ! StringUtils.OctToInt(IntByteSize2OctShortest + '7', maxDigits, False, digitsUsed), ! 'IntByteSize1 limited conversion'); ! Assert.AreEqual(maxDigits, digitsUsed, 'IntByteSize2 limited digits used'); ! Assert.AreEqual( ! IntByteSize2, ! StringUtils.OctToInt('000' + IntByteSize2OctShortest + '7', maxDigits, True, digitsUsed), ! 'IntByteSize2 limited (ignore leading zeroes) conversion'); ! Assert.AreEqual(maxDigits + 3, digitsUsed, 'IntByteSize2 limited (ignore leading zeroes) digits used'); ! Assert.AreEqual( ! IntByteSize2, ! StringUtils.OctToInt(IntByteSize2OctShortest + '8', digitsUsed), ! 'IntByteSize2 invalid character conversion'); ! Assert.AreEqual(maxDigits, digitsUsed, 'IntByteSize2 invalid character digits used'); ! end; ! ! procedure NumericConversions.IntToBin; ! begin ! Assert.AreEqual(IntByteSize1BinShortest, StringUtils.IntToBin(IntByteSize1), 'IntByteSize1 shortest'); ! Assert.AreEqual(IntByteSize1Bin, StringUtils.IntToBin(IntByteSize1, True), 'IntByteSize1'); ! Assert.AreEqual(IntByteSize2BinShortest, StringUtils.IntToBin(IntByteSize2), 'IntByteSize2 shortest'); ! Assert.AreEqual(IntByteSize2Bin, StringUtils.IntToBin(IntByteSize2, True), 'IntByteSize2'); ! ! Assert.AreEqual(IntWordSize1BinShortest, StringUtils.IntToBin(IntWordSize1), 'IntWordSize1 shortest'); ! Assert.AreEqual(IntWordSize1Bin, StringUtils.IntToBin(IntWordSize1, True), 'IntWordSize1'); ! Assert.AreEqual(IntWordSize2BinShortest, StringUtils.IntToBin(IntWordSize2), 'IntWordSize2 shortest'); ! Assert.AreEqual(IntWordSize2Bin, StringUtils.IntToBin(IntWordSize2, True), 'IntWordSize2'); ! ! Assert.AreEqual(IntLongSize1BinShortest, StringUtils.IntToBin(IntLongSize1), 'IntLongSize1 shortest'); ! Assert.AreEqual(IntLongSize1Bin, StringUtils.IntToBin(IntLongSize1, True), 'IntLongSize1'); ! Assert.AreEqual(IntLongSize2BinShortest, StringUtils.IntToBin(IntLongSize2), 'IntLongSize2 shortest'); ! Assert.AreEqual(IntLongSize2Bin, StringUtils.IntToBin(IntLongSize2, True), 'IntLongSize2'); end; procedure NumericConversions.IntToHex; begin ! Assert.AreEqual(IntByteSize1HexShortest, StringUtils.IntToHex(IntByteSize1), 'IntByteSize1 shortest'); ! Assert.AreEqual(IntByteSize1Hex, StringUtils.IntToHex(IntByteSize1, True), 'IntByteSize1'); ! Assert.AreEqual(IntByteSize2HexShortest, StringUtils.IntToHex(IntByteSize2), 'IntByteSize2 shortest'); ! Assert.AreEqual(IntByteSize2Hex, StringUtils.IntToHex(IntByteSize2, True), 'IntByteSize2'); ! ! Assert.AreEqual(IntWordSize1HexShortest, StringUtils.IntToHex(IntWordSize1), 'IntWordSize1 shortest'); ! Assert.AreEqual(IntWordSize1Hex, StringUtils.IntToHex(IntWordSize1, True), 'IntWordSize1'); ! Assert.AreEqual(IntWordSize2HexShortest, StringUtils.IntToHex(IntWordSize2), 'IntWordSize2 shortest'); ! Assert.AreEqual(IntWordSize2Hex, StringUtils.IntToHex(IntWordSize2, True), 'IntWordSize2'); ! ! Assert.AreEqual(IntLongSize1HexShortest, StringUtils.IntToHex(IntLongSize1), 'IntLongSize1 shortest'); ! Assert.AreEqual(IntLongSize1Hex, StringUtils.IntToHex(IntLongSize1, True), 'IntLongSize1'); ! Assert.AreEqual(IntLongSize2HexShortest, StringUtils.IntToHex(IntLongSize2), 'IntLongSize2 shortest'); ! Assert.AreEqual(IntLongSize2Hex, StringUtils.IntToHex(IntLongSize2, True), 'IntLongSize2'); ! end; ! ! procedure NumericConversions.IntToOct; ! begin ! Assert.AreEqual(IntByteSize1OctShortest, StringUtils.IntToOct(IntByteSize1), 'IntByteSize1 shortest'); ! Assert.AreEqual(IntByteSize1Oct, StringUtils.IntToOct(IntByteSize1, True), 'IntByteSize1'); ! Assert.AreEqual(IntByteSize2OctShortest, StringUtils.IntToOct(IntByteSize2), 'IntByteSize2 shortest'); ! Assert.AreEqual(IntByteSize2Oct, StringUtils.IntToOct(IntByteSize2, True), 'IntByteSize2'); ! ! Assert.AreEqual(IntWordSize1OctShortest, StringUtils.IntToOct(IntWordSize1), 'IntWordSize1 shortest'); ! Assert.AreEqual(IntWordSize1Oct, StringUtils.IntToOct(IntWordSize1, True), 'IntWordSize1'); ! Assert.AreEqual(IntWordSize2OctShortest, StringUtils.IntToOct(IntWordSize2), 'IntWordSize2 shortest'); ! Assert.AreEqual(IntWordSize2Oct, StringUtils.IntToOct(IntWordSize2, True), 'IntWordSize2'); ! ! Assert.AreEqual(IntLongSize1OctShortest, StringUtils.IntToOct(IntLongSize1), 'IntLongSize1 shortest'); ! Assert.AreEqual(IntLongSize1Oct, StringUtils.IntToOct(IntLongSize1, True), 'IntLongSize1'); ! Assert.AreEqual(IntLongSize2OctShortest, StringUtils.IntToOct(IntLongSize2), 'IntLongSize2 shortest'); ! Assert.AreEqual(IntLongSize2Oct, StringUtils.IntToOct(IntLongSize2, True), 'IntLongSize2'); end; {$ENDREGION} |