1
0
mirror of synced 2024-12-23 01:33:08 +01:00
x2utils/UnitTests/Units/BitsTest.pas

93 lines
1.6 KiB
ObjectPascal
Raw Normal View History

unit BitsTest;
2004-09-20 14:01:08 +02:00
interface
uses
TestFramework;
type
TBitsTest = class(TTestCase)
published
procedure testGet();
procedure testSet();
procedure testCombine();
procedure testBitsToString();
procedure testStringToBits();
end;
implementation
uses
X2UtBits;
const
Bits = [bit1, bit2, bit4, bit7];
2004-09-20 14:01:08 +02:00
BitsValue = 150;
BitsString = '10010110';
{ TBitsTest }
procedure TBitsTest.testGet;
var
bValue: Byte;
eBits: T8Bits absolute bValue;
begin
bValue := BitsValue;
Check(eBits = Bits, 'Bits do not match the value!');
2004-09-20 14:01:08 +02:00
end;
procedure TBitsTest.testSet;
var
bValue: Byte;
eBits: T8Bits absolute bValue;
begin
eBits := Bits;
2004-09-20 14:01:08 +02:00
Check(bValue = BitsValue, 'Value does not match the bits!');
end;
procedure TBitsTest.testCombine;
var
eBits1: T8Bits;
eBits2: T8Bits;
bValue: Byte absolute eBits1;
begin
eBits1 := [bit1, bit7];
eBits2 := [bit2, bit4];
eBits1 := eBits1 + eBits2;
Check(bValue = BitsValue, 'Value does not match the bits!');
end;
procedure TBitsTest.testBitsToString;
var
eBits: T8Bits;
sValue: String;
begin
eBits := Bits;
2004-09-20 14:01:08 +02:00
sValue := BitsToString(eBits, bs8);
Check(sValue = BitsString, 'Bits do not match the string!');
end;
procedure TBitsTest.testStringToBits;
var
eBits: T8Bits;
sValue: String;
begin
sValue := BitsString;
eBits := StringToBits(sValue);
Check(eBits = Bits, 'String does not match the bits!');
2004-09-20 14:01:08 +02:00
end;
initialization
RegisterTest('Bits', TBitsTest.Suite);
2004-09-20 14:01:08 +02:00
end.