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

New datatypes #433

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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
436 changes: 436 additions & 0 deletions PG.Commons/PG.Commons.Test/Collections/ValueListDictionaryTests.cs

Large diffs are not rendered by default.

139 changes: 139 additions & 0 deletions PG.Commons/PG.Commons.Test/Numerics/Vector2IntTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
using System;
using PG.Commons.Numerics;
using Xunit;

namespace PG.Commons.Test.Numerics;

public class Vector2IntTests
{
[Fact]
public void Constructor_WithTwoIntegers_ShouldInitializeCorrectly()
{
const int first = 5;
const int second = 10;

var vector = new Vector2Int(first, second);

Assert.Equal(first, vector.First);
Assert.Equal(second, vector.Second);
}

[Fact]
public void Constructor_WithSpan_ShouldInitializeCorrectly_WhenBothValuesProvided()
{
ReadOnlySpan<int> values = [1, 2];

var vector = new Vector2Int(values);

Assert.Equal(1, vector.First);
Assert.Equal(2, vector.Second);
}

[Fact]
public void Constructor_WithSpan_ShouldInitializeCorrectly_WhenOneValueProvided()
{
ReadOnlySpan<int> values = [3];

var vector = new Vector2Int(values);

Assert.Equal(3, vector.First);
Assert.Equal(0, vector.Second); // Default value for the second component
}

[Fact]
public void Constructor_WithSpan_ShouldInitializeCorrectly_WhenMoreValuesProvided()
{
ReadOnlySpan<int> values = [1, 2, 3];

var vector = new Vector2Int(values);

Assert.Equal(1, vector.First);
Assert.Equal(2, vector.Second);
}


[Fact]
public void Constructor_WithSpan_ShouldInitializeToZero_WhenNoValuesProvided()
{
var values = ReadOnlySpan<int>.Empty;

var vector = new Vector2Int(values);

Assert.Equal(0, vector.First); // Default value for the first component
Assert.Equal(0, vector.Second); // Default value for the second component
}

[Fact]
public void Equals_ShouldReturnTrue_WhenVectorsAreEqual()
{
var vector1 = new Vector2Int(1, 2);
var vector2 = new Vector2Int(1, 2);

var result = vector1.Equals(vector2);

Assert.True(result);
}

[Fact]
public void Equals_ShouldReturnFalse_WhenVectorsAreNotEqual()
{
var vector1 = new Vector2Int(1, 2);
var vector2 = new Vector2Int(3, 4);

var result = vector1.Equals(vector2);

Assert.False(result);
}

[Fact]
public void Equals_ShouldReturnTrue_WhenComparingWithEqualObject()
{
var vector1 = new Vector2Int(1, 2);
object vector2 = new Vector2Int(1, 2);

var result = vector1.Equals(vector2);

Assert.True(result);
}

[Fact]
public void Equals_ShouldReturnFalse_WhenComparingWithDifferentObject()
{
var vector1 = new Vector2Int(1, 2);
object vector2 = new Vector2Int(3, 4);

Assert.False(vector1.Equals(vector2));
}

[Fact]
public void Equals_ShouldReturnFalse_WhenComparingWithNullObject()
{
var vector = new Vector2Int(1, 2);

Assert.False(vector.Equals(null));
}

[Fact]
public void GetHashCode_ShouldReturnSameHashCode_ForEqualVectors()
{
var vector1 = new Vector2Int(1, 2);
var vector2 = new Vector2Int(1, 2);

var hashCode1 = vector1.GetHashCode();
var hashCode2 = vector2.GetHashCode();

Assert.Equal(hashCode1, hashCode2);
}

[Fact]
public void GetHashCode_ShouldReturnDifferentHashCode_ForDifferentVectors()
{
var vector1 = new Vector2Int(1, 2);
var vector2 = new Vector2Int(3, 4);

var hashCode1 = vector1.GetHashCode();
var hashCode2 = vector2.GetHashCode();

Assert.NotEqual(hashCode1, hashCode2);
}
}
134 changes: 134 additions & 0 deletions PG.Commons/PG.Commons.Test/Numerics/Vector3IntTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
using System;
using PG.Commons.Numerics;
using Xunit;

namespace PG.Commons.Test.Numerics;

public class Vector3IntTests
{
[Fact]
public void Constructor_WithThreeIntegers_ShouldInitializeCorrectly()
{
const int first = 5;
const int second = 10;
const int third = 15;

var vector = new Vector3Int(first, second, third);

Assert.Equal(first, vector.First);
Assert.Equal(second, vector.Second);
Assert.Equal(third, vector.Third);
}

[Fact]
public void Constructor_WithSpan_ShouldInitializeCorrectly_WhenAllValuesProvided()
{
ReadOnlySpan<int> values = [1, 2, 3];

var vector = new Vector3Int(values);

Assert.Equal(1, vector.First);
Assert.Equal(2, vector.Second);
Assert.Equal(3, vector.Third);
}

[Fact]
public void Constructor_WithSpan_ShouldInitializeCorrectly_WhenTwoValuesProvided()
{
ReadOnlySpan<int> values = [3, 4];

var vector = new Vector3Int(values);

Assert.Equal(3, vector.First);
Assert.Equal(4, vector.Second);
Assert.Equal(0, vector.Third); // Default value for the third component
}

[Fact]
public void Constructor_WithSpan_ShouldInitializeCorrectly_WhenOneValueProvided()
{
ReadOnlySpan<int> values = [5];

var vector = new Vector3Int(values);

Assert.Equal(5, vector.First);
Assert.Equal(0, vector.Second); // Default value for the second component
Assert.Equal(0, vector.Third); // Default value for the third component
}

[Fact]
public void Constructor_WithSpan_ShouldInitializeCorrectly_WhenMoreValuesProvided()
{
ReadOnlySpan<int> values = [1, 2, 3, 4];

var vector = new Vector3Int(values);

Assert.Equal(1, vector.First);
Assert.Equal(2, vector.Second);
Assert.Equal(3, vector.Third);
}

[Fact]
public void Constructor_WithSpan_ShouldInitializeToZero_WhenNoValuesProvided()
{
var values = ReadOnlySpan<int>.Empty;

var vector = new Vector3Int(values);

Assert.Equal(0, vector.First); // Default value for the first component
Assert.Equal(0, vector.Second); // Default value for the second component
Assert.Equal(0, vector.Third); // Default value for the third component
}

[Fact]
public void Equals_ShouldReturnTrue_WhenVectorsAreEqual()
{
var vector1 = new Vector3Int(1, 2, 3);
var vector2 = new Vector3Int(1, 2, 3);

Assert.True(vector1.Equals(vector2));
Assert.True(vector1.Equals((object)vector2));
}

[Fact]
public void Equals_ShouldReturnFalse_WhenComparingWithNullObject()
{
var vector = new Vector3Int(1, 2, 3);

Assert.False(vector.Equals(null));
}

[Fact]
public void Equals_ShouldReturnFalse_WhenVectorsAreNotEqual()
{
var vector1 = new Vector3Int(1, 2, 3);
var vector2 = new Vector3Int(4, 5, 6);

Assert.False(vector1.Equals(vector2));
Assert.False(vector1.Equals((object)vector2));
}

[Fact]
public void GetHashCode_ShouldReturnSameHashCode_ForEqualVectors()
{
var vector1 = new Vector3Int(1, 2, 3);
var vector2 = new Vector3Int(1, 2, 3);

var hashCode1 = vector1.GetHashCode();
var hashCode2 = vector2.GetHashCode();

Assert.Equal(hashCode1, hashCode2);
}

[Fact]
public void GetHashCode_ShouldReturnDifferentHashCode_ForDifferentVectors()
{
var vector1 = new Vector3Int(1, 2, 3);
var vector2 = new Vector3Int(4, 5, 6);

var hashCode1 = vector1.GetHashCode();
var hashCode2 = vector2.GetHashCode();

Assert.NotEqual(hashCode1, hashCode2);
}
}
Loading
Loading