/
TestRawShapeBox2DConverter.pas
122 lines (102 loc) · 3.43 KB
/
TestRawShapeBox2DConverter.pas
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
115
116
117
118
119
120
121
unit TestRawShapeBox2DConverter;
{
Delphi DUnit Test Case
----------------------
This unit contains a skeleton test case class generated by the Test Case Wizard.
Modify the generated code to correctly setup and call the methods from the unit
being tested.
}
interface
uses
TestFramework, System.SysUtils, uSoTypes, uRawShapes, uRawShapeBaseConverter,
System.Math,
uGeometryClasses, UPhysics2D, uRawShapeBox2DConverter, uTestRawShapesHelpers;
type
// Test methods for class TRawShapeBox2DShapeConverter
TestTRawShapeBox2DShapeConverter = class(TTestCase)
strict private
FRawShapeBox2DShapeConverter: TRawShapeBox2DShapeConverter;
public
procedure SetUp; override;
procedure TearDown; override;
published
procedure TestConvertFromCircle;
procedure TestConvertFromPoly;
procedure TestConvertToCircle;
procedure TestConvertToPoly;
end;
implementation
procedure TestTRawShapeBox2DShapeConverter.SetUp;
begin
FRawShapeBox2DShapeConverter := TRawShapeBox2DShapeConverter.Create;
end;
procedure TestTRawShapeBox2DShapeConverter.TearDown;
begin
FRawShapeBox2DShapeConverter.Free;
FRawShapeBox2DShapeConverter := nil;
end;
procedure TestTRawShapeBox2DShapeConverter.TestConvertFromCircle;
var
ReturnValue: TRawShape;
AObject: Tb2Shape;
begin
AObject := TTestShapesHelpers.CreateBox2DCircle(78, -0, 3);
ReturnValue := FRawShapeBox2DShapeConverter.ConvertFrom(AObject);
Check(
ReturnValue.IsEqualTo(TTestShapesHelpers.CreateRawCircle(78, -0, 3)),
'Converting from Box2D to TRawShape is working wrong'
);
end;
procedure TestTRawShapeBox2DShapeConverter.TestConvertFromPoly;
var
ReturnValue: TRawShape;
AObject: Tb2Shape;
begin
AObject := TTestShapesHelpers.CreateBox2DPoly([23.0, 45.0, -5.0, -10.0, -100.0, -100.0, -100.0, 400.0, 50.0, 50.0]);
ReturnValue := FRawShapeBox2DShapeConverter.ConvertFrom(AObject);
Check(
ReturnValue.IsEqualTo(
TTestShapesHelpers.CreateRawPoly([23.0, 45.0, -5.0, -10.0, -100.0, -100.0, -100.0, 400.0, 50.0, 50.0])),
'Converting from Box2D to TRawPoly is working wrong'
);
end;
procedure TestTRawShapeBox2DShapeConverter.TestConvertToCircle;
var
ReturnValue: Tb2Shape;
AShape: TRawShape;
begin
AShape := TTestShapesHelpers.CreateRawCircle(23, -1, 7);
ReturnValue := FRawShapeBox2DShapeConverter.ConvertTo(AShape);
Check(
(ReturnValue.m_radius = 7) and
(SameValue(Tb2CircleShape(ReturnValue).m_p.x, 23)) and
(SameValue(Tb2CircleShape(ReturnValue).m_p.y, -1)) and
(ReturnValue.ClassType = Tb2CircleShape),
'Convert to Box2D Circle works incorrect'
);
end;
procedure TestTRawShapeBox2DShapeConverter.TestConvertToPoly;
var
ReturnValue: Tb2Shape;
AShape: TRawShape;
i: Integer;
vArr: TArray<TPointF>;
begin
AShape := TTestShapesHelpers.CreateRawPoly([23, 23, -23, 7, -45, -45, 60, -100]);
ReturnValue := FRawShapeBox2DShapeConverter.ConvertTo(AShape);
SetLength(vArr, Tb2PolygonShape(ReturnValue).m_count);
for i := 0 to Tb2PolygonShape(ReturnValue).m_count - 1 do
begin
vArr[i].X := Tb2PolygonShape(ReturnValue).m_vertices[i].x;
vArr[i].Y := Tb2PolygonShape(ReturnValue).m_vertices[i].y;
end;
Check(
TTestShapesHelpers.IsPointArrayEquals(vArr, AShape.GetData) and
(ReturnValue.ClassType = Tb2PolygonShape),
'Convert RawShape to Box2DPolygon works incorrect'
);
end;
initialization
// Register any test cases with the test runner
RegisterTest(TestTRawShapeBox2DShapeConverter.Suite);
end.