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 StartNewLeg_AfterLegFinished() { var match = new Match("1", new[] { "p1", "p2" }, 20, 2); match.AddThrow(ThrowResult.Double(10)); match.AddThrow(ThrowResult.Double(10)); Assert.AreEqual(2, match.Legs.Count); Assert.IsTrue(match.CurrentLeg.Finished); }
public void BeSerializable() { var turn = new Turn(301) .WithAdditionalThrow(ThrowResult.Outside) .WithAdditionalThrow(ThrowResult.Single(1)) .WithAdditionalThrow(ThrowResult.Double(2)); var res = JsonConvert.SerializeObject(turn, new ThrowJsonConverter()); Assert.AreEqual(@"{""Throws"":[""0"",""1"",""D2""],""ScoreBefore"":301,""ScoreAfter"":296,""Finished"":true,""Bust"":false}", res, res); var deserialized = JsonConvert.DeserializeObject <Turn>(res, new ThrowJsonConverter()); Assert.AreEqual(turn, deserialized); }
public void BeSerializable() { var match = new Match("1", new[] { "p1", "p2" }, 20, 2); match.AddThrow(ThrowResult.Double(10)); match.AddThrow(ThrowResult.Double(10)); var text = JsonConvert.SerializeObject(match, Formatting.Indented, new ThrowJsonConverter()); Console.WriteLine(text); var deserializedMatch = JsonConvert.DeserializeObject <Match>(text, new ThrowJsonConverter()); var text2 = JsonConvert.SerializeObject(deserializedMatch, Formatting.Indented, new ThrowJsonConverter()); Console.WriteLine(text2); Assert.AreEqual(text, text2); }
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); }