File: testcastlecontrols.pas

package info (click to toggle)
castle-game-engine 6.4%2Bdfsg1-7
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 195,044 kB
  • sloc: pascal: 364,622; ansic: 8,606; java: 2,851; objc: 2,601; cpp: 1,412; xml: 851; makefile: 723; sh: 563; php: 26
file content (97 lines) | stat: -rw-r--r-- 3,274 bytes parent folder | download | duplicates (2)
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
{
  Copyright 2012-2017 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.

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

{ Test CastleControls unit. }
unit TestCastleControls;

interface

uses
  Classes, SysUtils, fpcunit, testutils, testregistry, CastleBaseTestCase;

type
  TTestCastleControls = class(TCastleBaseTestCase)
  published
    procedure TestFloatSliderRoundAndClamp;
  end;

implementation

uses CastleVectors, CastleControls;

procedure TTestCastleControls.TestFloatSliderRoundAndClamp;
const
  Epsilon = 0.001;
var
  F: TCastleFloatSlider;
begin
  F := TCastleFloatSlider.Create(nil);
  try
    F.Min := 10;
    F.Max := 20;
    F.MultipleOf := 0;
    AssertSameValue(12, F.RoundAndClamp(12), Epsilon);
    AssertSameValue(11, F.RoundAndClamp(11), Epsilon);
    AssertSameValue(10.1, F.RoundAndClamp(10.1), Epsilon);
    AssertSameValue(10.9, F.RoundAndClamp(10.9), Epsilon);
    AssertSameValue(10, F.RoundAndClamp(10), Epsilon);
    AssertSameValue(20, F.RoundAndClamp(20), Epsilon);
    AssertSameValue(10, F.RoundAndClamp(5), Epsilon);
    AssertSameValue(20, F.RoundAndClamp(25), Epsilon);

    F.Min := 10;
    F.Max := 20;
    F.MultipleOf := 3;
    AssertSameValue(12, F.RoundAndClamp(12), Epsilon);
    AssertSameValue(12, F.RoundAndClamp(11), Epsilon);
    AssertSameValue(10, F.RoundAndClamp(10.1), Epsilon);
    AssertSameValue(12, F.RoundAndClamp(10.9), Epsilon);
    AssertSameValue(10, F.RoundAndClamp(10), Epsilon);
    AssertSameValue(20, F.RoundAndClamp(20), Epsilon);
    AssertSameValue(15, F.RoundAndClamp(14), Epsilon);
    AssertSameValue(10, F.RoundAndClamp(5), Epsilon);
    AssertSameValue(20, F.RoundAndClamp(25), Epsilon);

    F.Min := 10;
    F.Max := 20;
    F.MultipleOf := -3;
    AssertSameValue(12, F.RoundAndClamp(12), Epsilon);
    AssertSameValue(12, F.RoundAndClamp(11), Epsilon);
    AssertSameValue(10, F.RoundAndClamp(10.1), Epsilon);
    AssertSameValue(12, F.RoundAndClamp(10.9), Epsilon);
    AssertSameValue(10, F.RoundAndClamp(10), Epsilon);
    AssertSameValue(20, F.RoundAndClamp(20), Epsilon);
    AssertSameValue(15, F.RoundAndClamp(14), Epsilon);
    AssertSameValue(10, F.RoundAndClamp(5), Epsilon);
    AssertSameValue(20, F.RoundAndClamp(25), Epsilon);

    F.Min := -20;
    F.Max := -10;
    F.MultipleOf := 3;
    AssertSameValue(-12, F.RoundAndClamp(-12), Epsilon);
    AssertSameValue(-12, F.RoundAndClamp(-11), Epsilon);
    AssertSameValue(-10, F.RoundAndClamp(-10.1), Epsilon);
    AssertSameValue(-12, F.RoundAndClamp(-10.9), Epsilon);
    AssertSameValue(-10, F.RoundAndClamp(-10), Epsilon);
    AssertSameValue(-20, F.RoundAndClamp(-20), Epsilon);
    AssertSameValue(-15, F.RoundAndClamp(-14), Epsilon);
    AssertSameValue(-10, F.RoundAndClamp(-5), Epsilon);
    AssertSameValue(-20, F.RoundAndClamp(-25), Epsilon);
  finally FreeAndNil(F) end;
end;

initialization
  RegisterTest(TTestCastleControls);
end.