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