Im trying to test for various bad test inputs to the FromRomanMethod but I just don't get C# syntax and way of doing it since I come from a Python background and not as strictly typed. Can I do everything from the test method or do I have to implement some logic check in the main code? This is not homework, simply taking on various challenges to learn coding.
My first thought was to just compare expected and actual for those test methods but i assume that it would just throw exception for those tested inlinedata and not all bad roman values?
Main code -> https://pastebin.com/xBMEHhWD
private Dictionary<char, int> fromRomanDict = new Dictionary<char, int>
{
{ 'I', 1 },
{ 'V', 5 },
{ 'X', 10 },
{ 'L', 50 },
{ 'C', 100 },
{ 'D', 500 },
{ 'M', 1000 }
};
/*Iterate over each character in the string that is passed*/
public int FromRomanMethod(string romanNumber)
{
if (string.IsNullOrEmpty(romanNumber))
throw new ArgumentException("Invalid input");
romanNumber = romanNumber.ToUpper();/*Make all roman characters uppercase*/
int number = 0;
for (int i = 0; i < romanNumber.Length; i++)
{
if(i + 1 < romanNumber.Length && fromRomanDict[romanNumber[i]] < romanNumber[i + 1])
{
number -= fromRomanDict[romanNumber[i]];
}
number += fromRomanDict[romanNumber[i]];
}
return number;
}
Test --> https://pastebin.com/UByNCF6K
[Fact]
public void Test_Null()
{
Assert.Throws<ArgumentException>(() => sut.FromRomanMethod(null));
}
[Theory]
[InlineData("CMCM"]
[InlineData("CDCD"]
[InlineData("XCXC"]
[InlineData("XLXL"]
[InlineData("IXIX"]
[InlineData("IVIV"]
public void Test_Repeated_Pairs(string expected, string actual)
{
}
Aucun commentaire:
Enregistrer un commentaire