Files

83 lines
1.7 KiB
C#

using NUnit.Framework;
using Sarand.Net.Standard.Base.Helpers;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
namespace Sacs.UnitTests.Net.Standard.Base.Helpers
{
[TestFixture]
public class SacsRandomHelper_Tester
{
// Random Helper.
// Fill byte array.
// --- Tests ---
[Test]
public void Fill_ByteArray()
{
int dataLength = 10;
byte[] data = new byte[dataLength];
Assert.That(data, Is.Not.Null);
// Initial values should be zero.
for (int i = 0; i < dataLength; i++)
Assert.That(data[i], Is.EqualTo(0));
SacsRandomHelper.Fill(data);
// Sum of data values should no longer be zero.
int total = 0;
for (int i = 0; i < dataLength; i++)
total += data[i];
Assert.That(total, Is.Not.EqualTo(0));
}
[Test]
public void GetInt32_ToExclusive()
{
for (int i = 1; i < 1000; i++)
{
int value = SacsRandomHelper.GetInt32(i);
Assert.That(value >= 0, Is.True);
Assert.That(value < i, Is.True);
}
}
[Test]
public void GetInt32_FromInclusive_ToExclusive()
{
for (int i = -100; i < 101; i++)
{
for (int j = i + 1; j < i + 100; j++)
{
int value = SacsRandomHelper.GetInt32(i, j);
//Debug.WriteLine("Value: "+value);
Assert.That(value >= i, Is.True);
Assert.That(value < j, Is.True);
}
}
}
[Test]
public void GetInt32_getRandomLengthNumber()
{
for (ushort i = 1; i < 13; i++)
{
for (int j = 0; j < 10; j++)
{
String value = SacsRandomHelper.GetRandomLengthNumber(i);
//Debug.WriteLine("Value: " + value);
Assert.That(value.Length > 0, Is.True);
Assert.That(value.Length < i + 1, Is.True);
}
}
}
// --- The End ---
}
}