Guest User

Untitled

a guest
Dec 5th, 2019
187
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using NUnit.Framework;
  2. //using FightingArena;
  3.  
  4. namespace Tests
  5. {
  6.     using FightingArena;
  7.     using System;
  8.  
  9.     public class WarriorTests
  10.     {
  11.         [SetUp]
  12.         public void Setup()
  13.         {
  14.         }
  15.  
  16.         /*
  17.             • Name cannot be null, empty or whitespace.
  18.             • Damage cannot be zero or negative.
  19.             • HP cannot be negative.
  20.             • Warrior cannot attack if his HP are below 30.
  21.             • Warrior cannot attack Warriors which HP are below 30.
  22.             • Warrior cannot attack stronger enemies.
  23.          */
  24.  
  25.         [Test]
  26.         public void Warrior_Constructor()
  27.         {
  28.             Warrior warrior = new Warrior("ABC", 25, 50);
  29.             var expectedName = "ABC";
  30.             var expectedDmg = 25;
  31.             var expectedHp = 50;
  32.             Assert.AreEqual(expectedName, warrior.Name);
  33.             Assert.AreEqual(expectedDmg, warrior.Damage);
  34.             Assert.AreEqual(expectedHp, warrior.HP);
  35.         }
  36.  
  37.         [Test]
  38.         [TestCase("")]
  39.         [TestCase(" ")]
  40.         [TestCase("  ")]
  41.         [TestCase("   ")]
  42.         [TestCase(null)]
  43.         public void WarriorTest_ArguemtException_NameNullEmptyOrWhiteSpace(string name)
  44.         {
  45.             Assert.Throws<ArgumentException>
  46.                 (() => new Warrior(name, 6, 6));
  47.         }
  48.  
  49.         [Test]
  50.         [TestCase(-1)]
  51.         [TestCase(0)]
  52.         [TestCase(-11)]
  53.         [TestCase(-22)]
  54.         public void WarriorTest_ArguemtException_DamageZeroOrNegative(int damage)
  55.         {
  56.             Assert.Throws<ArgumentException>
  57.                 (() => new Warrior("Bai Ivan", damage, 6));
  58.         }
  59.  
  60.         [Test]
  61.         [TestCase(-1)]
  62.         [TestCase(-2)]
  63.         [TestCase(-11)]
  64.         [TestCase(-22)]
  65.         public void WarriorTest_ArguemtException_HpNegative(int hp)
  66.         {
  67.             Assert.Throws<ArgumentException>
  68.                 (() => new Warrior("Bai Ivan", 11, hp));
  69.         }
  70.  
  71.         [Test]
  72.         [TestCase(28)]
  73.         [TestCase(29)]
  74.         [TestCase(20)]
  75.         [TestCase(10)]
  76.         [TestCase(30)]
  77.         public void WarriorTest_ArguemtException_WarriorCantAttackWithLessThan30Hp(int hp)
  78.         {
  79.             Warrior attacker = new Warrior("Bai Ivan", 10, hp);
  80.             Warrior defender = new Warrior("Bai Pesho", 10, 40);
  81.  
  82.             Assert.Throws<InvalidOperationException>
  83.                 (() => attacker.Attack(defender));
  84.  
  85.             Assert.Throws<InvalidOperationException>
  86.                 (() => attacker.Attack(defender));
  87.         }
  88.  
  89.         [Test]
  90.         [TestCase(28)]
  91.         [TestCase(29)]
  92.         [TestCase(20)]
  93.         [TestCase(10)]
  94.         [TestCase(30)]
  95.         public void WarriorTest_ArguemtException_WarriorCantBeAttackedWhenLessThan30Hp(int hp)
  96.         {
  97.             Warrior attacker = new Warrior("Bai Ivan", 10, 40);
  98.             Warrior defender = new Warrior("Bai Pesho", 10, hp);
  99.  
  100.             Assert.Throws<InvalidOperationException>
  101.                 (() => attacker.Attack(defender));
  102.         }
  103.  
  104.         [Test]
  105.         [TestCase(58)]
  106.         [TestCase(59)]
  107.         [TestCase(50)]
  108.         [TestCase(41)]
  109.         public void WarriorTest_ArguemtException_AtackingStrongerOpponent(int dmg)
  110.         {
  111.             Warrior attacker = new Warrior("Bai Ivan", 10, 40);
  112.             Warrior defender = new Warrior("Bai Pesho", dmg, 40);
  113.  
  114.             Assert.Throws<InvalidOperationException>
  115.                 (() => attacker.Attack(defender));
  116.         }
  117.  
  118.         [Test]
  119.         [TestCase(22, 40)]
  120.         [TestCase(49, 40)]
  121.         [TestCase(50, 40)]
  122.         public void WarriorTest_Atacks_Correctly(int dmg, int hp)
  123.         {
  124.             Warrior attacker = new Warrior("Bai Ivan", dmg, hp);
  125.             Warrior defender = new Warrior("Bai Pesho", 20, 50);
  126.  
  127.             attacker.Attack(defender);
  128.  
  129.             int expected = 50 - dmg;
  130.             int actual = defender.HP;
  131.  
  132.             Assert.AreEqual(expected, actual);
  133.         }
  134.        
  135.         [Test]
  136.         [TestCase(51, 40)]
  137.         [TestCase(52, 40)]
  138.         [TestCase(120, 40)]
  139.         public void WarriorTest_Atacks_Correctly_WithMoreDamage(int dmg, int hp)
  140.         {
  141.             Warrior attacker = new Warrior("Bai Ivan", dmg, hp);
  142.             Warrior defender = new Warrior("Bai Pesho", 20, 50);
  143.  
  144.             attacker.Attack(defender);
  145.  
  146.             int expected = 0;
  147.             int actual = defender.HP;
  148.  
  149.             Assert.AreEqual(expected, actual);
  150.         }
  151.     }
  152. }
RAW Paste Data