Skip to content
This repository was archived by the owner on Jul 3, 2025. It is now read-only.

Commit 62dcdbb

Browse files
committed
Cleanup and refactor to use fps
1 parent 14f0ebb commit 62dcdbb

40 files changed

+887
-1075
lines changed

Tilemap2Animation.Test/CommandLineOptions/FrameDelayOptionTests.cs renamed to Tilemap2Animation.Test/CommandLineOptions/FpsOptionTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@
22

33
namespace Tilemap2Animation.Test.CommandLineOptions;
44

5-
public class FrameDelayOptionTests
5+
public class FpsOptionTests
66
{
7-
private readonly FrameDelayOption _sut;
7+
private readonly FpsOption _sut;
88

9-
public FrameDelayOptionTests()
9+
public FpsOptionTests()
1010
{
11-
_sut = new FrameDelayOption();
11+
_sut = new FpsOption();
1212
}
1313

1414
[Fact]
1515
public void Option_HasCorrectName()
1616
{
1717
// Assert
18-
Assert.Equal("frame-delay", _sut.Option.Name);
18+
Assert.Equal("fps", _sut.Option.Name);
1919
}
2020

2121
[Fact]
2222
public void Option_HasCorrectAlias()
2323
{
2424
// Assert
25-
Assert.Contains("-d", _sut.Option.Aliases);
25+
Assert.Contains("-f", _sut.Option.Aliases);
2626
}
2727

2828
[Fact]

Tilemap2Animation.Test/Services/AnimationEncoderServiceTests.cs

Lines changed: 40 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,9 @@ public AnimationEncoderServiceTests()
1313
{
1414
_sut = new AnimationEncoderService();
1515
_testOutputPath = Path.Combine(Path.GetTempPath(), "test_animation.gif");
16-
16+
1717
// Ensure the test output file doesn't exist before each test
18-
if (File.Exists(_testOutputPath))
19-
{
20-
File.Delete(_testOutputPath);
21-
}
18+
if (File.Exists(_testOutputPath)) File.Delete(_testOutputPath);
2219
}
2320

2421
[Fact]
@@ -27,9 +24,9 @@ public async Task SaveAsGifAsync_WithValidFrames_CreatesGifFile()
2724
// Arrange
2825
var frames = new List<Image<Rgba32>>
2926
{
30-
new Image<Rgba32>(16, 16, new Rgba32(255, 0, 0)),
31-
new Image<Rgba32>(16, 16, new Rgba32(0, 255, 0)),
32-
new Image<Rgba32>(16, 16, new Rgba32(0, 0, 255))
27+
new(16, 16, new Rgba32(255, 0, 0)),
28+
new(16, 16, new Rgba32(0, 255, 0)),
29+
new(16, 16, new Rgba32(0, 0, 255))
3330
};
3431
var delays = new List<int> { 100, 100, 100 };
3532

@@ -45,26 +42,20 @@ public async Task SaveAsGifAsync_WithValidFrames_CreatesGifFile()
4542
finally
4643
{
4744
// Clean up
48-
foreach (var frame in frames)
49-
{
50-
frame.Dispose();
51-
}
52-
53-
if (File.Exists(_testOutputPath))
54-
{
55-
File.Delete(_testOutputPath);
56-
}
45+
foreach (var frame in frames) frame.Dispose();
46+
47+
if (File.Exists(_testOutputPath)) File.Delete(_testOutputPath);
5748
}
5849
}
59-
50+
6051
[Fact]
6152
public async Task SaveAsGifAsync_WithExistingFile_OverwritesFile()
6253
{
6354
// Arrange
6455
var frames = new List<Image<Rgba32>>
6556
{
66-
new Image<Rgba32>(16, 16, new Rgba32(255, 0, 0)),
67-
new Image<Rgba32>(16, 16, new Rgba32(0, 255, 0))
57+
new(16, 16, new Rgba32(255, 0, 0)),
58+
new(16, 16, new Rgba32(0, 255, 0))
6859
};
6960
var delays = new List<int> { 100, 100 };
7061

@@ -85,18 +76,12 @@ public async Task SaveAsGifAsync_WithExistingFile_OverwritesFile()
8576
finally
8677
{
8778
// Clean up
88-
foreach (var frame in frames)
89-
{
90-
frame.Dispose();
91-
}
92-
93-
if (File.Exists(_testOutputPath))
94-
{
95-
File.Delete(_testOutputPath);
96-
}
79+
foreach (var frame in frames) frame.Dispose();
80+
81+
if (File.Exists(_testOutputPath)) File.Delete(_testOutputPath);
9782
}
9883
}
99-
84+
10085
[Fact]
10186
public async Task SaveAsGifAsync_WithEmptyFrames_ThrowsArgumentException()
10287
{
@@ -105,12 +90,12 @@ public async Task SaveAsGifAsync_WithEmptyFrames_ThrowsArgumentException()
10590
var delays = new List<int>();
10691

10792
// Act & Assert
108-
var exception = await Assert.ThrowsAsync<ArgumentException>(() =>
93+
var exception = await Assert.ThrowsAsync<ArgumentException>(() =>
10994
_sut.SaveAsGifAsync(frames, delays, _testOutputPath));
110-
95+
11196
Assert.Contains("No frames to encode", exception.Message);
11297
}
113-
98+
11499
[Fact]
115100
public async Task SaveAsGifAsync_WithNullFrames_ThrowsArgumentException()
116101
{
@@ -119,87 +104,78 @@ public async Task SaveAsGifAsync_WithNullFrames_ThrowsArgumentException()
119104
var delays = new List<int> { 100 };
120105

121106
// Act & Assert
122-
var exception = await Assert.ThrowsAsync<ArgumentException>(() =>
107+
var exception = await Assert.ThrowsAsync<ArgumentException>(() =>
123108
_sut.SaveAsGifAsync(frames!, delays, _testOutputPath));
124-
109+
125110
Assert.Contains("No frames to encode", exception.Message);
126111
}
127-
112+
128113
[Fact]
129114
public async Task SaveAsGifAsync_WithMismatchedDelaysCount_ThrowsArgumentException()
130115
{
131116
// Arrange
132117
var frames = new List<Image<Rgba32>>
133118
{
134-
new Image<Rgba32>(16, 16, new Rgba32(255, 0, 0)),
135-
new Image<Rgba32>(16, 16, new Rgba32(0, 255, 0))
119+
new(16, 16, new Rgba32(255, 0, 0)),
120+
new(16, 16, new Rgba32(0, 255, 0))
136121
};
137122
var delays = new List<int> { 100 }; // Only one delay for two frames
138123

139124
try
140125
{
141126
// Act & Assert
142-
var exception = await Assert.ThrowsAsync<ArgumentException>(() =>
127+
var exception = await Assert.ThrowsAsync<ArgumentException>(() =>
143128
_sut.SaveAsGifAsync(frames, delays, _testOutputPath));
144-
129+
145130
Assert.Contains("Delays must match the number of frames", exception.Message);
146131
}
147132
finally
148133
{
149134
// Clean up
150-
foreach (var frame in frames)
151-
{
152-
frame.Dispose();
153-
}
135+
foreach (var frame in frames) frame.Dispose();
154136
}
155137
}
156-
138+
157139
[Fact]
158140
public async Task SaveAsGifAsync_WithNullDelays_ThrowsArgumentException()
159141
{
160142
// Arrange
161143
var frames = new List<Image<Rgba32>>
162144
{
163-
new Image<Rgba32>(16, 16, new Rgba32(255, 0, 0))
145+
new(16, 16, new Rgba32(255, 0, 0))
164146
};
165147
List<int>? delays = null;
166148

167149
try
168150
{
169151
// Act & Assert
170-
var exception = await Assert.ThrowsAsync<ArgumentException>(() =>
152+
var exception = await Assert.ThrowsAsync<ArgumentException>(() =>
171153
_sut.SaveAsGifAsync(frames, delays!, _testOutputPath));
172-
154+
173155
Assert.Contains("Delays must match the number of frames", exception.Message);
174156
}
175157
finally
176158
{
177159
// Clean up
178-
foreach (var frame in frames)
179-
{
180-
frame.Dispose();
181-
}
160+
foreach (var frame in frames) frame.Dispose();
182161
}
183162
}
184-
163+
185164
[Fact]
186165
public async Task SaveAsGifAsync_CreatesDirectoryIfNeeded()
187166
{
188167
// Arrange
189168
var frames = new List<Image<Rgba32>>
190169
{
191-
new Image<Rgba32>(16, 16, new Rgba32(255, 0, 0))
170+
new(16, 16, new Rgba32(255, 0, 0))
192171
};
193172
var delays = new List<int> { 100 };
194-
173+
195174
var nestedPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString(), "test_animation.gif");
196175
var directory = Path.GetDirectoryName(nestedPath)!;
197-
176+
198177
// Make sure directory doesn't exist
199-
if (Directory.Exists(directory))
200-
{
201-
Directory.Delete(directory, true);
202-
}
178+
if (Directory.Exists(directory)) Directory.Delete(directory, true);
203179

204180
try
205181
{
@@ -213,15 +189,9 @@ public async Task SaveAsGifAsync_CreatesDirectoryIfNeeded()
213189
finally
214190
{
215191
// Clean up
216-
foreach (var frame in frames)
217-
{
218-
frame.Dispose();
219-
}
220-
221-
if (Directory.Exists(directory))
222-
{
223-
Directory.Delete(directory, true);
224-
}
192+
foreach (var frame in frames) frame.Dispose();
193+
194+
if (Directory.Exists(directory)) Directory.Delete(directory, true);
225195
}
226196
}
227-
}
197+
}

0 commit comments

Comments
 (0)