Skip to content

Commit 1d4789b

Browse files
committed
ADD Tests
1 parent 9a491e0 commit 1d4789b

File tree

6 files changed

+219
-0
lines changed

6 files changed

+219
-0
lines changed

Tests.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tests/Editor.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
using NUnit.Framework;
2+
using UnityEngine;
3+
4+
namespace TNRD.Constraints.Tests
5+
{
6+
[TestFixture]
7+
internal class ConstrainedRectTests
8+
{
9+
private Rect rect;
10+
11+
[SetUp]
12+
public void SetUp()
13+
{
14+
rect = new Rect(0, 0, 128, 128);
15+
}
16+
17+
[Test]
18+
public void Relative()
19+
{
20+
var constrained = Constrain.To(rect)
21+
.Relative(8);
22+
23+
Assert.AreEqual(8, constrained.xMin);
24+
Assert.AreEqual(8, constrained.yMin);
25+
Assert.AreEqual(120, constrained.xMax);
26+
Assert.AreEqual(120, constrained.yMax);
27+
}
28+
29+
[Test]
30+
public void Absolute()
31+
{
32+
var constrained = Constrain.To(rect)
33+
.Left.Absolute(8)
34+
.Top.Absolute(8)
35+
.Right.Absolute(16)
36+
.Bottom.Absolute(16)
37+
.ToRect();
38+
39+
Assert.AreEqual(8, constrained.xMin);
40+
Assert.AreEqual(8, constrained.yMin);
41+
Assert.AreEqual(16, constrained.xMax);
42+
Assert.AreEqual(16, constrained.yMax);
43+
}
44+
45+
[Test]
46+
public void TopLeftRelative()
47+
{
48+
var constrained = Constrain.To(rect)
49+
.Top.Relative(8)
50+
.Left.Relative(8)
51+
.ToRect();
52+
53+
Assert.AreEqual(8, constrained.xMin);
54+
Assert.AreEqual(8, constrained.yMin);
55+
}
56+
57+
[Test]
58+
public void BottomRightRelative()
59+
{
60+
var constrained = Constrain.To(rect)
61+
.Bottom.Relative(8)
62+
.Right.Relative(8)
63+
.ToRect();
64+
65+
Assert.AreEqual(120, constrained.xMax);
66+
Assert.AreEqual(120, constrained.yMax);
67+
}
68+
69+
[Test]
70+
public void LeftWidthRelative()
71+
{
72+
var constrained = Constrain.To(rect)
73+
.Left.Relative(8)
74+
.Width.Relative(-8)
75+
.ToRect();
76+
77+
Assert.AreEqual(8, constrained.xMin);
78+
Assert.AreEqual(120, constrained.width);
79+
}
80+
81+
[Test]
82+
public void LeftWidthPercentage()
83+
{
84+
var constrained = Constrain.To(rect)
85+
.Left.Relative(8)
86+
.Width.Percentage(0.5f)
87+
.ToRect();
88+
89+
Assert.AreEqual(8, constrained.xMin);
90+
Assert.AreEqual(64, constrained.width);
91+
}
92+
93+
[Test]
94+
public void RightWidthRelative()
95+
{
96+
var constrained = Constrain.To(rect)
97+
.Right.Relative(8)
98+
.Width.Relative(-8)
99+
.ToRect();
100+
101+
Assert.AreEqual(120, constrained.xMax);
102+
Assert.AreEqual(120, constrained.width);
103+
}
104+
105+
[Test]
106+
public void RightWidthPercentage()
107+
{
108+
var constrained = Constrain.To(rect)
109+
.Right.Relative(8)
110+
.Width.Percentage(0.5f)
111+
.ToRect();
112+
113+
Assert.AreEqual(120, constrained.xMax);
114+
Assert.AreEqual(64, constrained.width);
115+
}
116+
117+
[Test]
118+
public void TopHeightRelative()
119+
{
120+
var constrained = Constrain.To(rect)
121+
.Top.Relative(8)
122+
.Height.Relative(-8)
123+
.ToRect();
124+
125+
Assert.AreEqual(8, constrained.yMin);
126+
Assert.AreEqual(120, constrained.height);
127+
}
128+
129+
[Test]
130+
public void TopHeightPercentage()
131+
{
132+
var constrained = Constrain.To(rect)
133+
.Top.Relative(8)
134+
.Height.Percentage(0.5f)
135+
.ToRect();
136+
137+
Assert.AreEqual(8, constrained.yMin);
138+
Assert.AreEqual(64, constrained.height);
139+
}
140+
141+
[Test]
142+
public void BottomHeightRelative()
143+
{
144+
var constrained = Constrain.To(rect)
145+
.Bottom.Relative(8)
146+
.Height.Relative(-8)
147+
.ToRect();
148+
149+
Assert.AreEqual(120, constrained.yMax);
150+
Assert.AreEqual(120, constrained.height);
151+
}
152+
153+
[Test]
154+
public void BottomHeightPercentage()
155+
{
156+
var constrained = Constrain.To(rect)
157+
.Bottom.Relative(8)
158+
.Height.Percentage(0.5f)
159+
.ToRect();
160+
161+
Assert.AreEqual(120, constrained.yMax);
162+
Assert.AreEqual(64, constrained.height);
163+
}
164+
}
165+
}

Tests/Editor/ConstrainedRectTests.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "Unity.ConstrainedRect.Editor.Tests",
3+
"references": [
4+
"GUID:b5a0f150547393d418a1c58e42e6b937",
5+
"GUID:0acc523941302664db1f4e527237feb3"
6+
],
7+
"includePlatforms": [
8+
"Editor"
9+
],
10+
"excludePlatforms": [],
11+
"allowUnsafeCode": false,
12+
"overrideReferences": true,
13+
"precompiledReferences": [
14+
"nunit.framework.dll"
15+
],
16+
"autoReferenced": false,
17+
"defineConstraints": [],
18+
"versionDefines": [],
19+
"noEngineReferences": false
20+
}

Tests/Editor/Unity.ConstrainedRect.Editor.Tests.asmdef.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)