Browse files

Merge branch 'master' of github.com:jasonyandell/Kata

Conflicts:
	.gitignore
  • Loading branch information...
2 parents a29a8f8 + 2a79df4 commit c83e4a402fc2242390391b951080116d7b50d8f7 @CShrock CShrock committed Oct 4, 2011
Showing with 339 additions and 102 deletions.
  1. +17 −1 .gitignore
  2. +2 −0 BowlingScore/.gitignore
  3. +0 −23 BowlingScore/BowlingScore.5.1.ReSharper.user
  4. BIN BowlingScore/BowlingScore.suo
  5. +0 −70 BowlingScore/BowlingScore/BowlingScore.cs
  6. +7 −1 BowlingScore/BowlingScore/BowlingScore.csproj
  7. +75 −0 BowlingScore/BowlingScore/BowlingScorer.cs
  8. +90 −0 BowlingScore/BowlingScore/BowlingTests.cs
  9. +15 −0 BowlingScore/BowlingScore/BowlingTestsCourt.cs
  10. +15 −0 BowlingScore/BowlingScore/BowlingTestsJason.cs
  11. +12 −0 BowlingScore/BowlingScore/IBowlingScorer.cs
  12. +12 −0 BowlingScore/BowlingScore/IScorer.cs
  13. +94 −0 BowlingScore/BowlingScore/JBowlingScorer.cs
  14. BIN BowlingScore/BowlingScore/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
  15. +0 −1 BowlingScore/_ReSharper.BowlingScore/BuildScriptCache/.crc
  16. BIN BowlingScore/_ReSharper.BowlingScore/BuildScriptCache/.version
  17. BIN BowlingScore/_ReSharper.BowlingScore/BuildScriptCache/8/76f55a5e.dat
  18. +0 −3 BowlingScore/_ReSharper.BowlingScore/ModuleIds.xml
  19. +0 −1 BowlingScore/_ReSharper.BowlingScore/NamedArguments/.crc
  20. BIN BowlingScore/_ReSharper.BowlingScore/NamedArguments/.version
  21. BIN BowlingScore/_ReSharper.BowlingScore/NamedArguments/8/76f55a5e.dat
  22. BIN BowlingScore/_ReSharper.BowlingScore/ProjectModel/ProjectModel.dat
  23. BIN BowlingScore/_ReSharper.BowlingScore/Resources/.crc
  24. BIN BowlingScore/_ReSharper.BowlingScore/Resources/.version
  25. BIN BowlingScore/_ReSharper.BowlingScore/SymbolCache.bin
  26. BIN BowlingScore/_ReSharper.BowlingScore/TagPrefixes/.crc
  27. BIN BowlingScore/_ReSharper.BowlingScore/TagPrefixes/.version
  28. +0 −1 BowlingScore/_ReSharper.BowlingScore/TodoCache/.crc
  29. BIN BowlingScore/_ReSharper.BowlingScore/TodoCache/.version
  30. BIN BowlingScore/_ReSharper.BowlingScore/TodoCache/8/76f55a5e.dat
  31. BIN BowlingScore/_ReSharper.BowlingScore/WebsiteFileReferences/.crc
  32. BIN BowlingScore/_ReSharper.BowlingScore/WebsiteFileReferences/.version
  33. +0 −1 BowlingScore/_ReSharper.BowlingScore/WordIndex/.crc
  34. BIN BowlingScore/_ReSharper.BowlingScore/WordIndex/.version
  35. BIN BowlingScore/_ReSharper.BowlingScore/WordIndex/8/76f55a5e.dat
View
18 .gitignore
@@ -1,4 +1,20 @@
/BowlingScore/TestResults
/BowlingScore/BowlingScore/obj
-/BowlingScore/BowlingScore/bin
+/BowlingScore/BowlingScore/bin
+[Oo]bj
+[Bb]in
+*.user
+*.suo
+*.[Cc]ache
+*.bak
+*.ncb
+*.log
+*.DS_Store
+[Tt]humbs.db
+_ReSharper.*
+*.resharper
+Ankh.NoLoad
+*.svn
+TestResults
+/Development/StaticSite/DiyPinkFloyd/DiyPinkFloyd.Publish.xml
View
2 BowlingScore/.gitignore
@@ -0,0 +1,2 @@
+
+*.suo
View
23 BowlingScore/BowlingScore.5.1.ReSharper.user
@@ -1,23 +0,0 @@
-<Configuration>
- <SettingsComponent>
- <string />
- <integer />
- <boolean>
- <setting name="SolutionAnalysisEnabled">False</setting>
- </boolean>
- </SettingsComponent>
- <RecentFiles>
- <RecentFiles />
- <RecentEdits />
- </RecentFiles>
- <NAntValidationSettings>
- <NAntPath value="" />
- </NAntValidationSettings>
- <UnitTestRunner>
- <Providers />
- </UnitTestRunner>
- <UnitTestRunnerNUnit>
- <NUnitInstallDir>C:\Program Files (x86)\NUnit 2.5.2\bin\net-2.0\</NUnitInstallDir>
- <UseAddins>Never</UseAddins>
- </UnitTestRunnerNUnit>
-</Configuration>
View
BIN BowlingScore/BowlingScore.suo
Binary file not shown.
View
70 BowlingScore/BowlingScore/BowlingScore.cs
@@ -1,70 +0,0 @@
-using System;
-using System.Text;
-using System.Collections.Generic;
-using System.Linq;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-namespace BowlingScore
-{
- /// <summary>
- /// Summary description for UnitTest1
- /// </summary>
- [TestClass]
- public class UnitTest1
- {
- public UnitTest1()
- {
- //
- // TODO: Add constructor logic here
- //
- }
-
- private TestContext testContextInstance;
-
- /// <summary>
- ///Gets or sets the test context which provides
- ///information about and functionality for the current test run.
- ///</summary>
- public TestContext TestContext
- {
- get
- {
- return testContextInstance;
- }
- set
- {
- testContextInstance = value;
- }
- }
-
- #region Additional test attributes
- //
- // You can use the following additional attributes as you write your tests:
- //
- // Use ClassInitialize to run code before running the first test in the class
- // [ClassInitialize()]
- // public static void MyClassInitialize(TestContext testContext) { }
- //
- // Use ClassCleanup to run code after all tests in a class have run
- // [ClassCleanup()]
- // public static void MyClassCleanup() { }
- //
- // Use TestInitialize to run code before running each test
- // [TestInitialize()]
- // public void MyTestInitialize() { }
- //
- // Use TestCleanup to run code after each test has run
- // [TestCleanup()]
- // public void MyTestCleanup() { }
- //
- #endregion
-
- [TestMethod]
- public void TestMethod1()
- {
- //
- // TODO: Add test logic here
- //
- }
- }
-}
View
8 BowlingScore/BowlingScore/BowlingScore.csproj
@@ -45,8 +45,14 @@
</CodeAnalysisDependentAssemblyPaths>
</ItemGroup>
<ItemGroup>
+ <Compile Include="BowlingScorer.cs" />
+ <Compile Include="BowlingTests.cs" />
+ <Compile Include="BowlingTestsCourt.cs" />
+ <Compile Include="BowlingTestsJason.cs" />
+ <Compile Include="JBowlingScorer.cs" />
+ <Compile Include="IBowlingScorer.cs" />
+ <Compile Include="IScorer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
- <Compile Include="UnitTest1.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
View
75 BowlingScore/BowlingScore/BowlingScorer.cs
@@ -0,0 +1,75 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace BowlingScore
+{
+ public class BowlingScorer : IBowlingScorer
+ {
+ /*
+ protected string input;
+ protected int[] scores = new int[10];
+
+ protected IEnumerable<char[]> FrameScores
+ {
+ get {
+ int s = 0;
+ char[] frame = new char[3];
+ for (int f = 0; f < input.Length; f++) {
+ frame[s] = input[f];
+ if (frame[s]
+ }
+ }
+ }
+
+ public int Score(string input)
+ {
+ char t = input[0];
+
+ if (char.ToUpper(t) != 'X')
+
+ string frame = string.Format("{0}", t, );
+ }
+
+ public int ScoreFrame()
+ {
+ return 0;
+ }
+ */
+
+ public int Score(string input)
+ {
+ List<string> frames = new List<string>();
+ string frame = string.Empty;
+
+ for (int f = 0; f < input.Length; f++) {
+ char t = input[f];
+ frame += t;
+ if (char.ToUpper(t) == 'X' || char.ToUpper(t) == '/') {
+ frames.Add(frame);
+ frame = string.Empty;
+ }
+ }
+ if (frame != string.Empty)
+ frames.Add(frame);
+
+ return frames.Select(f => ScoreFrame(f)).Sum();
+ }
+
+ public static int ScoreFrame(string input)
+ {
+ if (string.IsNullOrEmpty(input)) return 0;
+ char t = input[0];
+ if (char.ToUpper(t) == 'X') {
+ return 10;
+ } else if (char.ToUpper(t) == '/') {
+ return 10;
+ } else {
+ int score = (int)Char.GetNumericValue(t);
+ score += ScoreFrame(input.Substring(1));
+ return score;
+ }
+ }
+ }
+}
View
90 BowlingScore/BowlingScore/BowlingTests.cs
@@ -0,0 +1,90 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace BowlingScore
+{
+ [TestClass]
+ public abstract class BowlingTests
+ {
+ protected IBowlingScorer scorer;
+
+ [TestInitialize]
+ public abstract void TestInitialize();
+
+ [TestMethod]
+ public void can_score_strike()
+ {
+ Assert.AreEqual(10, scorer.Score("X"));
+ }
+
+ [TestMethod]
+ public void can_score_frame_with_gutter()
+ {
+ Assert.AreEqual(5, scorer.Score("5-"));
+ }
+
+ [TestMethod]
+ public void can_score_spare_as_a_single_frame()
+ {
+ Assert.AreEqual(10, scorer.Score("5/"));
+ }
+
+ [TestMethod]
+ public void can_score_mundane_frame()
+ {
+ Assert.AreEqual(7, scorer.Score("25"));
+ }
+
+ [TestMethod]
+ public void can_score_spare_mundane()
+ {
+ Assert.AreEqual(12 + 7, scorer.Score("5/25"));
+ }
+
+ [TestMethod]
+ public void can_score_strike_mundane_mundane()
+ {
+ Assert.AreEqual((10 + 2 + 5) + 7 + 7, scorer.Score("X2525"));
+ }
+
+ [TestMethod]
+ public void can_score_strike_spare_mundane()
+ {
+ Assert.AreEqual((10 + (5 + 5)) + (10 + 2) + 7, scorer.Score("X5/25"));
+ }
+
+ [TestMethod]
+ public void WebSample1()
+ {
+ Assert.AreEqual(300, scorer.Score("XXXXXXXXXXXX"));
+ }
+
+ [TestMethod]
+ public void WebSample2()
+ {
+ Assert.AreEqual(90, scorer.Score("9-9-9-9-9-9-9-9-9-9-"));
+ }
+
+ [TestMethod]
+ public void WebSample3()
+ {
+ Assert.AreEqual(150, scorer.Score("5/5/5/5/5/5/5/5/5/5/5"));
+ }
+
+ [TestMethod]
+ public void WebSample4()
+ {
+ Assert.AreEqual(133, scorer.Score("14456/5/X017/6/X2/6"));
+ }
+
+ [TestMethod]
+ public void WebSample5()
+ {
+ Assert.AreEqual(184, scorer.Score("45X5/XXX450/81XX6"));
+ }
+
+ }
+}
View
15 BowlingScore/BowlingScore/BowlingTestsCourt.cs
@@ -0,0 +1,15 @@
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace BowlingScore
+{
+ [TestClass]
+ public class BowlingTestsCourt : BowlingTests
+ {
+ [TestInitialize]
+ public override void TestInitialize()
+ {
+ scorer = new BowlingScorer();
+ }
+
+ }
+}
View
15 BowlingScore/BowlingScore/BowlingTestsJason.cs
@@ -0,0 +1,15 @@
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace BowlingScore
+{
+ [TestClass]
+ public class BowlingTestsJason : BowlingTests
+ {
+ [TestInitialize]
+ public override void TestInitialize()
+ {
+ scorer = new JBowlingScorer();
+ }
+
+ }
+}
View
12 BowlingScore/BowlingScore/IBowlingScorer.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace BowlingScore
+{
+ public interface IBowlingScorer : IScorer
+ {
+ int Score(string input);
+ }
+}
View
12 BowlingScore/BowlingScore/IScorer.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace BowlingScore
+{
+ public interface IScorer
+ {
+
+ }
+}
View
94 BowlingScore/BowlingScore/JBowlingScorer.cs
@@ -0,0 +1,94 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace BowlingScore
+{
+ public class JBowlingScorer : IBowlingScorer
+ {
+ protected int[] scores = new int[10];
+
+ public int SimpleValue(string input, int index)
+ {
+ if (index < 0) return 0;
+ if (index >= input.Length) return 0;
+
+ var ch = input[index];
+
+ switch (ch)
+ {
+ case 'X':
+ return 10;
+ case '/':
+ return 10 - SimpleValue(input, index - 1);
+ case '-':
+ return 0;
+ default:
+ if ("0123456789".Contains(ch))
+ {
+ return "0123456789".IndexOf(ch);
+ }
+ throw new ArgumentException("Cannot parse "+ch, "input");
+ }
+ }
+
+ public int Value(string input, int index)
+ {
+ if (index < 0) return 0;
+ if (index >= input.Length) return 0;
+
+ var ch = input[index];
+
+ switch (ch)
+ {
+ case 'X':
+ return SimpleValue(input, index) + SimpleValue(input, index + 1) + SimpleValue(input, index + 2);
+ case '/':
+ return SimpleValue(input, index) + SimpleValue(input, index + 1);
+ case '-':
+ return SimpleValue(input, index);
+ default:
+ return SimpleValue(input, index);
+ }
+ }
+
+ public int LastFrameIndex(string input)
+ {
+ // there will be no more than 10 frames
+ if (input.Length < 11) return input.Length;
+
+ int frameCount = 0;
+ int counter = 0;
+ for (int i = 0; i < input.Length; ++i)
+ {
+ var ch = input[i];
+
+ if ((ch == 'X') || (++counter == 2))
+ {
+ frameCount++;
+ counter = 0;
+ }
+
+ if (frameCount == 10)
+ return i+1;
+ }
+ return input.Length;
+ }
+
+ public int Score(string input)
+ {
+ var results = new List<KeyValuePair<char, int>>();
+
+ var total = 0;
+ var lastFrameIndex = LastFrameIndex(input);
+ for(int i = 0; i < lastFrameIndex; ++i)
+ {
+ var val = Value(input, i);
+ results.Add(new KeyValuePair<char, int>(input[i], val));
+ total += val;
+ }
+ return total;
+ }
+ }
+}
View
BIN BowlingScore/BowlingScore/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
Binary file not shown.
View
1 BowlingScore/_ReSharper.BowlingScore/BuildScriptCache/.crc
@@ -1 +0,0 @@
-k? .
View
BIN BowlingScore/_ReSharper.BowlingScore/BuildScriptCache/.version
Binary file not shown.
View
BIN BowlingScore/_ReSharper.BowlingScore/BuildScriptCache/8/76f55a5e.dat
Binary file not shown.
View
3 BowlingScore/_ReSharper.BowlingScore/ModuleIds.xml
@@ -1,3 +0,0 @@
-<Modules>
- <Module PersistentId="923A5AFF-AC1C-4CAA-AE91-4FF157AD9415" ModuleId="BowlingScore" />
-</Modules>
View
1 BowlingScore/_ReSharper.BowlingScore/NamedArguments/.crc
@@ -1 +0,0 @@
-,??o
View
BIN BowlingScore/_ReSharper.BowlingScore/NamedArguments/.version
Binary file not shown.
View
BIN BowlingScore/_ReSharper.BowlingScore/NamedArguments/8/76f55a5e.dat
Binary file not shown.
View
BIN BowlingScore/_ReSharper.BowlingScore/ProjectModel/ProjectModel.dat
Binary file not shown.
View
BIN BowlingScore/_ReSharper.BowlingScore/Resources/.crc
Binary file not shown.
View
BIN BowlingScore/_ReSharper.BowlingScore/Resources/.version
Binary file not shown.
View
BIN BowlingScore/_ReSharper.BowlingScore/SymbolCache.bin
Binary file not shown.
View
BIN BowlingScore/_ReSharper.BowlingScore/TagPrefixes/.crc
Binary file not shown.
View
BIN BowlingScore/_ReSharper.BowlingScore/TagPrefixes/.version
Binary file not shown.
View
1 BowlingScore/_ReSharper.BowlingScore/TodoCache/.crc
@@ -1 +0,0 @@
-????
View
BIN BowlingScore/_ReSharper.BowlingScore/TodoCache/.version
Binary file not shown.
View
BIN BowlingScore/_ReSharper.BowlingScore/TodoCache/8/76f55a5e.dat
Binary file not shown.
View
BIN BowlingScore/_ReSharper.BowlingScore/WebsiteFileReferences/.crc
Binary file not shown.
View
BIN BowlingScore/_ReSharper.BowlingScore/WebsiteFileReferences/.version
Binary file not shown.
View
1 BowlingScore/_ReSharper.BowlingScore/WordIndex/.crc
@@ -1 +0,0 @@
-?<?f
View
BIN BowlingScore/_ReSharper.BowlingScore/WordIndex/.version
Binary file not shown.
View
BIN BowlingScore/_ReSharper.BowlingScore/WordIndex/8/76f55a5e.dat
Binary file not shown.

0 comments on commit c83e4a4

Please sign in to comment.