Skip to content

Commit 29c966a

Browse files
committed
Added test and implementation for LongRange
1 parent 8f84ac0 commit 29c966a

File tree

2 files changed

+137
-0
lines changed

2 files changed

+137
-0
lines changed

Tynamix.ObjectFiller.Test/RangePluginTest.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,69 @@ public void TestFloateRangeWithMinMaxValue()
5151
Assert.IsNotNull(sl.ChildList);
5252
Assert.IsTrue(sl.ChildList.All(x => x >= min && x <= max));
5353
}
54+
55+
[TestMethod]
56+
public void TestLongRangeWithMaxValue()
57+
{
58+
long max = int.MaxValue * 10L;
59+
Filler<SimpleList<long>> filler = new Filler<SimpleList<long>>();
60+
61+
filler.Setup().OnType<long>().Use(new LongRange(max));
62+
var sl = filler.Create();
63+
64+
Assert.IsNotNull(sl);
65+
Assert.IsNotNull(sl.ChildList);
66+
Assert.IsTrue(sl.ChildList.All(x => x < max));
67+
Assert.IsFalse(sl.ChildList.All(x => x == sl.ChildList[0]));
68+
}
69+
70+
[TestMethod]
71+
public void TestLongRangeWithMinMaxValue()
72+
{
73+
long min = int.MinValue * 10L;
74+
long max = int.MaxValue * 10L;
75+
Filler<SimpleList<long>> filler = new Filler<SimpleList<long>>();
76+
77+
filler.Setup().OnType<long>().Use(new LongRange(min, max));
78+
var sl = filler.Create();
79+
80+
Assert.IsNotNull(sl);
81+
Assert.IsNotNull(sl.ChildList);
82+
Assert.IsTrue(sl.ChildList.All(x => x >= min && x <= max));
83+
Assert.IsFalse(sl.ChildList.All(x => x == sl.ChildList[0]));
84+
}
85+
86+
[TestMethod]
87+
public void TestLongRangeWithMinMaxValueLowSmallRange()
88+
{
89+
long min = long.MinValue;
90+
long max = long.MinValue + 10;
91+
Filler<SimpleList<long>> filler = new Filler<SimpleList<long>>();
92+
93+
filler.Setup().OnType<long>().Use(new LongRange(min, max));
94+
var sl = filler.Create();
95+
96+
Assert.IsNotNull(sl);
97+
Assert.IsNotNull(sl.ChildList);
98+
Assert.IsTrue(sl.ChildList.All(x => x >= min && x <= max));
99+
Assert.IsFalse(sl.ChildList.All(x => x == sl.ChildList[0]));
100+
}
101+
102+
[TestMethod]
103+
public void TestLongRangeWithMinMaxValueHighSmallRange()
104+
{
105+
long min = long.MaxValue - 10;
106+
long max = long.MaxValue;
107+
Filler<SimpleList<long>> filler = new Filler<SimpleList<long>>();
108+
109+
filler.Setup().OnType<long>().Use(new LongRange(min, max));
110+
var sl = filler.Create();
111+
112+
Assert.IsNotNull(sl);
113+
Assert.IsNotNull(sl.ChildList);
114+
Assert.IsTrue(sl.ChildList.All(x => x >= min && x <= max));
115+
Assert.IsFalse(sl.ChildList.All(x => x == sl.ChildList[0]));
116+
}
117+
54118
}
55119
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
namespace Tynamix.ObjectFiller
2+
{
3+
using System;
4+
5+
/// <summary>
6+
/// The 64-integer range plugin
7+
/// </summary>
8+
public class LongRange : IRandomizerPlugin<long>, IRandomizerPlugin<long?>
9+
{
10+
/// <summary>
11+
/// The min value
12+
/// </summary>
13+
private readonly long min;
14+
15+
/// <summary>
16+
/// The max value
17+
/// </summary>
18+
private readonly long max;
19+
20+
/// <summary>
21+
/// Initializes a new instance of the <see cref="LongRange"/> class.
22+
/// </summary>
23+
/// <param name="min">
24+
/// The min value
25+
/// </param>
26+
/// <param name="max">
27+
/// The max value
28+
/// </param>
29+
public LongRange(long min, long max)
30+
{
31+
this.min = min;
32+
this.max = max;
33+
}
34+
35+
/// <summary>
36+
/// Initializes a new instance of the <see cref="LongRange"/> class.
37+
/// </summary>
38+
/// <param name="max">
39+
/// The max.
40+
/// </param>
41+
public LongRange(long max)
42+
: this(long.MinValue, max)
43+
{
44+
}
45+
46+
/// <summary>
47+
/// Initializes a new instance of the <see cref="LongRange"/> class.
48+
/// </summary>
49+
public LongRange()
50+
: this(long.MinValue, long.MaxValue)
51+
{
52+
}
53+
54+
/// <summary>
55+
/// Gets random data for type <see cref="long"/>
56+
/// </summary>
57+
/// <returns>Random data for type <see cref="long"/></returns>
58+
public long GetValue()
59+
{
60+
return Random.NextLong(this.min, this.max);
61+
}
62+
63+
64+
/// <summary>
65+
/// Gets random data for type <see cref="Nullable{Int64}"/>
66+
/// </summary>
67+
/// <returns>Random data for type <see cref="Nullable{Int64}"/></returns>
68+
long? IRandomizerPlugin<long?>.GetValue()
69+
{
70+
return this.GetValue();
71+
}
72+
}
73+
}

0 commit comments

Comments
 (0)