2020-08-08 22:24:01 +02:00
|
|
|
using Geekbot.Core.DiceParser;
|
2020-09-23 16:05:43 +02:00
|
|
|
using Geekbot.Core.GlobalSettings;
|
2020-08-08 22:24:01 +02:00
|
|
|
using Geekbot.Core.RandomNumberGenerator;
|
2020-09-23 16:05:43 +02:00
|
|
|
using Moq;
|
2020-06-21 15:49:18 +02:00
|
|
|
using Xunit;
|
|
|
|
|
2020-08-08 22:24:01 +02:00
|
|
|
namespace Tests.Core.DiceParser
|
2020-06-21 15:49:18 +02:00
|
|
|
{
|
|
|
|
public class SingleDieTest
|
|
|
|
{
|
|
|
|
public struct SingleDieNameTestDto
|
|
|
|
{
|
|
|
|
public DieAdvantageType AdvantageType { get; set; }
|
|
|
|
public string Expected { get; set; }
|
|
|
|
}
|
|
|
|
|
|
|
|
public static TestData<SingleDieNameTestDto> SingleDieNameTestData => new TestData<SingleDieNameTestDto>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
"No advantage",
|
|
|
|
new SingleDieNameTestDto()
|
|
|
|
{
|
|
|
|
AdvantageType = DieAdvantageType.None,
|
|
|
|
Expected = "1d20"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"With advantage",
|
|
|
|
new SingleDieNameTestDto()
|
|
|
|
{
|
|
|
|
AdvantageType = DieAdvantageType.Advantage,
|
|
|
|
Expected = "1d20 (with advantage)"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"With disadvantage",
|
|
|
|
new SingleDieNameTestDto()
|
|
|
|
{
|
|
|
|
AdvantageType = DieAdvantageType.Disadvantage,
|
|
|
|
Expected = "1d20 (with disadvantage)"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
[Theory, MemberData(nameof(SingleDieNameTestData))]
|
|
|
|
public void SingleDieNameTestFunc(string testName, SingleDieNameTestDto testData)
|
|
|
|
{
|
2021-09-17 14:03:35 +02:00
|
|
|
var die = new SingleDie(new RandomNumberGenerator()) {AdvantageType = testData.AdvantageType};
|
2020-06-21 15:49:18 +02:00
|
|
|
Assert.Equal(die.DiceName, testData.Expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
public struct SingleDieValidationTestDto
|
|
|
|
{
|
|
|
|
public int Sides { get; set; }
|
|
|
|
public int Amount { get; set; }
|
|
|
|
public bool PassValidation { get; set; }
|
|
|
|
}
|
|
|
|
|
|
|
|
public static TestData<SingleDieValidationTestDto> SingleDieValidationTestData => new TestData<SingleDieValidationTestDto>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
"To many sides",
|
|
|
|
new SingleDieValidationTestDto()
|
|
|
|
{
|
|
|
|
Amount = 1,
|
|
|
|
Sides = 200,
|
|
|
|
PassValidation = false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"To few sides",
|
|
|
|
new SingleDieValidationTestDto()
|
|
|
|
{
|
|
|
|
Amount = 1,
|
|
|
|
Sides = 1,
|
|
|
|
PassValidation = false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"To many Dice",
|
|
|
|
new SingleDieValidationTestDto()
|
|
|
|
{
|
|
|
|
Amount = 200,
|
|
|
|
Sides = 20,
|
|
|
|
PassValidation = false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"To few Dice",
|
|
|
|
new SingleDieValidationTestDto()
|
|
|
|
{
|
|
|
|
Amount = 0,
|
|
|
|
Sides = 20,
|
|
|
|
PassValidation = false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Correct Dice",
|
|
|
|
new SingleDieValidationTestDto()
|
|
|
|
{
|
|
|
|
Amount = 1,
|
|
|
|
Sides = 20,
|
|
|
|
PassValidation = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
[Theory, MemberData(nameof(SingleDieValidationTestData))]
|
|
|
|
public void SingleDieValidationTestFunc(string testName, SingleDieValidationTestDto testData)
|
|
|
|
{
|
2021-09-17 14:03:35 +02:00
|
|
|
var die = new SingleDie(new RandomNumberGenerator())
|
2020-06-21 15:49:18 +02:00
|
|
|
{
|
|
|
|
Amount = testData.Amount,
|
|
|
|
Sides = testData.Sides
|
|
|
|
};
|
|
|
|
|
|
|
|
if (testData.PassValidation)
|
|
|
|
{
|
|
|
|
die.ValidateDie();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Assert.Throws<DiceException>(() => die.ValidateDie());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|