Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add more pixel conversion tests
  • Loading branch information
brianpopow committed May 4, 2019
commit 07670cb0d1c313d0311a3cc781f0452a23b76212
2 changes: 1 addition & 1 deletion src/ImageSharp/PixelFormats/PixelImplementations/Byte4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public void ToRgba32(ref Rgba32 dest)
public override string ToString()
{
var vector = this.ToVector4();
return FormattableString.Invariant($"Bgra5551({vector.X:#0.##}, {vector.Y:#0.##}, {vector.Z:#0.##}, {vector.W:#0.##})");
return FormattableString.Invariant($"Byte4({vector.X:#0.##}, {vector.Y:#0.##}, {vector.Z:#0.##}, {vector.W:#0.##})");
}

/// <summary>
Expand Down
62 changes: 62 additions & 0 deletions tests/ImageSharp.Tests/PixelFormats/Argb32Tests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.

using System;
using System.Numerics;
using SixLabors.ImageSharp.PixelFormats;
using Xunit;
Expand All @@ -9,6 +10,67 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
{
public class Argb32Tests
{
/// <summary>
/// Tests the equality operators for equality.
/// </summary>
[Fact]
public void AreEqual()
{
var color1 = new Argb32(0.0f, 0.0f, 0.0f, 0.0f);
var color2 = new Argb32(new Vector4(0.0f));
var color3 = new Argb32(new Vector4(1.0f, 0.0f, 1.0f, 1.0f));
var color4 = new Argb32(1.0f, 0.0f, 1.0f, 1.0f);

Assert.Equal(color1, color2);
Assert.Equal(color3, color4);
}

/// <summary>
/// Tests the equality operators for inequality.
/// </summary>
[Fact]
public void AreNotEqual()
{
var color1 = new Argb32(0.0f, 0.0f, 0.0f, 0.0f);
var color2 = new Argb32(new Vector4(1.0f));
var color3 = new Argb32(new Vector4(1.0f, 0.0f, 0.0f, 1.0f));
var color4 = new Argb32(1.0f, 1.0f, 0.0f, 1.0f);

Assert.NotEqual(color1, color2);
Assert.NotEqual(color3, color4);
}

/// <summary>
/// Tests whether the color constructor correctly assign properties.
/// </summary>
[Fact]
public void ConstructorAssignsProperties()
{
var color1 = new Argb32(1, .1f, .133f, .864f);
Assert.Equal(255, color1.R);
Assert.Equal((byte)Math.Round(.1f * 255), color1.G);
Assert.Equal((byte)Math.Round(.133f * 255), color1.B);
Assert.Equal((byte)Math.Round(.864f * 255), color1.A);

var color2 = new Argb32(1, .1f, .133f);
Assert.Equal(255, color2.R);
Assert.Equal(Math.Round(.1f * 255), color2.G);
Assert.Equal(Math.Round(.133f * 255), color2.B);
Assert.Equal(255, color2.A);

var color4 = new Argb32(new Vector3(1, .1f, .133f));
Assert.Equal(255, color4.R);
Assert.Equal(Math.Round(.1f * 255), color4.G);
Assert.Equal(Math.Round(.133f * 255), color4.B);
Assert.Equal(255, color4.A);

var color5 = new Argb32(new Vector4(1, .1f, .133f, .5f));
Assert.Equal(255, color5.R);
Assert.Equal(Math.Round(.1f * 255), color5.G);
Assert.Equal(Math.Round(.133f * 255), color5.B);
Assert.Equal(Math.Round(.5f * 255), color5.A);
}

[Fact]
public void Argb32_PackedValue()
{
Expand Down
18 changes: 18 additions & 0 deletions tests/ImageSharp.Tests/PixelFormats/Bgr24Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
{
public class Bgr24Tests
{
[Fact]
public void AreEqual()
{
var color1 = new Bgr24(byte.MaxValue, 0, byte.MaxValue);
var color2 = new Bgr24(byte.MaxValue, 0, byte.MaxValue);

Assert.Equal(color1, color2);
}

[Fact]
public void AreNotEqual()
{
var color1 = new Bgr24(byte.MaxValue, 0, 0);
var color2 = new Bgr24(byte.MaxValue, 0, byte.MaxValue);

Assert.NotEqual(color1, color2);
}

public static readonly TheoryData<byte, byte, byte> ColorData =
new TheoryData<byte, byte, byte>() { { 1, 2, 3 }, { 4, 5, 6 }, { 0, 255, 42 } };

Expand Down
1 change: 0 additions & 1 deletion tests/ImageSharp.Tests/PixelFormats/Bgr565Tests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.

using System;
using System.Numerics;
using SixLabors.ImageSharp.PixelFormats;
using Xunit;
Expand Down
25 changes: 25 additions & 0 deletions tests/ImageSharp.Tests/PixelFormats/Bgra32Tests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.

using System;
using System.Numerics;
using SixLabors.ImageSharp.PixelFormats;
using Xunit;
Expand All @@ -9,6 +10,30 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
{
public class Bgra32Tests
{
/// <summary>
/// Tests the equality operators for equality.
/// </summary>
[Fact]
public void AreEqual()
{
var color1 = new Bgra32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
var color2 = new Bgra32(byte.MaxValue, byte.MaxValue, byte.MaxValue);

Assert.Equal(color1, color2);
}

/// <summary>
/// Tests the equality operators for inequality.
/// </summary>
[Fact]
public void AreNotEqual()
{
var color1 = new Bgra32(0, 0, byte.MaxValue, byte.MaxValue);
var color2 = new Bgra32(byte.MaxValue, byte.MaxValue, byte.MaxValue);

Assert.NotEqual(color1, color2);
}

public static readonly TheoryData<byte, byte, byte, byte> ColorData =
new TheoryData<byte, byte, byte, byte>()
{
Expand Down
14 changes: 14 additions & 0 deletions tests/ImageSharp.Tests/PixelFormats/Byte4Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,20 @@ public void Byte4_ToScaledVector4()
Assert.Equal(1, actual.W);
}

[Fact]
public void Byte4_ToRgba32()
{
// arrange
var byte4 = new Byte4(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
var expected = new Rgba32(Vector4.One);
var actual = default(Rgba32);

// act
byte4.ToRgba32(ref actual);

Assert.Equal(expected, actual);
}

[Fact]
public void Byte4_FromScaledVector4()
{
Expand Down
18 changes: 18 additions & 0 deletions tests/ImageSharp.Tests/PixelFormats/Gray16Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
{
public class Gray16Tests
{
[Fact]
public void AreEqual()
{
var color1 = new Gray16(3000);
var color2 = new Gray16(3000);

Assert.Equal(color1, color2);
}

[Fact]
public void AreNotEqual()
{
var color1 = new Gray16(12345);
var color2 = new Gray16(54321);

Assert.NotEqual(color1, color2);
}

[Theory]
[InlineData(0)]
[InlineData(65535)]
Expand Down
20 changes: 18 additions & 2 deletions tests/ImageSharp.Tests/PixelFormats/Gray8Tests.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.

using System.Diagnostics;
using System.Numerics;

using SixLabors.ImageSharp.Common.Helpers;
using SixLabors.ImageSharp.PixelFormats;
using Xunit;

Expand Down Expand Up @@ -45,6 +43,24 @@ public class Gray8Tests
public void Gray8_PackedValue_EqualsInput(byte input)
=> Assert.Equal(input, new Gray8(input).PackedValue);

[Fact]
public void AreEqual()
{
var color1 = new Gray8(100);
var color2 = new Gray8(100);

Assert.Equal(color1, color2);
}

[Fact]
public void AreNotEqual()
{
var color1 = new Gray8(100);
var color2 = new Gray8(200);

Assert.NotEqual(color1, color2);
}

[Fact]
public void Gray8_FromScaledVector4()
{
Expand Down
Loading