Skip to content

Commit

Permalink
test: add test to color and depth color
Browse files Browse the repository at this point in the history
  • Loading branch information
pabllopf committed Jan 31, 2024
1 parent cea8e35 commit 3d58d90
Show file tree
Hide file tree
Showing 5 changed files with 230 additions and 1 deletion.
2 changes: 1 addition & 1 deletion 6_Ideation/Math/src/Definition/Color.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public struct Color
/// <param name="g">The </param>
/// <param name="b">The </param>
/// <param name="a">The </param>
private Color(byte r, byte g, byte b, byte a)
public Color(byte r, byte g, byte b, byte a)
{
R = r;
G = g;
Expand Down
29 changes: 29 additions & 0 deletions 6_Ideation/Math/src/Definition/Color.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Color Struct

## Description

The `Color` struct represents a color in RGBA color space. Each color component is represented as a byte, with values ranging from 0 to 255.

## Properties

- `R`: The red component of the color.
- `G`: The green component of the color.
- `B`: The blue component of the color.
- `A`: The alpha (transparency) component of the color.

## Constructors

- `Color(byte r, byte g, byte b, byte a)`: Initializes a new instance of the `Color` struct with the specified red, green, blue, and alpha values.
- `Color(int r, int g, int b, int a)`: Initializes a new instance of the `Color` struct with the specified red, green, blue, and alpha values. The integer values are cast to bytes.

## Static Properties

- `Black`: Represents the color black. This property is read-only.
- `Red`: Represents the color red. This property is read-only.

## Examples

Creating a new `Color` instance:

```csharp
Color color = new Color(255, 128, 64, 32);
20 changes: 20 additions & 0 deletions 6_Ideation/Math/src/Definition/Depth.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Depth Struct

## Description

The `Depth` struct represents a depth value in a 3D space. The depth is represented as an integer.

## Properties

- `Value`: The depth value.

## Constructors

- `Depth(int value)`: Initializes a new instance of the `Depth` struct with the specified depth value.

## Examples

Creating a new `Depth` instance:

```csharp
Depth depth = new Depth(10);
123 changes: 123 additions & 0 deletions 6_Ideation/Math/test/Definition/ColorTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
// --------------------------------------------------------------------------
//
// █▀▀█ ░█─── ▀█▀ ░█▀▀▀█
// ░█▄▄█ ░█─── ░█─ ─▀▀▀▄▄
// ░█─░█ ░█▄▄█ ▄█▄ ░█▄▄▄█
//
// --------------------------------------------------------------------------
// File:ColorTest.cs
//
// Author:Pablo Perdomo Falcón
// Web:https://www.pabllopf.dev/
//
// Copyright (c) 2021 GNU General Public License v3.0
//
// This program is free software:you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.If not, see <http://www.gnu.org/licenses/>.
//
// --------------------------------------------------------------------------

using Alis.Core.Aspect.Math.Definition;
using Xunit;

namespace Alis.Core.Aspect.Math.Test.Definition
{

/// <summary>
/// The color tests class
/// </summary>
public class ColorTests
{
/// <summary>
/// Tests that constructor sets properties correctly when given bytes
/// </summary>
[Fact]
public void Constructor_SetsPropertiesCorrectly_WhenGivenBytes()
{
// Arrange
const byte r = 255;
const byte g = 128;
const byte b = 64;
const byte a = 32;

// Act
Color color = new Color(r, g, b, a);

// Assert
Assert.Equal(r, color.R);
Assert.Equal(g, color.G);
Assert.Equal(b, color.B);
Assert.Equal(a, color.A);
}

/// <summary>
/// Tests that constructor sets properties correctly when given ints
/// </summary>
[Fact]
public void Constructor_SetsPropertiesCorrectly_WhenGivenInts()
{
// Arrange
const int r = 255;
const int g = 128;
const int b = 64;
const int a = 32;

// Act
Color color = new Color(r, g, b, a);

// Assert
Assert.Equal(r, color.R);
Assert.Equal(g, color.G);
Assert.Equal(b, color.B);
Assert.Equal(a, color.A);
}

/// <summary>
/// Tests that black returns correct color
/// </summary>
[Fact]
public void Black_ReturnsCorrectColor()
{
// Arrange
Color expected = new Color(0, 0, 0, 255);

// Act
Color actual = Color.Black;

// Assert
Assert.Equal(expected.R, actual.R);
Assert.Equal(expected.G, actual.G);
Assert.Equal(expected.B, actual.B);
Assert.Equal(expected.A, actual.A);
}

/// <summary>
/// Tests that red returns correct color
/// </summary>
[Fact]
public void Red_ReturnsCorrectColor()
{
// Arrange
Color expected = new Color(255, 0, 0, 255);

// Act
Color actual = Color.Red;

// Assert
Assert.Equal(expected.R, actual.R);
Assert.Equal(expected.G, actual.G);
Assert.Equal(expected.B, actual.B);
Assert.Equal(expected.A, actual.A);
}
}
}
57 changes: 57 additions & 0 deletions 6_Ideation/Math/test/Definition/DepthTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// --------------------------------------------------------------------------
//
// █▀▀█ ░█─── ▀█▀ ░█▀▀▀█
// ░█▄▄█ ░█─── ░█─ ─▀▀▀▄▄
// ░█─░█ ░█▄▄█ ▄█▄ ░█▄▄▄█
//
// --------------------------------------------------------------------------
// File:DepthTest.cs
//
// Author:Pablo Perdomo Falcón
// Web:https://www.pabllopf.dev/
//
// Copyright (c) 2021 GNU General Public License v3.0
//
// This program is free software:you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.If not, see <http://www.gnu.org/licenses/>.
//
// --------------------------------------------------------------------------

using Alis.Core.Aspect.Math.Definition;
using Xunit;

namespace Alis.Core.Aspect.Math.Test.Definition
{

/// <summary>
/// The depth tests class
/// </summary>
public class DepthTests
{
/// <summary>
/// Tests that constructor sets value correctly
/// </summary>
[Fact]
public void Constructor_SetsValueCorrectly()
{
// Arrange
const int expectedValue = 10;

// Act
Depth depth = new Depth(expectedValue);

// Assert
Assert.Equal(expectedValue, depth.Value);
}
}
}

0 comments on commit 3d58d90

Please sign in to comment.