Add Tests for Utils.Modulo

This commit is contained in:
2023-04-26 19:29:12 +02:00
parent ee5bda2fe3
commit 6b6aba1073
2 changed files with 18 additions and 1 deletions

View File

@ -81,8 +81,11 @@ namespace Elwig.Helpers {
}
public static int Modulo(string a, int b) {
if (!a.All(char.IsDigit))
if (a.Length == 0 || !a.All(char.IsDigit)) {
throw new ArgumentException("First argument has to be a decimal string");
} else if (b < 2) {
throw new ArgumentException("Second argument has to be greater than 1");
}
return a.Select(ch => ch - '0').Aggregate((sum, n) => (sum * 10 + n) % b);
}