public void Execute() { var numbers = new[] { 1, 2, 3, 4, 5 }; // // Sum拡張メソッドは、文字通り合計を求める拡張メソッド。 // // Sum拡張メソッドには、各基本型のオーバーロードが用意されており // (decimal, double, int, long, single及びそれぞれのNullable型) // それぞれに、引数無しとselectorを指定するバージョンのメソッドがある。 // // // 引数無しのSum拡張メソッドの使用. // Output.WriteLine("引数無し = {0}", numbers.Sum()); // // selectorを指定するSum拡張メソッドの使用. // Output.WriteLine("引数有り = {0}", numbers.Sum(item => item%2 == 0 ? item : 0)); }
public void TestDistribute() { var values = new [] {10d, 70d, 1d}.Distribute(100); Assert.AreEqual(100, values.Sum()); values = new[] { 1d, 1d, 1d }.Distribute(100); Assert.AreEqual(100, values.Sum()); values = new[] { 10d }.Distribute(100); Assert.AreEqual(100, values.Sum()); values = new[] { 100d, 200d }.Distribute(100); Assert.AreEqual(100, values.Sum()); }
public void When_laird_is_defeated_then_all_kobolds_in_hall_are_defeated() { // Arrange var context = new TestContext(); var player = context.Player; var laird = context.CreateCard<KoboldHumanoid>("Drakeclan Laird"); var ambusher = context.CreateCard<KoboldHumanoid>("Drakeclan Ambusher"); var cutter = context.CreateCard<KoboldHumanoid>("Drakeclan Cutter"); var shaman = context.CreateCard<KoboldHumanoid>("Drakeclan Shaman"); var kobolds = new[] {laird, ambusher, cutter, shaman}; context.SetTopOfDungeonDeck(kobolds); context.AdvanceMonsterToFirstRank(laird); var hand = Enumerable.Range(0, 6).Select(x => context.CreateCard<Criochan>("Criochan Captain")).ToArray(); context.SetPlayerHand(hand); var startingXp = player.Xp; var startingVp = player.Vp; // Act context.WhenBattling(laird); player.DetermineBattleResult(); // Assert kobolds.Each(x => Assert.That(player.Discard.Contains(x), "Discard does not contain {0}".Template(x.Name))); context.Game.Dungeon.Ranks.Each(r=> Assert.That(r.Card, Is.Not.Null, "Rank {0} is empty".Template(r.Number))); kobolds.Each(x => Assert.That(context.Game.Dungeon.Ranks.All(rank => rank.Card != x))); Assert.That(player.Xp, Is.EqualTo(startingXp + laird.Xp)); Assert.That(player.Vp, Is.EqualTo(startingVp + kobolds.Sum(x => x.Vp))); }
public void GetScore_MultipleFrames_Strike_ShouldReturnSumPlusSumOfTwoBallsAfterStrike() { // Arrange var bowlSequence = new[] { 10, 4, 3 }; GivenBowlSequence(bowlSequence); // Act var score = game.GetScore(); // Assert score.Should().Be(bowlSequence.Sum() + 4 + 3); }
public void GetScore_MultipleFrames_SpareFirstFrame_ShouldReturnSumPlusFirstBallAfterSpare() { // Arrange var bowlSequence = new[] { 4, 6, 4, 3 }; GivenBowlSequence(bowlSequence); // Act var score = game.GetScore(); // Assert score.Should().Be(bowlSequence.Sum() + 4); }
public void GetScore_MultipleFrames_FourthAndFifthBallAddUpToTenButNoSparesOrStrikes_ShouldReturnSum() { // Arrange var bowlSequence = new[] { 3, 6, 4, 3, 7, 2 }; GivenBowlSequence(bowlSequence); // Act var score = game.GetScore(); // Assert score.Should().Be(bowlSequence.Sum()); }
public void GetScore_MultipleFramesPinsDownLessThanTenEachFrame_ShouldReturnSumOfPinsDown() { // Arrange var bowlSequence = new[] {4, 5, 4, 3}; GivenBowlSequence(bowlSequence); // Act var score = game.GetScore(); // Assert score.Should().Be(bowlSequence.Sum()); }
public void MultipleFramesIncludingASpare_GetScore_ShouldReturnSumOfPinsDownPlusBowlAfterSpare() { // Arrange var bowlSequence = new[] { 6, 4, 4, 4 }; RunBowlSequence(bowlSequence); // Act var score = game.GetScore(); // Assert score.Should().Be(bowlSequence.Sum() + 4); }
public void MultipleFramesButNeverAllPinsDown_GetScoreShouldReturnSumOfPinsDown() { // Arrange var bowlSequence = new[] {4, 4, 4, 4}; RunBowlSequence(bowlSequence); // Act var score = game.GetScore(); // Assert score.Should().Be(bowlSequence.Sum()); }
public void MultipleFrameFoolsSpareStraddlingFrames_GetScore_ShouldReturnSumOfPinsDown() { // Arrange var bowlSequence = new[] { 4, 4, 6, 4 }; RunBowlSequence(bowlSequence); // Act var score = game.GetScore(); // Assert score.Should().Be(bowlSequence.Sum()); }