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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
|
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework.Graphics;
using MonoGame.Extended.TextureAtlases;
using Xunit;
namespace MonoGame.Extended.Tests.TextureAtlases
{
//public class TextureAtlasTests : IDisposable
//{
// private readonly TestGame _game;
// public TextureAtlasTests()
// {
// _game = new TestGame();
// }
// public void Dispose()
// {
// _game.Dispose();
// }
// [Fact]
// public void TextureAtlas_CreateRegion_Test()
// {
// using (var texture = new Texture2D(_game.GraphicsDevice, 100, 200))
// {
// var atlas = new TextureAtlas(null, texture);
// var region = atlas.CreateRegion("region0", 10, 20, 30, 40);
// Assert.Same(texture, region.Texture);
// Assert.Equal(10, region.X);
// Assert.Equal(20, region.Y);
// Assert.Equal(30, region.Width);
// Assert.Equal(40, region.Height);
// }
// }
// [Fact]
// public void TextureAtlas_GetRegionsByIndex_Test()
// {
// using (var texture = new Texture2D(_game.GraphicsDevice, 100, 200))
// {
// var atlas = new TextureAtlas(null, texture);
// var region0 = atlas.CreateRegion("region0", 10, 20, 30, 40);
// var region1 = atlas.CreateRegion("region1", 50, 60, 35, 45);
// Assert.Same(region0, atlas[0]);
// Assert.Same(region1, atlas[1]);
// Assert.Same(region0, atlas.GetRegion(0));
// Assert.Same(region1, atlas.GetRegion(1));
// }
// }
// [Fact]
// public void TextureAtlas_GetRegionsByName_Test()
// {
// using (var texture = new Texture2D(_game.GraphicsDevice, 100, 200))
// {
// var atlas = new TextureAtlas(null, texture);
// var region0 = atlas.CreateRegion("region0", 10, 20, 30, 40);
// var region1 = atlas.CreateRegion("region1", 50, 60, 35, 45);
// Assert.Same(region0, atlas["region0"]);
// Assert.Same(region1, atlas["region1"]);
// Assert.Same(region0, atlas.GetRegion("region0"));
// Assert.Same(region1, atlas.GetRegion("region1"));
// }
// }
// [Fact]
// public void TextureAtlas_RemoveRegions_Test()
// {
// using (var texture = new Texture2D(_game.GraphicsDevice, 100, 200))
// {
// var atlas = new TextureAtlas(null, texture);
// var region0 = atlas.CreateRegion("region0", 10, 20, 30, 40);
// var region1 = atlas.CreateRegion("region1", 50, 60, 35, 45);
// var region2 = atlas.CreateRegion("region2", 32, 33, 34, 35);
// Assert.Same(texture, atlas.Texture);
// Assert.Equal(3, atlas.RegionCount);
// Assert.Equal(atlas.RegionCount, atlas.Regions.Count());
// Assert.Same(region1, atlas[1]);
// atlas.RemoveRegion(1);
// Assert.Equal(2, atlas.Regions.Count());
// Assert.Same(region0, atlas[0]);
// Assert.Same(region2, atlas[1]);
// atlas.RemoveRegion("region0");
// Assert.Single(atlas.Regions);
// Assert.Same(region2, atlas[0]);
// }
// }
// [Fact]
// public void TextureAtlas_CreateRegionThatAlreadyExistsThrowsException_Test()
// {
// using (var texture = new Texture2D(_game.GraphicsDevice, 100, 200))
// {
// var atlas = new TextureAtlas(null, texture);
// atlas.CreateRegion("region0", 10, 20, 30, 40);
// Assert.Throws<InvalidOperationException>(() => atlas.CreateRegion("region0", 50, 60, 35, 45));
// }
// }
// [Fact]
// public void TextureAtlas_GetRegion_InvalidIndexThrowsException_Test()
// {
// using (var texture = new Texture2D(_game.GraphicsDevice, 100, 200))
// {
// var atlas = new TextureAtlas(null, texture);
// atlas.CreateRegion("region0", 10, 20, 30, 40);
// Assert.Throws<IndexOutOfRangeException>(() => atlas.GetRegion(-1));
// }
// }
// [Fact]
// public void TextureAtlas_GetRegion_InvalidNameThrowsException_Test()
// {
// using (var texture = new Texture2D(_game.GraphicsDevice, 100, 200))
// {
// var atlas = new TextureAtlas(null, texture);
// atlas.CreateRegion("region0", 10, 20, 30, 40);
// Assert.Throws<KeyNotFoundException>(() => atlas.GetRegion("region1"));
// }
// }
// [Fact]
// public void TextureAtlas_EnumerateRegions_Test()
// {
// using (var texture = new Texture2D(_game.GraphicsDevice, 100, 200))
// {
// var atlas = new TextureAtlas(null, texture);
// var regions = new TextureRegion2D[3];
// regions[0] = atlas.CreateRegion("region0", 10, 20, 30, 40);
// regions[1] = atlas.CreateRegion("region1", 50, 60, 35, 45);
// regions[2] = atlas.CreateRegion("region2", 32, 33, 34, 35);
// var index = 0;
// foreach (var region in atlas)
// {
// Assert.Same(region, regions[index]);
// index++;
// }
// }
// }
// [Fact]
// public void TextureAtlas_Create_WithDefaultParameters_Test()
// {
// using (var texture = new Texture2D(_game.GraphicsDevice, 50, 100) {Name = "testTexture"})
// {
// var atlas = TextureAtlas.Create(null, texture, 25, 50);
// Assert.Equal(4, atlas.RegionCount);
// Assert.True(atlas.Regions.All(i => i.Width == 25));
// Assert.True(atlas.Regions.All(i => i.Height == 50));
// Assert.True(atlas.Regions.All(i => ReferenceEquals(i.Texture, texture)));
// Assert.True(atlas.Regions.All(i => i.Name.StartsWith(texture.Name)));
// }
// }
// [Fact]
// public void TextureAtlas_Create_WithMaxRegionCount_Test()
// {
// using (var texture = new Texture2D(_game.GraphicsDevice, 64, 64))
// {
// var atlas = TextureAtlas.Create(null, texture, 32, 32, maxRegionCount: 3);
// Assert.Equal(3, atlas.RegionCount);
// }
// }
// [Fact]
// public void TextureAtlas_Create_WithMargin_Test()
// {
// using (var texture = new Texture2D(_game.GraphicsDevice, 24, 24))
// {
// var atlas = TextureAtlas.Create(null, texture, 10, 10, margin: 2);
// Assert.Equal(4, atlas.RegionCount);
// Assert.True(atlas.Regions.All(i => i.Width == 10 && i.Height == 10));
// Assert.Equal(2, atlas[0].X);
// Assert.Equal(2, atlas[0].Y);
// Assert.Equal(12, atlas[3].X);
// Assert.Equal(12, atlas[3].Y);
// }
// }
// [Fact]
// public void TextureAtlas_Create_WithSpacing_Test()
// {
// using (var texture = new Texture2D(_game.GraphicsDevice, 24, 24))
// {
// var atlas = TextureAtlas.Create(null, texture, 10, 10, spacing: 2);
// Assert.Equal(4, atlas.RegionCount);
// Assert.True(atlas.Regions.All(i => i.Width == 10 && i.Height == 10));
// Assert.Equal(0, atlas[0].X);
// Assert.Equal(0, atlas[0].Y);
// Assert.Equal(12, atlas[3].X);
// Assert.Equal(12, atlas[3].Y);
// }
// }
// [Fact]
// public void TextureAtlas_Create_WithMarginAndSpacing_Test()
// {
// using (var texture = new Texture2D(_game.GraphicsDevice, 28, 28))
// {
// var atlas = TextureAtlas.Create(null, texture, 10, 10, margin: 3, spacing: 2);
// Assert.Equal(4, atlas.RegionCount);
// Assert.True(atlas.Regions.All(i => i.Width == 10 && i.Height == 10));
// Assert.Equal(3, atlas[0].X);
// Assert.Equal(3, atlas[0].Y);
// Assert.Equal(15, atlas[3].X);
// Assert.Equal(15, atlas[3].Y);
// }
// }
//}
}
|