rename Limits record to Sample

This commit is contained in:
onyx-and-iris 2026-02-26 00:56:23 +00:00
parent 72e7728e8f
commit 481925d210
2 changed files with 20 additions and 20 deletions

View File

@ -3,16 +3,16 @@
internal class Generator internal class Generator
{ {
/// <summary> /// <summary>
/// Simple algorithm for generating a list of unique numbers of Limits.Count size /// Simple algorithm for generating a list of unique numbers of sample.Count size.
/// </summary> /// </summary>
/// <param name="limits">Defines the amount of numbers to generate, the min and max values</param> /// <param name="sample">Defines the sample size as well as the upper and lower bounds.</param>
/// <returns>Numbers are returned as a sorted set.</returns> /// <returns>Numbers are returned as a sorted set.</returns>
public static SortedSet<int> Generate(Limits limits) public static SortedSet<int> Generate(Sample sample)
{ {
List<int> candidates = [.. Enumerable.Range(limits.Lower, limits.Upper)]; List<int> candidates = [.. Enumerable.Range(sample.Lower, sample.Upper)];
SortedSet<int> numbers = []; SortedSet<int> numbers = [];
for (int i = 0; i < limits.Count; i++) for (int i = 0; i < sample.Count; i++)
{ {
int RandomIndex = Random.Shared.Next(candidates.Count); int RandomIndex = Random.Shared.Next(candidates.Count);
numbers.Add(candidates[RandomIndex]); numbers.Add(candidates[RandomIndex]);

View File

@ -1,15 +1,15 @@
namespace Lottery namespace Lottery
{ {
internal record Limits(int Count, int Lower, int Upper); internal record Sample(int Lower, int Upper, int Count);
/// <summary> /// <summary>
/// Abstract base class for lotteries. /// Abstract base class for lotteries.
/// Limits property must be overridden. /// Sample property must be overridden.
/// </summary> /// </summary>
internal abstract class Lottery internal abstract class Lottery
{ {
protected virtual Limits Limits => throw new NotImplementedException(); protected virtual Sample Sample => throw new NotImplementedException();
public virtual string Play() => $"Numbers: {string.Join(", ", Generator.Generate(Limits))}"; public virtual string Play() => $"Numbers: {string.Join(", ", Generator.Generate(Sample))}";
} }
/// <summary> /// <summary>
@ -18,24 +18,24 @@
/// </summary> /// </summary>
internal class LottoLottery : Lottery internal class LottoLottery : Lottery
{ {
protected override Limits Limits { get; } = new(Count: 6, Lower: 1, Upper: 59); protected override Sample Sample { get; } = new(Lower: 1, Upper: 59, Count: 6);
} }
/// <summary> /// <summary>
/// Abstract base class for Lotteries with Special values. /// Abstract base class for Lotteries with Special values.
/// It subclasses Lottery. /// It subclasses Lottery.
/// SpecialLimits and SpecialIdentifier properties must be overridden. /// SpecialSample and SpecialIdentifier properties must be overridden.
/// </summary> /// </summary>
internal abstract class LotteryWithSpecial : Lottery internal abstract class LotteryWithSpecial : Lottery
{ {
protected virtual Limits SpecialLimits => throw new NotImplementedException(); protected virtual Sample SpecialSample => throw new NotImplementedException();
protected virtual string SpecialIdentifier => throw new NotImplementedException(); protected virtual string SpecialIdentifier => throw new NotImplementedException();
public override string Play() public override string Play()
{ {
return string.Join("\n", [ return string.Join("\n", [
$"Numbers: {string.Join(", ", Generator.Generate(Limits))}", $"Numbers: {string.Join(", ", Generator.Generate(Sample))}",
$"{SpecialIdentifier}: {string.Join(", ", Generator.Generate(SpecialLimits))}", $"{SpecialIdentifier}: {string.Join(", ", Generator.Generate(SpecialSample))}",
]); ]);
} }
} }
@ -46,8 +46,8 @@
/// </summary> /// </summary>
internal class EuroMillionsLottery : LotteryWithSpecial internal class EuroMillionsLottery : LotteryWithSpecial
{ {
protected override Limits Limits { get; } = new(Count: 5, Lower: 1, Upper: 50); protected override Sample Sample { get; } = new(Lower: 1, Upper: 50, Count: 5);
protected override Limits SpecialLimits { get; } = new(Count: 2, Lower: 1, Upper: 12); protected override Sample SpecialSample { get; } = new(Lower: 1, Upper: 12, Count: 2);
protected override string SpecialIdentifier => "Lucky Stars"; protected override string SpecialIdentifier => "Lucky Stars";
} }
@ -57,8 +57,8 @@
/// </summary> /// </summary>
internal class SetForLifeLottery : LotteryWithSpecial internal class SetForLifeLottery : LotteryWithSpecial
{ {
protected override Limits Limits { get; } = new(Count: 5, Lower: 1, Upper: 47); protected override Sample Sample { get; } = new(Lower: 1, Upper: 47, Count: 5);
protected override Limits SpecialLimits { get; } = new(Count: 1, Lower: 1, Upper: 10); protected override Sample SpecialSample { get; } = new(Lower: 1, Upper: 10, Count: 1);
protected override string SpecialIdentifier => "Life Ball"; protected override string SpecialIdentifier => "Life Ball";
} }
@ -68,8 +68,8 @@
/// </summary> /// </summary>
internal class ThunderballLottery : LotteryWithSpecial internal class ThunderballLottery : LotteryWithSpecial
{ {
protected override Limits Limits { get; } = new(Count: 5, Lower: 1, Upper: 39); protected override Sample Sample { get; } = new(Lower: 1, Upper: 39, Count: 5);
protected override Limits SpecialLimits { get; } = new(Count: 1, Lower: 1, Upper: 14); protected override Sample SpecialSample { get; } = new(Lower: 1, Upper: 14, Count: 1);
protected override string SpecialIdentifier => "Thunderball"; protected override string SpecialIdentifier => "Thunderball";
} }
} }