Skip to content

Commit

Permalink
Merge pull request #187 from DomCR/refactor-Color-struct
Browse files Browse the repository at this point in the history
Color struct refactor
  • Loading branch information
DomCR authored Oct 26, 2023
2 parents 052746d + f8ca186 commit 1cb0c7a
Show file tree
Hide file tree
Showing 43 changed files with 12,180 additions and 1,726 deletions.
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

0 comments on commit 1cb0c7a

Please sign in to comment.