Skip to content
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

Improved test for roll_the_die #2354

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
19 changes: 16 additions & 3 deletions exercises/concept/roll-the-die/RollTheDieTests.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,38 @@
using Xunit;
using Exercism.Tests;
using System.Collections.Generic;

public class RollTheDieTests
{
[Fact]
[Task(1)]
public void RollDie()
{
var rollCount = 1000;
var rolls = new HashSet<int>(rollCount);
var player = new Player();
for (var i = 0; i < 100; i++)
for (var i = 0; i < rollCount; i++)
{
var roll = player.RollDie();
rolls.Add(roll);
Assert.InRange(player.RollDie(), 1, 18);
}
Assert.Equal(18, rolls.Count);
}

[Fact]
[Task(2)]
public void GenerateSpellStrength()
{
var rollCount = 100;
var rolls = new HashSet<double>(rollCount);
var player = new Player();
var strength = player.GenerateSpellStrength();
Assert.InRange(strength, 0.0, 100.0);
for (var i = 0; i < rollCount; i++)
{
var strength = player.GenerateSpellStrength();
rolls.Add(strength);
Assert.InRange(strength, 0.0, 100.0);
}
Assert.Equal(rollCount, rolls.Count);
Comment on lines +27 to +36
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean that you expect all 100 rolls to be unique, correct? If so, I wonder if we should maybe be slightly more tolerant of accidental duplicates. Maybe something like Assert.True(rolls.Count >= rollCount - 5) or something like that

}
}