From 30efcd2bfda0cdf5cc8304a558560e2c52ec0048 Mon Sep 17 00:00:00 2001 From: moitoius_cp <7bd20ad30720b36bd251fb928c419f8754d57bfcCkJyHhZD> Date: Sun, 13 Jan 2008 15:28:12 +0000 Subject: [PATCH] Guess works (hardcoded 5). Test cases. Int16.Parse() works. --- .../Cosmos/Cosmos.Shell.Console/Commands/GuessCommand.cs | 8 ++++---- source/Cosmos/Cosmos.Shell.Console/Tests/ParseTest.cs | 2 ++ source/Cosmos/Cosmos.Shell.Console/Tests/StringTest.cs | 2 ++ .../CustomImplementations/System/Int16Impl.cs | 9 ++++----- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/source/Cosmos/Cosmos.Shell.Console/Commands/GuessCommand.cs b/source/Cosmos/Cosmos.Shell.Console/Commands/GuessCommand.cs index 9ab2da4c2..b8263f194 100644 --- a/source/Cosmos/Cosmos.Shell.Console/Commands/GuessCommand.cs +++ b/source/Cosmos/Cosmos.Shell.Console/Commands/GuessCommand.cs @@ -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() diff --git a/source/Cosmos/Cosmos.Shell.Console/Tests/ParseTest.cs b/source/Cosmos/Cosmos.Shell.Console/Tests/ParseTest.cs index 747513be1..858b801a1 100644 --- a/source/Cosmos/Cosmos.Shell.Console/Tests/ParseTest.cs +++ b/source/Cosmos/Cosmos.Shell.Console/Tests/ParseTest.cs @@ -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"); } } } diff --git a/source/Cosmos/Cosmos.Shell.Console/Tests/StringTest.cs b/source/Cosmos/Cosmos.Shell.Console/Tests/StringTest.cs index aa5cd77ab..9509a752e 100644 --- a/source/Cosmos/Cosmos.Shell.Console/Tests/StringTest.cs +++ b/source/Cosmos/Cosmos.Shell.Console/Tests/StringTest.cs @@ -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\""); } } } diff --git a/source/Indy.IL2CPU.IL/CustomImplementations/System/Int16Impl.cs b/source/Indy.IL2CPU.IL/CustomImplementations/System/Int16Impl.cs index f71e46d78..9e9a75a62 100644 --- a/source/Indy.IL2CPU.IL/CustomImplementations/System/Int16Impl.cs +++ b/source/Indy.IL2CPU.IL/CustomImplementations/System/Int16Impl.cs @@ -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; }