1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-10 07:35:42 +00:00
X10D/X10D.Unity.Tests/Assets/Tests/Drawing/RandomTests.cs

78 lines
2.5 KiB
C#
Raw Normal View History

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;
namespace X10D.Unity.Tests.Drawing
2022-05-08 12:09:30 +01:00
{
public class RandomTests
{
[Test]
public void NextColorArgb_ShouldReturn331515e5_GivenSeed1234()
2022-05-08 12:09:30 +01:00
{
var random = new Random(1234);
var color = random.NextColorArgb();
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
}
[Test]
public void NextColorArgb_ShouldThrow_GivenNull()
2022-05-08 12:09:30 +01:00
{
Random random = null!;
Assert.Throws<ArgumentNullException>(() => random.NextColorArgb());
2022-05-08 12:09:30 +01:00
}
[Test]
public void NextColor32Argb_ShouldReturn331515e5_GivenSeed1234()
2022-05-08 12:09:30 +01:00
{
var random = new Random(1234);
Assert.That(random.NextColor32Argb(), Is.EqualTo(new Color32(21, 21, 229, 51)));
2022-05-08 12:09:30 +01:00
}
[Test]
public void NextColor32Argb_ShouldThrow_GivenNull()
2022-05-08 12:09:30 +01:00
{
Random random = null!;
Assert.Throws<ArgumentNullException>(() => random.NextColor32Argb());
2022-05-08 12:09:30 +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();
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
}
[Test]
public void NextColorRgb_ShouldThrow_GivenNull()
2022-05-08 12:09:30 +01:00
{
Random random = null!;
Assert.Throws<ArgumentNullException>(() => random.NextColorRgb());
2022-05-08 12:09:30 +01:00
}
[Test]
public void NextColor32Rgb_ShouldReturn1515e5_GivenSeed1234()
2022-05-08 12:09:30 +01:00
{
var random = new Random(1234);
Assert.That(random.NextColor32Rgb(), Is.EqualTo(new Color32(21, 21, 229, 255)));
2022-05-08 12:09:30 +01:00
}
[Test]
public void NextColor32Rgb_ShouldThrow_GivenNull()
2022-05-08 12:09:30 +01:00
{
Random random = null!;
Assert.Throws<ArgumentNullException>(() => random.NextColor32Rgb());
2022-05-08 12:09:30 +01:00
}
}
}