1.4 Resolution value type
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -51,7 +51,7 @@ Each type lives in `src/FrameProcessor/Domain/`. Tests in `tests/FrameProcessor.
|
|||||||
- `enum { Landscape, Portrait }`.
|
- `enum { Landscape, Portrait }`.
|
||||||
- JSON converter reading/writing kebab-case lowercase.
|
- JSON converter reading/writing kebab-case lowercase.
|
||||||
|
|
||||||
### [ ] 1.4 `Resolution`
|
### [x] 1.4 `Resolution`
|
||||||
- `record(int Width, int Height)`.
|
- `record(int Width, int Height)`.
|
||||||
- `Resolution ForOrientation(Orientation o)` — swaps when portrait.
|
- `Resolution ForOrientation(Orientation o)` — swaps when portrait.
|
||||||
|
|
||||||
|
|||||||
11
src/FrameProcessor/Domain/Resolution.cs
Normal file
11
src/FrameProcessor/Domain/Resolution.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
namespace FrameProcessor.Domain;
|
||||||
|
|
||||||
|
public sealed record Resolution(int Width, int Height)
|
||||||
|
{
|
||||||
|
public Resolution ForOrientation(Orientation orientation) => orientation switch
|
||||||
|
{
|
||||||
|
Orientation.Landscape => this,
|
||||||
|
Orientation.Portrait => new Resolution(Height, Width),
|
||||||
|
_ => throw new ArgumentOutOfRangeException(nameof(orientation), orientation, null),
|
||||||
|
};
|
||||||
|
}
|
||||||
44
tests/FrameProcessor.Tests/ResolutionTests.cs
Normal file
44
tests/FrameProcessor.Tests/ResolutionTests.cs
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
using FrameProcessor.Domain;
|
||||||
|
|
||||||
|
namespace FrameProcessor.Tests;
|
||||||
|
|
||||||
|
public class ResolutionTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void Constructor_StoresWidthAndHeight()
|
||||||
|
{
|
||||||
|
var resolution = new Resolution(1600, 1200);
|
||||||
|
|
||||||
|
Assert.Equal(1600, resolution.Width);
|
||||||
|
Assert.Equal(1200, resolution.Height);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ForOrientation_Landscape_ReturnsSameDimensions()
|
||||||
|
{
|
||||||
|
var resolution = new Resolution(1600, 1200);
|
||||||
|
|
||||||
|
var oriented = resolution.ForOrientation(Orientation.Landscape);
|
||||||
|
|
||||||
|
Assert.Equal(1600, oriented.Width);
|
||||||
|
Assert.Equal(1200, oriented.Height);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ForOrientation_Portrait_SwapsWidthAndHeight()
|
||||||
|
{
|
||||||
|
var resolution = new Resolution(1600, 1200);
|
||||||
|
|
||||||
|
var oriented = resolution.ForOrientation(Orientation.Portrait);
|
||||||
|
|
||||||
|
Assert.Equal(1200, oriented.Width);
|
||||||
|
Assert.Equal(1600, oriented.Height);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Equality_BasedOnWidthAndHeight()
|
||||||
|
{
|
||||||
|
Assert.Equal(new Resolution(1600, 1200), new Resolution(1600, 1200));
|
||||||
|
Assert.NotEqual(new Resolution(1600, 1200), new Resolution(1200, 1600));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user