87 lines
2.2 KiB
C#
87 lines
2.2 KiB
C#
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
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
|
|
{
|
|
//=======================================================================
|
|
[TestClass]
|
|
public class SacsRandomHelper_Tester
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Random Helper.
|
|
//-------------------------------------------------------------------
|
|
// Fill byte array.
|
|
[TestMethod]
|
|
public void Fill_ByteArray()
|
|
{
|
|
int dataLength = 10;
|
|
byte[] data = new byte[dataLength];
|
|
Assert.IsNotNull(data);
|
|
|
|
// Initial values should be zero.
|
|
for (int i = 0; i < dataLength; i++)
|
|
Assert.AreEqual(0, data[i]);
|
|
|
|
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.AreNotEqual(0, total);
|
|
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
[TestMethod]
|
|
public void GetInt32_ToExclusive()
|
|
{
|
|
for (int i = 1; i < 1000; i++)
|
|
{
|
|
int value = SacsRandomHelper.GetInt32(i);
|
|
Assert.IsTrue(value >= 0);
|
|
Assert.IsTrue(value < i);
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
[TestMethod]
|
|
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.IsTrue(value >= i);
|
|
Assert.IsTrue(value < j);
|
|
}
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
[TestMethod]
|
|
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.IsTrue(value.Length > 0);
|
|
Assert.IsTrue(value.Length < i + 1);
|
|
}
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|