#D&D Character C# Exercise, Test 20

5 messages · Page 1 of 1 (latest)

fervent quail
#

All other Tests are fine but I'm kinda stuck on this one.

https://exercism.org/tracks/csharp/exercises/dnd-character

the test checks if the Random numbers created by my Ability() Method matches the Distribution that is expected by the Faktors in the Dictionary declared in the Test times the min multiplicator and the max multiplicator, which are 200 and 300 respectively.

I calculated that the for loop in the test where my Distribution get's generated will run 324.000 times
Here is my Ability() Method

public static int Ability() 
    {
        List<int> rolls = new List<int>();
        int lowest = 6;
        Random dice = new Random();

        for (int i = 0; i < 4; i++)
        {
            int roll = (int)dice.NextInt64(1, 6);
            if (roll < lowest)
            {
                lowest = roll;
            }
            rolls.Insert(i, roll);
        }

        rolls.Remove(lowest);
        return rolls.Sum();
    }

I plan on refactoring later

and these are some test results

Assert.InRange() Failure
Range:  (200 - 300)
Actual: 554

Assert.InRange() Failure
Range:  (200 - 300)
Actual: 540

Assert.InRange() Failure
Range:  (200 - 300)
Actual: 527

I don't know how to make sure I land in the Distribution range required.

Exercism

Can you solve D&D Character in C#? Improve your C# skills with support from our world-class team of mentors.

nova wave
#

Is the whole lowest = 6 and then insert and remove is just for picking the highest 3 dice? This could be improved a bit

fervent quail
fervent quail