Guess works (hardcoded 5). Test cases. Int16.Parse() works.

This commit is contained in:
moitoius_cp 2008-01-13 15:28:12 +00:00
parent f64952d8ba
commit 30efcd2bfd
4 changed files with 12 additions and 9 deletions

View file

@ -19,19 +19,19 @@ namespace Cosmos.Shell.Console.Commands
public override void Execute(string param)
{
short num = 5; // TODO: Random Number Generator
short num = 5;
short guess = short.Parse(System.Console.ReadLine());
while (guess != num)
{
if (guess > num)
System.Console.WriteLine("Too High.");
System.Console.WriteLine("Too high.");
else
System.Console.WriteLine("Too Low.");
System.Console.WriteLine("Too low.");
guess = short.Parse(System.Console.ReadLine());
}
System.Console.WriteLine("You Got It!!!!");
System.Console.WriteLine("You got it!!!!");
}
public override void Help()

View file

@ -25,6 +25,8 @@ namespace Cosmos.Shell.Console.Tests
public override void Test()
{
Assert(short.Parse("5") == 5, "short.Parse(\"5\") == 5");
Assert(short.Parse("500") == 500, "short.Parse(\"500\") == 500");
Assert(short.Parse("-500") == -500, "short.Parse(\"-500\") == -500");
}
}
}

View file

@ -27,6 +27,8 @@ namespace Cosmos.Shell.Console.Tests
Assert("ABCDEFG".IndexOf('E') == 4, "\"ABCDEFG\".IndexOf('E') == 4");
Assert("0123456789".IndexOf('5') == 5, "\"0123456789\".IndexOf('5') == 5");
Assert("0123456789"[5] == '5', "\"0123456789\"[5] == '5'");
Assert("a" != "b", "\"a\" != \"b\"");
Assert('a'.ToString() == "a", "'a'.ToString() == \"a\"");
}
}
}

View file

@ -30,25 +30,24 @@ namespace Indy.IL2CPU.IL.CustomImplementations.System {
if (s.Length >= 1)
{
if (s[0] == '+')
z++;
z = 1;
if (s[0] == '-')
{
z++;
z = 1;
neg = true;
}
}
for (int i = z; i < s.Length; i++)
{
Int16 ind = (Int16)digits.IndexOf(digits[i]);
global::System.Console.WriteLine(ind.ToString());
Int16 ind = (Int16)digits.IndexOf(s[i]);
if (ind == -1)
throw new FormatException();
result = (short)((result * 10) + ind);
}
if (neg)
z *= -1;
result *= -1;
return result;
}