2022-07-13 13:18:12 +00:00
|
|
|
|
using System;
|
2022-05-08 18:29:59 +00:00
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using X10D.Unity.Drawing;
|
|
|
|
|
|
|
|
|
|
namespace X10D.Unity.Tests.Drawing
|
|
|
|
|
{
|
|
|
|
|
public class ColorTests
|
|
|
|
|
{
|
2022-05-09 08:51:37 +00:00
|
|
|
|
private static readonly Color Black = new(0, 0, 0);
|
|
|
|
|
private static readonly Color White = new(1, 1, 1);
|
|
|
|
|
private static readonly Color Red = new(1, 0, 0);
|
|
|
|
|
private static readonly Color Green = new(0, 1, 0);
|
|
|
|
|
private static readonly Color Blue = new(0, 0, 1);
|
|
|
|
|
private static readonly Color Cyan = new(0, 1, 1);
|
|
|
|
|
private static readonly Color Magenta = new(1, 0, 1);
|
|
|
|
|
private static readonly Color Yellow = new(1, 1, 0);
|
|
|
|
|
|
2023-04-05 18:18:06 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void Deconstruct_ShouldDeconstruct_ToCorrectValues()
|
2023-02-27 13:55:06 +00:00
|
|
|
|
{
|
|
|
|
|
float a, r, g, b;
|
|
|
|
|
|
|
|
|
|
(r, g, b) = White;
|
2023-04-05 21:51:04 +00:00
|
|
|
|
Assert.That(r, Is.EqualTo(1.0f));
|
|
|
|
|
Assert.That(g, Is.EqualTo(1.0f));
|
|
|
|
|
Assert.That(b, Is.EqualTo(1.0f));
|
2023-02-27 13:55:06 +00:00
|
|
|
|
|
|
|
|
|
(a, r, g, b) = Yellow;
|
2023-04-05 21:51:04 +00:00
|
|
|
|
Assert.That(a, Is.EqualTo(1.0f));
|
|
|
|
|
Assert.That(r, Is.EqualTo(1.0f));
|
|
|
|
|
Assert.That(g, Is.EqualTo(1.0f));
|
|
|
|
|
Assert.That(b, Is.EqualTo(0.0f));
|
2023-02-27 13:55:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-05 18:18:06 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void GetClosestConsoleColor_ShouldReturnClosestColor_GivenValidColor()
|
2022-07-13 13:18:12 +00:00
|
|
|
|
{
|
2023-04-05 21:51:04 +00:00
|
|
|
|
Assert.That(Color.red.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Red));
|
|
|
|
|
Assert.That(Color.green.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Green));
|
|
|
|
|
Assert.That(Color.blue.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Blue));
|
|
|
|
|
Assert.That(Color.white.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.White));
|
|
|
|
|
Assert.That(Color.black.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Black));
|
|
|
|
|
Assert.That(Color.yellow.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Yellow));
|
|
|
|
|
Assert.That(Color.cyan.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Cyan));
|
|
|
|
|
Assert.That(Color.magenta.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Magenta));
|
|
|
|
|
Assert.That(Color.gray.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Gray));
|
|
|
|
|
Assert.That(Color.grey.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Gray));
|
|
|
|
|
Assert.That(Color.clear.GetClosestConsoleColor(), Is.EqualTo(ConsoleColor.Black));
|
2022-07-13 13:18:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-05 18:18:06 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void Inverted_ShouldReturnInvertedColor()
|
2022-05-08 18:29:59 +00:00
|
|
|
|
{
|
2023-04-05 21:51:04 +00:00
|
|
|
|
Assert.That(Black.Inverted(), Is.EqualTo(White));
|
|
|
|
|
Assert.That(White.Inverted(), Is.EqualTo(Black));
|
|
|
|
|
Assert.That(Cyan.Inverted(), Is.EqualTo(Red));
|
|
|
|
|
Assert.That(Red.Inverted(), Is.EqualTo(Cyan));
|
|
|
|
|
Assert.That(Magenta.Inverted(), Is.EqualTo(Green));
|
|
|
|
|
Assert.That(Green.Inverted(), Is.EqualTo(Magenta));
|
|
|
|
|
Assert.That(Blue.Inverted(), Is.EqualTo(Yellow));
|
|
|
|
|
Assert.That(Yellow.Inverted(), Is.EqualTo(Blue));
|
2022-05-08 18:29:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-05 18:18:06 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void Inverted_ShouldIgnoreAlpha()
|
2022-05-08 18:29:59 +00:00
|
|
|
|
{
|
|
|
|
|
var expected = new Color(0, 0, 0, 1);
|
|
|
|
|
var actual = new Color(1, 1, 1, 1).Inverted();
|
|
|
|
|
|
2023-04-05 21:51:04 +00:00
|
|
|
|
Assert.That(actual, Is.EqualTo(expected));
|
2022-05-08 18:29:59 +00:00
|
|
|
|
}
|
2022-05-09 09:01:03 +00:00
|
|
|
|
|
2023-04-05 18:18:06 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void ToSystemDrawingColor_ShouldReturnEquivalentColor()
|
2022-05-16 09:41:53 +00:00
|
|
|
|
{
|
|
|
|
|
System.Drawing.Color expected = System.Drawing.Color.FromArgb(255, 255, 255);
|
|
|
|
|
System.Drawing.Color actual = White.ToSystemDrawingColor();
|
|
|
|
|
|
2023-04-05 21:51:04 +00:00
|
|
|
|
Assert.That(actual, Is.EqualTo(expected));
|
2022-05-16 09:41:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-05 18:18:06 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void ToUnityColor_ShouldReturnEquivalentColor()
|
2022-05-16 09:41:53 +00:00
|
|
|
|
{
|
|
|
|
|
Color expected = White;
|
|
|
|
|
Color actual = System.Drawing.Color.FromArgb(255, 255, 255).ToUnityColor();
|
|
|
|
|
|
2023-04-05 21:51:04 +00:00
|
|
|
|
Assert.That(actual, Is.EqualTo(expected));
|
2022-05-16 09:41:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-05 18:18:06 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void WithA0_ShouldReturnSameColor_GivenWhite()
|
2022-05-09 09:01:03 +00:00
|
|
|
|
{
|
|
|
|
|
var transparent = new Color(1, 1, 1, 0);
|
2023-04-05 21:51:04 +00:00
|
|
|
|
Assert.That(White.WithA(0), Is.EqualTo(transparent));
|
|
|
|
|
Assert.That(transparent.WithA(0), Is.EqualTo(transparent));
|
2022-05-09 09:01:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-05 18:18:06 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void WithB0_ShouldReturnYellow_GivenWhite()
|
2022-05-09 09:01:03 +00:00
|
|
|
|
{
|
2023-04-05 21:51:04 +00:00
|
|
|
|
Assert.That(White.WithB(0), Is.EqualTo(Yellow));
|
|
|
|
|
Assert.That(Yellow.WithB(0), Is.EqualTo(Yellow));
|
2022-05-09 09:01:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-05 18:18:06 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void WithG0_ShouldReturnMagenta_GivenWhite()
|
2022-05-09 09:01:03 +00:00
|
|
|
|
{
|
2023-04-05 21:51:04 +00:00
|
|
|
|
Assert.That(White.WithG(0), Is.EqualTo(Magenta));
|
|
|
|
|
Assert.That(Magenta.WithG(0), Is.EqualTo(Magenta));
|
2022-05-09 09:01:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-05 18:18:06 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void WithR0_ShouldReturnCyan_GivenWhite()
|
2022-05-09 09:01:03 +00:00
|
|
|
|
{
|
2023-04-05 21:51:04 +00:00
|
|
|
|
Assert.That(White.WithR(0), Is.EqualTo(Cyan));
|
|
|
|
|
Assert.That(Cyan.WithR(0), Is.EqualTo(Cyan));
|
2022-05-09 09:01:03 +00:00
|
|
|
|
}
|
2022-05-08 18:29:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|