2023-08-26 18:11:29 +01:00
|
|
|
using NUnit.Framework;
|
2023-03-31 20:37:50 +01:00
|
|
|
using X10D.Math;
|
|
|
|
|
|
|
|
namespace X10D.Tests.Math;
|
|
|
|
|
2023-08-22 17:32:47 +01:00
|
|
|
internal partial class Int32Tests
|
2023-03-31 20:37:50 +01:00
|
|
|
{
|
2023-04-05 22:26:31 +01:00
|
|
|
[TestFixture]
|
2023-03-31 20:37:50 +01:00
|
|
|
public class WrapTests
|
|
|
|
{
|
2023-04-05 22:26:31 +01:00
|
|
|
[Test]
|
2023-03-31 20:37:50 +01:00
|
|
|
public void Wrap_ShouldReturnLow_WhenValueIsEqualToLow()
|
|
|
|
{
|
|
|
|
const int value = 10;
|
|
|
|
const int low = 10;
|
|
|
|
const int high = 20;
|
|
|
|
|
|
|
|
int result = value.Wrap(low, high);
|
|
|
|
|
2023-04-05 22:26:31 +01:00
|
|
|
Assert.That(result, Is.EqualTo(low));
|
2023-03-31 20:37:50 +01:00
|
|
|
}
|
|
|
|
|
2023-04-05 22:26:31 +01:00
|
|
|
[Test]
|
2023-03-31 20:37:50 +01:00
|
|
|
public void Wrap_ShouldReturnHigh_WhenValueIsEqualToHigh()
|
|
|
|
{
|
|
|
|
const int value = 20;
|
|
|
|
const int low = 10;
|
|
|
|
const int high = 20;
|
|
|
|
|
|
|
|
int result = value.Wrap(low, high);
|
|
|
|
|
2023-04-05 22:26:31 +01:00
|
|
|
Assert.That(result, Is.EqualTo(low));
|
2023-03-31 20:37:50 +01:00
|
|
|
}
|
|
|
|
|
2023-04-05 22:26:31 +01:00
|
|
|
[Test]
|
2023-03-31 20:37:50 +01:00
|
|
|
public void Wrap_ShouldReturnCorrectResult_WhenValueIsGreaterThanHigh()
|
|
|
|
{
|
|
|
|
const int value = 30;
|
|
|
|
const int low = 10;
|
|
|
|
const int high = 20;
|
|
|
|
|
|
|
|
int result = value.Wrap(low, high);
|
|
|
|
|
2023-04-05 22:26:31 +01:00
|
|
|
Assert.That(result, Is.EqualTo(low));
|
2023-03-31 20:37:50 +01:00
|
|
|
}
|
|
|
|
|
2023-04-05 22:26:31 +01:00
|
|
|
[Test]
|
2023-03-31 20:37:50 +01:00
|
|
|
public void Wrap_ShouldReturnCorrectResult_WhenValueIsLessThanLow()
|
|
|
|
{
|
|
|
|
const int value = 5;
|
|
|
|
const int low = 10;
|
|
|
|
const int high = 20;
|
|
|
|
|
|
|
|
int result = value.Wrap(low, high);
|
|
|
|
|
2023-04-05 22:26:31 +01:00
|
|
|
Assert.That(result, Is.EqualTo(15));
|
2023-03-31 20:37:50 +01:00
|
|
|
}
|
|
|
|
|
2023-04-05 22:26:31 +01:00
|
|
|
[Test]
|
2023-03-31 20:37:50 +01:00
|
|
|
public void Wrap_ShouldReturnCorrectResult_WhenValueIsInBetweenLowAndHigh()
|
|
|
|
{
|
|
|
|
const int value = 15;
|
|
|
|
const int low = 10;
|
|
|
|
const int high = 20;
|
|
|
|
|
|
|
|
int result = value.Wrap(low, high);
|
|
|
|
|
2023-04-05 22:26:31 +01:00
|
|
|
Assert.That(result, Is.EqualTo(value));
|
2023-03-31 20:37:50 +01:00
|
|
|
}
|
|
|
|
|
2023-04-05 22:26:31 +01:00
|
|
|
[Test]
|
2023-03-31 20:37:50 +01:00
|
|
|
public void Wrap_ShouldReturnZero_WhenValueIsEqualToLength()
|
|
|
|
{
|
|
|
|
const int value = 10;
|
|
|
|
const int length = 10;
|
|
|
|
|
|
|
|
int result = value.Wrap(length);
|
|
|
|
|
2023-04-05 22:26:31 +01:00
|
|
|
Assert.That(result, Is.Zero);
|
2023-03-31 20:37:50 +01:00
|
|
|
}
|
|
|
|
|
2023-04-05 22:26:31 +01:00
|
|
|
[Test]
|
2023-03-31 20:37:50 +01:00
|
|
|
public void Wrap_ShouldReturnValue_WhenValueIsLessThanLength()
|
|
|
|
{
|
|
|
|
const int value = 5;
|
|
|
|
const int length = 10;
|
|
|
|
|
|
|
|
int result = value.Wrap(length);
|
|
|
|
|
2023-04-05 22:26:31 +01:00
|
|
|
Assert.That(result, Is.EqualTo(value));
|
2023-03-31 20:37:50 +01:00
|
|
|
}
|
|
|
|
|
2023-04-05 22:26:31 +01:00
|
|
|
[Test]
|
2023-03-31 20:37:50 +01:00
|
|
|
public void Wrap_ShouldReturnCorrectResult_WhenValueIsGreaterThanLength()
|
|
|
|
{
|
|
|
|
const int value = 15;
|
|
|
|
const int length = 10;
|
|
|
|
|
|
|
|
int result = value.Wrap(length);
|
|
|
|
|
2023-04-05 22:26:31 +01:00
|
|
|
Assert.That(result, Is.EqualTo(5));
|
2023-03-31 20:37:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|