public void ShouldCalculateDoubleDamageTenPercentOfTheTime() { // Arrange var random = new Model.Random(); var sut = new Human(random); sut.Strength = 0; // Action int cntDblDmg = 0; for (int i = 0; i < 10000; i++) { int dmg = sut.CalculateDamage(); if (dmg != 1) { cntDblDmg++; } } var actual = cntDblDmg; // Assert var expected = 1000; var variance = 50; Assert.That(actual, Is.EqualTo(expected).Within(variance)); }
public void ShouldReportATie() { // Arrange var sut = new Battle(); var random = new Model.Random(); var creature1 = new TestCreature(random) { Damage = 10 }; var creature2 = new TestCreature(random) { Damage = 10 }; sut.AddCreature(creature1); sut.AddCreature(creature2); // Action sut.Duel(0, 1); // Assert var actual = sut.Messages.Last <string>(); var expected = "The battle between creatures 1 and 2, the TestCreature and the TestCreature, was a draw."; Assert.That(actual, Is.EqualTo(expected)); }
public void ShouldReportThatCreature2WonTheDuel() { // Arrange var sut = new Battle(); var random = new Model.Random(); var creature1 = new TestCreature(random) { Damage = 1 }; var creature2 = new TestCreature(random) { Damage = 10 }; sut.AddCreature(creature1); sut.AddCreature(creature2); // Action sut.Duel(0, 1); // Assert var actual = sut.Messages.Last <string>(); var expected = "Creature 2, the TestCreature, was victorious! Creature 1, the TestCreature, was defeated."; Assert.That(actual, Is.EqualTo(expected)); }
public void ShouldCalculateNormalDamageSeventyFivePercentOfTheTime() { // Arrange var random = new Model.Random(); var sut = new DummyDemon(random); sut.Strength = 0; // Action int cntDmg = 0; for (int i = 0; i < 10000; i++) { int dmg = sut.CalculateDamage(); if (dmg == 1) { cntDmg++; } } var actual = cntDmg; // Assert var expected = 7500; var variance = 50; Assert.That(actual, Is.EqualTo(expected).Within(variance)); }
public void ShouldHaveANintyNinePercentChanceOfTakingSomeDamage() { // Arrange var random = new Model.Random(); var sut = new Model.DummyCreature(random); // Action int cntDmg = 0; for (int i = 0; i < 10000; i++) { int dmg = sut.TakeDamage(10); if (dmg == 10) { cntDmg++; } } var actual_cntDmg = cntDmg; // Assert var expected_cntDmg = 9900; var variance = 15; Assert.That(actual_cntDmg, Is.EqualTo(expected_cntDmg).Within(variance)); }
static void Main(string[] args) { Battle battle = new Battle(); Model.Random random = new Model.Random(); int winner = int.MaxValue; // Maps duels results to the number of times that result occured. Dictionary <int, int> winners = new Dictionary <int, int>(); winners.Add(-1, 0); // Ties winners.Add(0, 0); // Human wins winners.Add(1, 0); // Balrog wins for (int i = 0; i < NUMBER_OF_TEST_DUELS; i++) { // Make some test creatures to duel Human human = new Human(random); Balrog balrog = new Balrog(random); // Add the creatures battle.AddCreature(human); battle.AddCreature(balrog); // Make the two creatures duel winner = battle.Duel(0, 1); winners[winner] += 1; // Remove the creatures battle.RemoveCreature(1); battle.RemoveCreature(0); // Add duel header Console.WriteLine("Human v. Balrog"); // Print the messages printMessages(battle.Messages); // Clear the message log battle.Messages.Clear(); } printResults(winners); Console.WriteLine("Press [Enter/Return] to Exit"); Console.ReadLine(); }