Пишу код
using System;
using System.Text.RegularExpressions;
public class Kata
{
public static string GoodVsEvil(string good, string evil)
{
string shap = @"\s";
string[] _good = (new Regex(shap)).Split(good);
string[] _evil = (new Regex(shap)).Split(evil);
int power_good = 0;
foreach (string s in _good)
{
power_good += Convert.ToInt32(s);
}
int power_evil = 0;
foreach (string s in _evil)
{
power_evil += System.Convert.ToInt32(s);
}
if (power_good > power_evil)
{ return "Battle Result: Good triumphs over Evil"; }
else
if (power_good < power_evil)
{ return "Battle Result: Evil eradicates all trace of Good"; }
return "Battle Result: No victor on this battle field";
}
}
Код тестов
using System;
using NUnit.Framework;
[TestFixture]
public class GoodVsEvil
{
[Test]
public static void EvilShouldWin()
{
Assert.AreEqual("Battle Result: Evil eradicates all trace of Good", Kata.GoodVsEvil("1 1 1 1 1 1", "1 1 1 1 1 1 1"));
}
[Test]
public static void GoodShouldTriumph()
{
Assert.AreEqual("Battle Result: Good triumphs over Evil", Kata.GoodVsEvil("0 0 0 0 0 10", "0 1 1 1 1 0 0"));
}
[Test]
public static void ShouldBeATie()
{
Assert.AreEqual("Battle Result: No victor on this battle field", Kata.GoodVsEvil("1 0 0 0 0 0", "1 0 0 0 0 0 0"));
}
}