Skip to content

Added test and implementation for LongRange #123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions Tynamix.ObjectFiller.Test/RangePluginTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,69 @@ public void TestFloateRangeWithMinMaxValue()
Assert.IsNotNull(sl.ChildList);
Assert.IsTrue(sl.ChildList.All(x => x >= min && x <= max));
}

[TestMethod]
public void TestLongRangeWithMaxValue()
{
long max = int.MaxValue * 10L;
Filler<SimpleList<long>> filler = new Filler<SimpleList<long>>();

filler.Setup().OnType<long>().Use(new LongRange(max));
var sl = filler.Create();

Assert.IsNotNull(sl);
Assert.IsNotNull(sl.ChildList);
Assert.IsTrue(sl.ChildList.All(x => x < max));
Assert.IsFalse(sl.ChildList.All(x => x == sl.ChildList[0]));
}

[TestMethod]
public void TestLongRangeWithMinMaxValue()
{
long min = int.MinValue * 10L;
long max = int.MaxValue * 10L;
Filler<SimpleList<long>> filler = new Filler<SimpleList<long>>();

filler.Setup().OnType<long>().Use(new LongRange(min, max));
var sl = filler.Create();

Assert.IsNotNull(sl);
Assert.IsNotNull(sl.ChildList);
Assert.IsTrue(sl.ChildList.All(x => x >= min && x <= max));
Assert.IsFalse(sl.ChildList.All(x => x == sl.ChildList[0]));
}

[TestMethod]
public void TestLongRangeWithMinMaxValueLowSmallRange()
{
long min = long.MinValue;
long max = long.MinValue + 10;
Filler<SimpleList<long>> filler = new Filler<SimpleList<long>>();

filler.Setup().OnType<long>().Use(new LongRange(min, max));
var sl = filler.Create();

Assert.IsNotNull(sl);
Assert.IsNotNull(sl.ChildList);
Assert.IsTrue(sl.ChildList.All(x => x >= min && x <= max));
Assert.IsFalse(sl.ChildList.All(x => x == sl.ChildList[0]));
}

[TestMethod]
public void TestLongRangeWithMinMaxValueHighSmallRange()
{
long min = long.MaxValue - 10;
long max = long.MaxValue;
Filler<SimpleList<long>> filler = new Filler<SimpleList<long>>();

filler.Setup().OnType<long>().Use(new LongRange(min, max));
var sl = filler.Create();

Assert.IsNotNull(sl);
Assert.IsNotNull(sl.ChildList);
Assert.IsTrue(sl.ChildList.All(x => x >= min && x <= max));
Assert.IsFalse(sl.ChildList.All(x => x == sl.ChildList[0]));
}

}
}
73 changes: 73 additions & 0 deletions Tynamix.ObjectFiller/Plugins/Long/LongRange.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
namespace Tynamix.ObjectFiller
{
using System;

/// <summary>
/// The 64-integer range plugin
/// </summary>
public class LongRange : IRandomizerPlugin<long>, IRandomizerPlugin<long?>
{
/// <summary>
/// The min value
/// </summary>
private readonly long min;

/// <summary>
/// The max value
/// </summary>
private readonly long max;

/// <summary>
/// Initializes a new instance of the <see cref="LongRange"/> class.
/// </summary>
/// <param name="min">
/// The min value
/// </param>
/// <param name="max">
/// The max value
/// </param>
public LongRange(long min, long max)
{
this.min = min;
this.max = max;
}

/// <summary>
/// Initializes a new instance of the <see cref="LongRange"/> class.
/// </summary>
/// <param name="max">
/// The max.
/// </param>
public LongRange(long max)
: this(long.MinValue, max)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="LongRange"/> class.
/// </summary>
public LongRange()
: this(long.MinValue, long.MaxValue)
{
}

/// <summary>
/// Gets random data for type <see cref="long"/>
/// </summary>
/// <returns>Random data for type <see cref="long"/></returns>
public long GetValue()
{
return Random.NextLong(this.min, this.max);
}


/// <summary>
/// Gets random data for type <see cref="Nullable{Int64}"/>
/// </summary>
/// <returns>Random data for type <see cref="Nullable{Int64}"/></returns>
long? IRandomizerPlugin<long?>.GetValue()
{
return this.GetValue();
}
}
}