forked from ppy/osu-framework
/
TestCasePropertyBoundaries.cs
94 lines (81 loc) · 3.37 KB
/
TestCasePropertyBoundaries.cs
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
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Testing;
using OpenTK;
namespace osu.Framework.Tests.Visual
{
[TestFixture]
[System.ComponentModel.Description("ensure validity of drawables when receiving certain values")]
public class TestCasePropertyBoundaries : TestCase
{
[BackgroundDependencyLoader]
private void load()
{
testPositiveScale();
testZeroScale();
testNegativeScale();
}
private void testPositiveScale()
{
var box = new Box
{
Size = new Vector2(100),
Scale = new Vector2(2)
};
Add(box);
AddAssert("Box is loaded", () => box.LoadState >= LoadState.Ready);
AddAssert("Box is present", () => box.IsPresent);
AddAssert("Box has valid draw matrix", () => checkDrawInfo(box.DrawInfo));
}
private void testZeroScale()
{
var box = new Box
{
Size = new Vector2(100),
Scale = new Vector2(0)
};
Add(box);
AddAssert("Box is loaded", () => box.LoadState >= LoadState.Ready);
AddAssert("Box is present", () => !box.IsPresent);
AddAssert("Box has valid draw matrix", () => checkDrawInfo(box.DrawInfo));
}
private void testNegativeScale()
{
var box = new Box
{
Size = new Vector2(100),
Scale = new Vector2(-2)
};
Add(box);
AddAssert("Box is loaded", () => box.LoadState >= LoadState.Ready);
AddAssert("Box is present", () => box.IsPresent);
AddAssert("Box has valid draw matrix", () => checkDrawInfo(box.DrawInfo));
}
private bool checkDrawInfo(DrawInfo drawInfo)
{
return checkFloat(drawInfo.Matrix.M11)
&& checkFloat(drawInfo.Matrix.M12)
&& checkFloat(drawInfo.Matrix.M13)
&& checkFloat(drawInfo.Matrix.M21)
&& checkFloat(drawInfo.Matrix.M22)
&& checkFloat(drawInfo.Matrix.M23)
&& checkFloat(drawInfo.Matrix.M31)
&& checkFloat(drawInfo.Matrix.M32)
&& checkFloat(drawInfo.Matrix.M33)
&& checkFloat(drawInfo.MatrixInverse.M11)
&& checkFloat(drawInfo.MatrixInverse.M12)
&& checkFloat(drawInfo.MatrixInverse.M13)
&& checkFloat(drawInfo.MatrixInverse.M21)
&& checkFloat(drawInfo.MatrixInverse.M22)
&& checkFloat(drawInfo.MatrixInverse.M23)
&& checkFloat(drawInfo.MatrixInverse.M31)
&& checkFloat(drawInfo.MatrixInverse.M32)
&& checkFloat(drawInfo.MatrixInverse.M33);
}
private bool checkFloat(float value) => !float.IsNaN(value) && !float.IsInfinity(value) && !float.IsNegativeInfinity(value);
}
}