public void PlayMatch() { var leg = new SinglePlayerLeg(126) // Turn #1 .WithAdditionalThrow(ThrowResult.Triple(20)) .WithAdditionalThrow(ThrowResult.Double(20)) .WithAdditionalThrow(ThrowResult.Single(20)) // Score = 6 // Turn #2 .WithAdditionalThrow(ThrowResult.Outside) .WithAdditionalThrow(ThrowResult.Outside) .WithAdditionalThrow(ThrowResult.Outside) // Turn #3. Bust! Not double! .WithAdditionalThrow(ThrowResult.Triple(2)) // Turn #4. Bust! Too many! .WithAdditionalThrow(ThrowResult.InnerBull) // Turn #5. Bust! Can't leave 1. .WithAdditionalThrow(ThrowResult.Single(5)) // Turn #6. Finished .WithAdditionalThrow(ThrowResult.Double(3)); Assert.AreEqual(6, leg.Turns.Count); Assert.AreEqual(0, leg.Score); }
public void Finish_IfOnlyOneHasNonZeroScore() { var leg = new Leg("id", 20); leg.AddThrow(ThrowResult.Triple(20)); //0 bust! leg.AddThrow(ThrowResult.Double(10)); //1 finished Assert.IsTrue(leg.Finished); Assert.AreEqual(1, leg.WinnerIndex); }
public void BeSerializable() { var leg = new Leg("1", 20); leg.AddThrow(ThrowResult.Single(10)); //#1 leg.AddThrow(ThrowResult.Triple(20)); //#1 bust! leg.AddThrow(ThrowResult.Double(10)); //#2 finished var text = JsonConvert.SerializeObject(leg, Formatting.Indented, new ThrowJsonConverter()); Console.WriteLine(text); var deserialized = JsonConvert.DeserializeObject <Leg>(text, new ThrowJsonConverter()); var text2 = JsonConvert.SerializeObject(deserialized, Formatting.Indented, new ThrowJsonConverter()); Console.WriteLine(text2); Assert.AreEqual(text, text2); }