diff options
author | uzvkl <dennis.kobert@student.kit.edu> | 2019-05-20 03:00:44 +0200 |
---|---|---|
committer | uzvkl <dennis.kobert@student.kit.edu> | 2019-05-20 03:00:44 +0200 |
commit | d51f315a8da246c3852017b4a1c127a29a43811f (patch) | |
tree | f28fdc31578f4bbd9e3f1fb9a8b2ef9591634670 /DSALib/Auxiliary/Dice.cs | |
parent | ed26623e17e8dfcc036f88cca6de10d5a35697ec (diff) |
Begin Testing
Diffstat (limited to 'DSALib/Auxiliary/Dice.cs')
-rw-r--r-- | DSALib/Auxiliary/Dice.cs | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/DSALib/Auxiliary/Dice.cs b/DSALib/Auxiliary/Dice.cs index b07d47f..0bfabeb 100644 --- a/DSALib/Auxiliary/Dice.cs +++ b/DSALib/Auxiliary/Dice.cs @@ -15,18 +15,20 @@ namespace DSALib.Auxiliary public static int Roll(string input) { var strings = input.ToLower().Split(new[] {'w', 'd'}, 2, StringSplitOptions.RemoveEmptyEntries).ToList(); - var count = Convert.ToInt32(strings[0]); - var d = Convert.ToInt32(strings[0]); + if (strings.Count != 2) - throw new ArgumentException($"{input}: erfüllt nicht die Formatvogaben( Anzahl d Augenzahl)"); + throw new ArgumentException($"{input}: does not satisfy the format requirements( dice count (d|w) die size)"); + + var count = Convert.ToInt32(strings[0]); + var d = Convert.ToInt32(strings[0]); return Roll(count, d); } public static int Roll(int count, int d) { - if (d <= 0) return 0; + if (d <= 0 || count <= 0) return 0; var sum = 0; for (var i = 0; i < Math.Abs(count); i++) |