Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Color struct refactor #187

Merged
merged 9 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
66 changes: 60 additions & 6 deletions ACadSharp.Tests/ColorTests.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
using System;
using ACadSharp.Tests.Common;
using System;
using System.Drawing;
using Xunit;
using Xunit.Abstractions;

namespace ACadSharp.Tests
{
public class ColorTests
{
private ITestOutputHelper _output;

public ColorTests(ITestOutputHelper output)
{
_output = output;
}

[Fact]
public void IndexedColorProperties()
{
Assert.True(new Color(0).IsByBlock);
Assert.True(new Color(256).IsByLayer);
Assert.True(new Color(2705).IsTrueColor);
Assert.True(new Color(2706).IsTrueColor);
Assert.True(new Color(2707).IsTrueColor);
Assert.True(new Color(2708).IsTrueColor);

Assert.True(Color.FromTrueColor(2705).IsTrueColor);
Assert.True(Color.FromTrueColor(2706).IsTrueColor);
Assert.True(Color.FromTrueColor(2707).IsTrueColor);
Assert.True(Color.FromTrueColor(2708).IsTrueColor);
}

[Fact]
Expand Down Expand Up @@ -61,6 +71,50 @@ public void HandlesIndexedColors()
}
}

[Fact]
public void GetRgbTest()
{
CSMathRandom random = new CSMathRandom();

byte r = random.Next<byte>();
byte g = random.Next<byte>();
byte b = random.Next<byte>();

Color color = new Color(r, g, b);

this._output.WriteLine($"Color value: {color}");

var rgb = color.GetRgb();

Assert.Equal(r, rgb[0]);
Assert.Equal(g, rgb[1]);
Assert.Equal(b, rgb[2]);
}

[Fact]
public void ByLayerTest()
{
Color byLayer = Color.ByLayer;

this._output.WriteLine($"Color value: {byLayer}");

Assert.True(byLayer.IsByLayer);
Assert.False(byLayer.IsByBlock);
Assert.Equal(256, byLayer.Index);
}

[Fact]
public void ByBlockTest()
{
Color byBlock = Color.ByBlock;

this._output.WriteLine($"Color value: {byBlock}");

Assert.True(byBlock.IsByBlock);
Assert.False(byBlock.IsByLayer);
Assert.Equal(0, byBlock.Index);
}

private int int32FromInt24(byte[] array)
{
if (BitConverter.IsLittleEndian)
Expand Down
Loading
Loading