File: testintrects.pas

package info (click to toggle)
castle-game-engine 5.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 164,776 kB
  • ctags: 30,841
  • sloc: pascal: 168,882; cpp: 1,340; objc: 730; makefile: 492; sh: 477; xml: 434; php: 1
file content (76 lines) | stat: -rw-r--r-- 1,945 bytes parent folder | download
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
{
  Copyright 2004-2014 Michalis Kamburelis.

  This file is part of "Castle Game Engine".

  "Castle Game Engine" is free software; see the file COPYING.txt,
  included in this distribution, for details about the copyright.

  "Castle Game Engine" is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

  ----------------------------------------------------------------------------
}

unit TestIntRects;

interface

uses
  Classes, SysUtils, fpcunit, testutils, testregistry;

type
  TTestIntRects = class(TTestCase)
    procedure TestIntRects;
  end;

implementation

uses CastleVectors, IntRects;

procedure TTestIntRects.TestIntRects;
const 
  R1       :TIntRect = ((2, 4), (3, 5));
  EqualToR1: TIntRect = ((2, 4), (3, 5));
  R2: TIntRect = ((2, 4), (10, 5));
  R3: TIntRect = ((2, 4), (10, 50));
  R4: TIntRect = ((2, 4), (10, 6));
var
  R: TIntRect;
begin
 Assert(RectsEqual(R1, R1));
 Assert(RectsEqual(R1, EqualToR1));
 Assert(not RectsEqual(R1, R2));
 
 Assert(RectsEqual(IntRect(2, 4, 3, 5), R1));
 
 Assert(IntRectToNiceStr(R1) = '(2,4)-(3,5)');
 
 Assert(RectWidth(R1) = 1);
 Assert(RectHeight(R1) = 1);
 Assert(RectWidth(R2) = 8);
 Assert(RectHeight(R2) = 1);
 
 Assert(RectsEqual(IntRect(0, 2, 5, 7), GrowRect(R1, 2)));
 Assert(RectsEqual(IntRect(3, 5, 9, 49), GrowRect(R3, -1)));
 
 R := CenteredRect(R4, 4, 10);
 Assert(RectWidth(R) = 4);
 Assert(RectHeight(R) = 10);
 Assert(RectsEqual(IntRect(4, 0, 8, 10), R));
 
 Assert(PointInRect(Vector2Integer(4, 4), R4));
 Assert(PointInRect(Vector2Integer(2, 4), R4));
 Assert(not PointInRect(Vector2Integer(2, 6), R4));
 Assert(not PointInRect(Vector2Integer(2, 10), R4));
 
 Assert(PointInRect(4, 4, R4));
 Assert(PointInRect(2, 4, R4));
 Assert(not PointInRect(2, 6, R4));
 Assert(not PointInRect(2, 10, R4));
end;

initialization
 RegisterTest(TTestIntRects);
end.