Make random object used in Dice.cs static and remove unused logging. (#5)
All checks were successful
MANDATORY: Build project (Pflib Net) TeamCity build finished
All checks were successful
MANDATORY: Build project (Pflib Net) TeamCity build finished
Remove unused parts of negative test. Reviewed-on: #5 Co-authored-by: Malachy Byrne <malachybyrne1@gmail.com> Co-committed-by: Malachy Byrne <malachybyrne1@gmail.com>
This commit is contained in:
parent
8abd1e99ef
commit
2894fc99d8
@ -49,10 +49,9 @@ public class DiceTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
[TestCase(1, 1)]
|
public void CannotSetKeepHighestAndKeepLowest()
|
||||||
public void CannotSetKeepHighestAndKeepLowest(int high, int low)
|
|
||||||
{
|
{
|
||||||
var e = Assert.Throws<InvalidOperationException>(
|
Assert.Throws<InvalidOperationException>(
|
||||||
() => new Dice(1, 40, high, low));
|
() => new Dice(1, 40, 1, 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -7,6 +7,7 @@ public struct Dice
|
|||||||
private int KeepHighest { get; set; }
|
private int KeepHighest { get; set; }
|
||||||
private int KeepLowest { get; set; }
|
private int KeepLowest { get; set; }
|
||||||
private int Add { get; set; }
|
private int Add { get; set; }
|
||||||
|
private static readonly Random Random = new();
|
||||||
|
|
||||||
public Dice(int size, int count = 1, int keepHighest = 0, int keepLowest = 0, int add = 0)
|
public Dice(int size, int count = 1, int keepHighest = 0, int keepLowest = 0, int add = 0)
|
||||||
{
|
{
|
||||||
@ -24,11 +25,10 @@ public struct Dice
|
|||||||
|
|
||||||
public int GetValue()
|
public int GetValue()
|
||||||
{
|
{
|
||||||
var random = new Random();
|
|
||||||
var rolls = new List<int>();
|
var rolls = new List<int>();
|
||||||
for (var i = 0; i < Count; i++)
|
for (var i = 0; i < Count; i++)
|
||||||
{
|
{
|
||||||
rolls.Add(random.Next(Size) + 1);
|
rolls.Add(Random.Next(Size) + 1);
|
||||||
}
|
}
|
||||||
rolls.Sort();
|
rolls.Sort();
|
||||||
|
|
||||||
@ -37,7 +37,6 @@ public struct Dice
|
|||||||
var repeats = Count - KeepHighest;
|
var repeats = Count - KeepHighest;
|
||||||
for (var i = 0; i < repeats; i++)
|
for (var i = 0; i < repeats; i++)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Removing max");
|
|
||||||
rolls.Remove(rolls.Max());
|
rolls.Remove(rolls.Max());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -48,7 +47,6 @@ public struct Dice
|
|||||||
|
|
||||||
for (var i = 0; i < repeats; i++)
|
for (var i = 0; i < repeats; i++)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Removing min");
|
|
||||||
rolls.Remove(rolls.Min());
|
rolls.Remove(rolls.Min());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user