1.6 DitherAlgorithm value type
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
57
tests/FrameProcessor.Tests/DitherAlgorithmTests.cs
Normal file
57
tests/FrameProcessor.Tests/DitherAlgorithmTests.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using System.Text.Json;
|
||||
using FrameProcessor.Domain;
|
||||
|
||||
namespace FrameProcessor.Tests;
|
||||
|
||||
public class DitherAlgorithmTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("\"floyd-steinberg\"", DitherAlgorithm.FloydSteinberg)]
|
||||
[InlineData("\"atkinson\"", DitherAlgorithm.Atkinson)]
|
||||
[InlineData("\"stucki\"", DitherAlgorithm.Stucki)]
|
||||
[InlineData("\"jarvis\"", DitherAlgorithm.Jarvis)]
|
||||
public void JsonDeserialize_KebabCaseLowercase(string json, DitherAlgorithm expected)
|
||||
{
|
||||
var value = JsonSerializer.Deserialize<DitherAlgorithm>(json);
|
||||
Assert.Equal(expected, value);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(DitherAlgorithm.FloydSteinberg, "\"floyd-steinberg\"")]
|
||||
[InlineData(DitherAlgorithm.Atkinson, "\"atkinson\"")]
|
||||
[InlineData(DitherAlgorithm.Stucki, "\"stucki\"")]
|
||||
[InlineData(DitherAlgorithm.Jarvis, "\"jarvis\"")]
|
||||
public void JsonSerialize_KebabCaseLowercase(DitherAlgorithm value, string expected)
|
||||
{
|
||||
var json = JsonSerializer.Serialize(value);
|
||||
Assert.Equal(expected, json);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("\"FloydSteinberg\"")]
|
||||
[InlineData("\"floyd_steinberg\"")]
|
||||
[InlineData("\"FLOYD-STEINBERG\"")]
|
||||
[InlineData("\"sierra\"")]
|
||||
[InlineData("\"\"")]
|
||||
public void JsonDeserialize_RejectsInvalid(string json)
|
||||
{
|
||||
Assert.Throws<JsonException>(() => JsonSerializer.Deserialize<DitherAlgorithm>(json));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonRoundTrip_PreservesValue()
|
||||
{
|
||||
foreach (var value in new[]
|
||||
{
|
||||
DitherAlgorithm.FloydSteinberg,
|
||||
DitherAlgorithm.Atkinson,
|
||||
DitherAlgorithm.Stucki,
|
||||
DitherAlgorithm.Jarvis,
|
||||
})
|
||||
{
|
||||
var json = JsonSerializer.Serialize(value);
|
||||
var roundTripped = JsonSerializer.Deserialize<DitherAlgorithm>(json);
|
||||
Assert.Equal(value, roundTripped);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user