Skip to content

Commit

Permalink
Rename Channel to ChannelValue
Browse files Browse the repository at this point in the history
  • Loading branch information
ds5678 committed Mar 24, 2024
1 parent 2bb946b commit 1bf5f70
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private static void MakeGenericColorTests()
writer.WriteLine($"[TestFixture(TypeArgs = new Type[] {{ typeof({colorName}<{channeName}>), typeof({channeName}) }})]");
}
}
writer.WriteLine("partial class GenericColorTests<TColor, TChannel>");
writer.WriteLine("partial class GenericColorTests<TColor, TChannelValue>");
using (new CurlyBrackets(writer))
{
}
Expand Down Expand Up @@ -354,4 +354,4 @@ private static void WritePropertySymmetryTests(this IndentedTextWriter textWrite
textWriter.WriteLine();
}
}
}
}
6 changes: 3 additions & 3 deletions AssetRipper.TextureDecoder.Tests/Formats/ColorRandom.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using AssetRipper.TextureDecoder.Rgb;

namespace AssetRipper.TextureDecoder.Tests.Formats;
internal static class ColorRandom<TColor, TChannel> where TColor : unmanaged, IColor<TChannel> where TChannel : unmanaged
internal static class ColorRandom<TColor, TChannelValue> where TColor : unmanaged, IColor<TChannelValue> where TChannelValue : unmanaged
{
public static TChannel MakeRandomValue()
public static TChannelValue MakeRandomValue()
{
ulong value = TestContext.CurrentContext.Random.NextULong();
return NumericConversion.Convert<ulong, TChannel>(value);
return NumericConversion.Convert<ulong, TChannelValue>(value);
}

public static TColor MakeRandomColor()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@

namespace AssetRipper.TextureDecoder.Tests.Formats.Generic;

internal partial class GenericColorTests<TColor, TChannel> where TColor : unmanaged, IColor<TChannel> where TChannel : unmanaged
internal partial class GenericColorTests<TColor, TChannelValue> where TColor : unmanaged, IColor<TChannelValue> where TChannelValue : unmanaged
{
[Test]
public void CorrectSizeTest()
{
Assert.That(Unsafe.SizeOf<TColor>(), Is.EqualTo(Color.GetChannelCount<TColor>() * Unsafe.SizeOf<TChannel>()));
Assert.That(Unsafe.SizeOf<TColor>(), Is.EqualTo(Color.GetChannelCount<TColor>() * Unsafe.SizeOf<TChannelValue>()));
}

[Test]
public void PropertyIsSymmetric_R()
{
TColor color = MakeRandomColor();
TChannel r = color.R;
TChannelValue r = color.R;
color.R = r;
Assert.That(color.R, Is.EqualTo(r));
}
Expand All @@ -24,7 +24,7 @@ public void PropertyIsSymmetric_R()
public void PropertyIsSymmetric_G()
{
TColor color = MakeRandomColor();
TChannel g = color.G;
TChannelValue g = color.G;
color.G = g;
Assert.That(color.G, Is.EqualTo(g));
}
Expand All @@ -33,7 +33,7 @@ public void PropertyIsSymmetric_G()
public void PropertyIsSymmetric_B()
{
TColor color = MakeRandomColor();
TChannel b = color.B;
TChannelValue b = color.B;
color.B = b;
Assert.That(color.B, Is.EqualTo(b));
}
Expand All @@ -42,7 +42,7 @@ public void PropertyIsSymmetric_B()
public void PropertyIsSymmetric_A()
{
TColor color = MakeRandomColor();
TChannel a = color.A;
TChannelValue a = color.A;
color.A = a;
Assert.That(color.A, Is.EqualTo(a));
}
Expand All @@ -51,9 +51,9 @@ public void PropertyIsSymmetric_A()
public void ChannelsAreIndependent_R()
{
TColor color = MakeRandomColor();
TChannel g = color.G;
TChannel b = color.B;
TChannel a = color.A;
TChannelValue g = color.G;
TChannelValue b = color.B;
TChannelValue a = color.A;
color.R = MakeRandomValue();
Assert.Multiple(() =>
{
Expand All @@ -67,9 +67,9 @@ public void ChannelsAreIndependent_R()
public void ChannelsAreIndependent_G()
{
TColor color = MakeRandomColor();
TChannel r = color.R;
TChannel b = color.B;
TChannel a = color.A;
TChannelValue r = color.R;
TChannelValue b = color.B;
TChannelValue a = color.A;
color.G = MakeRandomValue();
Assert.Multiple(() =>
{
Expand All @@ -83,9 +83,9 @@ public void ChannelsAreIndependent_G()
public void ChannelsAreIndependent_B()
{
TColor color = MakeRandomColor();
TChannel r = color.R;
TChannel g = color.G;
TChannel a = color.A;
TChannelValue r = color.R;
TChannelValue g = color.G;
TChannelValue a = color.A;
color.B = MakeRandomValue();
Assert.Multiple(() =>
{
Expand All @@ -99,9 +99,9 @@ public void ChannelsAreIndependent_B()
public void ChannelsAreIndependent_A()
{
TColor color = MakeRandomColor();
TChannel r = color.R;
TChannel g = color.G;
TChannel b = color.B;
TChannelValue r = color.R;
TChannelValue g = color.G;
TChannelValue b = color.B;
color.A = MakeRandomValue();
Assert.Multiple(() =>
{
Expand All @@ -115,7 +115,7 @@ public void ChannelsAreIndependent_A()
public void GetMethodMatchesProperties()
{
TColor color = MakeRandomColor();
color.GetChannels(out TChannel r, out TChannel g, out TChannel b, out TChannel a);
color.GetChannels(out TChannelValue r, out TChannelValue g, out TChannelValue b, out TChannelValue a);
Assert.Multiple(() =>
{
Assert.That(color.R, Is.EqualTo(r));
Expand All @@ -129,7 +129,7 @@ public void GetMethodMatchesProperties()
public void MethodsAreSymmetric()
{
TColor color = MakeRandomColor();
color.GetChannels(out TChannel r, out TChannel g, out TChannel b, out TChannel a);
color.GetChannels(out TChannelValue r, out TChannelValue g, out TChannelValue b, out TChannelValue a);
color.SetChannels(r, g, b, a);
Assert.Multiple(() =>
{
Expand All @@ -140,7 +140,7 @@ public void MethodsAreSymmetric()
});
}

private static TChannel MakeRandomValue() => ColorRandom<TColor, TChannel>.MakeRandomValue();
private static TChannelValue MakeRandomValue() => ColorRandom<TColor, TChannelValue>.MakeRandomValue();

private static TColor MakeRandomColor() => ColorRandom<TColor, TChannel>.MakeRandomColor();
private static TColor MakeRandomColor() => ColorRandom<TColor, TChannelValue>.MakeRandomColor();
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,6 @@ namespace AssetRipper.TextureDecoder.Tests.Formats.Generic;
[TestFixture(TypeArgs = new Type[] { typeof(ColorRGB<decimal>), typeof(decimal) })]
[TestFixture(TypeArgs = new Type[] { typeof(ColorRGBA<decimal>), typeof(decimal) })]
[TestFixture(TypeArgs = new Type[] { typeof(ColorA<decimal>), typeof(decimal) })]
partial class GenericColorTests<TColor, TChannel>
partial class GenericColorTests<TColor, TChannelValue>
{
}
18 changes: 9 additions & 9 deletions AssetRipper.TextureDecoder.Tests/Formats/LosslessConversion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
namespace AssetRipper.TextureDecoder.Tests.Formats;
internal static class LosslessConversion
{
internal static void Assert<TColor1, TChannel1, TColor2, TChannel2>()
where TChannel1 : unmanaged
where TChannel2 : unmanaged
where TColor1 : unmanaged, IColor<TChannel1>
where TColor2 : unmanaged, IColor<TChannel2>
internal static void Assert<TColor1, TChannelValue1, TColor2, TChannelValue2>()
where TChannelValue1 : unmanaged
where TChannelValue2 : unmanaged
where TColor1 : unmanaged, IColor<TChannelValue1>
where TColor2 : unmanaged, IColor<TChannelValue2>
{
TColor1 original = ColorRandom<TColor1, TChannel1>.MakeRandomColor();
TColor2 converted = original.Convert<TColor1, TChannel1, TColor2, TChannel2>();
TColor1 convertedBack = converted.Convert<TColor2, TChannel2, TColor1, TChannel1>();
TColor1 original = ColorRandom<TColor1, TChannelValue1>.MakeRandomColor();
TColor2 converted = original.Convert<TColor1, TChannelValue1, TColor2, TChannelValue2>();
TColor1 convertedBack = converted.Convert<TColor2, TChannelValue2, TColor1, TChannelValue1>();
NUnit.Framework.Assert.That(convertedBack, Is.EqualTo(original));
}
}
}
Loading

0 comments on commit 1bf5f70

Please sign in to comment.