2022-05-08 12:09:30 +01:00
|
|
|
|
#nullable enable
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using X10D.Unity.Drawing;
|
|
|
|
|
using Random = System.Random;
|
|
|
|
|
|
2022-05-08 12:17:57 +01:00
|
|
|
|
namespace X10D.Unity.Tests.Drawing
|
2022-05-08 12:09:30 +01:00
|
|
|
|
{
|
|
|
|
|
public class RandomTests
|
|
|
|
|
{
|
2023-04-05 19:18:06 +01:00
|
|
|
|
[Test]
|
|
|
|
|
public void NextColorArgb_ShouldReturn331515e5_GivenSeed1234()
|
2022-05-08 12:09:30 +01:00
|
|
|
|
{
|
|
|
|
|
var random = new Random(1234);
|
|
|
|
|
var color = random.NextColorArgb();
|
2023-04-05 22:51:04 +01:00
|
|
|
|
Assert.That(color.r, Is.EqualTo(0.373868465f).Within(1e-6f));
|
|
|
|
|
Assert.That(color.g, Is.EqualTo(0.391597569f).Within(1e-6f));
|
|
|
|
|
Assert.That(color.b, Is.EqualTo(0.675019085f).Within(1e-6f));
|
|
|
|
|
Assert.That(color.a, Is.EqualTo(0.234300315f).Within(1e-6f));
|
2022-05-08 12:09:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-05 19:18:06 +01:00
|
|
|
|
[Test]
|
|
|
|
|
public void NextColorArgb_ShouldThrow_GivenNull()
|
2022-05-08 12:09:30 +01:00
|
|
|
|
{
|
2023-04-05 19:18:06 +01:00
|
|
|
|
Random random = null!;
|
|
|
|
|
Assert.Throws<ArgumentNullException>(() => random.NextColorArgb());
|
2022-05-08 12:09:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-05 19:18:06 +01:00
|
|
|
|
[Test]
|
|
|
|
|
public void NextColor32Argb_ShouldReturn331515e5_GivenSeed1234()
|
2022-05-08 12:09:30 +01:00
|
|
|
|
{
|
|
|
|
|
var random = new Random(1234);
|
2023-04-05 22:51:04 +01:00
|
|
|
|
Assert.That(random.NextColor32Argb(), Is.EqualTo(new Color32(21, 21, 229, 51)));
|
2022-05-08 12:09:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-05 19:18:06 +01:00
|
|
|
|
[Test]
|
|
|
|
|
public void NextColor32Argb_ShouldThrow_GivenNull()
|
2022-05-08 12:09:30 +01:00
|
|
|
|
{
|
2023-04-05 19:18:06 +01:00
|
|
|
|
Random random = null!;
|
|
|
|
|
Assert.Throws<ArgumentNullException>(() => random.NextColor32Argb());
|
2022-05-08 12:09:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-05 19:18:06 +01:00
|
|
|
|
[Test]
|
|
|
|
|
public void NextColorRgb_ShouldReturn1515e5_GivenSeed1234()
|
2022-05-08 12:09:30 +01:00
|
|
|
|
{
|
|
|
|
|
var random = new Random(1234);
|
|
|
|
|
var color = random.NextColorRgb();
|
2023-04-05 22:51:04 +01:00
|
|
|
|
Assert.That(color.r, Is.EqualTo(0.234300315f).Within(1e-6f));
|
|
|
|
|
Assert.That(color.g, Is.EqualTo(0.373868465f).Within(1e-6f));
|
|
|
|
|
Assert.That(color.b, Is.EqualTo(0.391597569f).Within(1e-6f));
|
|
|
|
|
Assert.That(color.a, Is.EqualTo(1).Within(1e-6f));
|
2022-05-08 12:09:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-05 19:18:06 +01:00
|
|
|
|
[Test]
|
|
|
|
|
public void NextColorRgb_ShouldThrow_GivenNull()
|
2022-05-08 12:09:30 +01:00
|
|
|
|
{
|
2023-04-05 19:18:06 +01:00
|
|
|
|
Random random = null!;
|
|
|
|
|
Assert.Throws<ArgumentNullException>(() => random.NextColorRgb());
|
2022-05-08 12:09:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-05 19:18:06 +01:00
|
|
|
|
[Test]
|
|
|
|
|
public void NextColor32Rgb_ShouldReturn1515e5_GivenSeed1234()
|
2022-05-08 12:09:30 +01:00
|
|
|
|
{
|
|
|
|
|
var random = new Random(1234);
|
2023-04-05 22:51:04 +01:00
|
|
|
|
Assert.That(random.NextColor32Rgb(), Is.EqualTo(new Color32(21, 21, 229, 255)));
|
2022-05-08 12:09:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-05 19:18:06 +01:00
|
|
|
|
[Test]
|
|
|
|
|
public void NextColor32Rgb_ShouldThrow_GivenNull()
|
2022-05-08 12:09:30 +01:00
|
|
|
|
{
|
2023-04-05 19:18:06 +01:00
|
|
|
|
Random random = null!;
|
|
|
|
|
Assert.Throws<ArgumentNullException>(() => random.NextColor32Rgb());
|
2022-05-08 12:09:30 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|