public void GetByCardTypeAndMaximumDamage_ShouldWorkCorrectly() { //Arrange IArena RA = new RoyaleArena(); Battlecard cd1 = new Battlecard(2, CardType.SPELL, "valq", 14, 5); Battlecard cd2 = new Battlecard(1, CardType.SPELL, "valq", 14, 5); Battlecard cd3 = new Battlecard(4, CardType.SPELL, "valq", 15, 6); Battlecard cd4 = new Battlecard(3, CardType.SPELL, "valq", 15, 7); Battlecard cd5 = new Battlecard(8, CardType.SPELL, "valq", 18, 8); List <Battlecard> expected = new List <Battlecard>() { cd4, cd3, cd2, cd1 }; //Act RA.Add(cd1); RA.Add(cd3); RA.Add(cd2); RA.Add(cd4); RA.Add(cd5); //Assert List <Battlecard> actual = RA .GetByCardTypeAndMaximumDamage(CardType.SPELL, 17) .ToList(); CollectionAssert.AreEqual(expected, actual); }
public void GetByCardTypeAndMaximumDamage_ShouldWorkCorrectly_AfterRemove() { //Arrange IArena RA = new RoyaleArena(); Battlecard cd1 = new Battlecard(2, CardType.SPELL, "valq", 14.8, 53); Battlecard cd2 = new Battlecard(1, CardType.SPELL, "valq", 14.8, 5); Battlecard cd3 = new Battlecard(4, CardType.SPELL, "valq", 15.6, 6); Battlecard cd4 = new Battlecard(3, CardType.SPELL, "valq", 15.6, 12); Battlecard cd5 = new Battlecard(8, CardType.RANGED, "valq", 17.8, 613); List <Battlecard> expected = new List <Battlecard>() { cd2 }; //Act RA.Add(cd1); RA.Add(cd3); RA.Add(cd2); RA.Add(cd4); RA.Add(cd5); RA.RemoveById(cd1.Id); //Assert List <Battlecard> actual = RA .GetByCardTypeAndMaximumDamage(CardType.SPELL, 15.0) .ToList(); CollectionAssert.AreEqual(expected, actual); }
public void GetByCardTypeAndMaximumDamage_ShouldWorkCorrectly_OnExistingSender() { //Arrange IArena RA = new RoyaleArena(); BattleCard cd1 = new BattleCard(2, CardType.SPELL, "joro", 1, 5); BattleCard cd2 = new BattleCard(1, CardType.SPELL, "valq", 14.8, 6); BattleCard cd3 = new BattleCard(3, CardType.SPELL, "valq", 15.6, 12); BattleCard cd4 = new BattleCard(4, CardType.SPELL, "valq", 15.6, 61); BattleCard cd5 = new BattleCard(8, CardType.SPELL, "valq", 17.8, 13); List <BattleCard> expected = new List <BattleCard>() { cd3, cd4, cd2, cd1 }; //Act RA.Add(cd1); RA.Add(cd3); RA.Add(cd2); RA.Add(cd4); RA.Add(cd5); //Assert IEnumerable <BattleCard> battlecards = RA.GetByCardTypeAndMaximumDamage(CardType.SPELL, 15.6); List <BattleCard> actual = new List <BattleCard>(); foreach (var item in battlecards) { actual.Add(item); } CollectionAssert.AreEqual(expected, actual); }
public void GetByCardTypeAndMaximumDamage_ShouldThrowOnEmpty_RA() { //Arrange IArena RA = new RoyaleArena(); //Act //Assert Assert.Throws <InvalidOperationException>(() => { RA.GetByCardTypeAndMaximumDamage(CardType.MELEE, 5); }); }
public void GetByCardTypeAndMaximumDamage_ShouldWorkFast() { IArena ar = new RoyaleArena(); List <Battlecard> cds = new List <Battlecard>(); Random rand = new Random(); for (int i = 0; i < 100000; i++) { int amount = rand.Next(0, 1000); Battlecard cd = new Battlecard(i, CardType.SPELL, i.ToString(), amount, i); ar.Add(cd); if (amount <= 500) { cds.Add(cd); } } cds = cds.OrderByDescending(x => x.Damage).ThenBy(x => x.Id).ToList(); int count = ar.Count; Assert.AreEqual(100000, count); Stopwatch watch = new Stopwatch(); watch.Start(); IEnumerable <Battlecard> all = ar.GetByCardTypeAndMaximumDamage( CardType.SPELL, 500); int c = 0; foreach (Battlecard cd in all) { Assert.AreSame(cd, cds[c]); c++; } watch.Stop(); long l1 = watch.ElapsedMilliseconds; Assert.Less(l1, 150); Assert.AreEqual(cds.Count, c); }
static void Main(string[] args) { Battlecard cd1 = new Battlecard(2, CardType.SPELL, "joro", 5, 1); Battlecard cd2 = new Battlecard(1, CardType.SPELL, "joro", 6, 1); Battlecard cd3 = new Battlecard(4, CardType.SPELL, "joro", 7, 15.6); Battlecard cd4 = new Battlecard(3, CardType.SPELL, "joro", 8, 15.6); Battlecard cd5 = new Battlecard(8, CardType.RANGED, "joro", 11, 17.8); var a = new RoyaleArena(); a.Add(cd1); a.Add(cd3); a.Add(cd2); a.Add(cd4); a.Add(cd5); var resultBySwag = a.GetByNameOrderedBySwagDescending("joro").ToList(); var resultByDemage = a.GetByCardTypeAndMaximumDamage(CardType.SPELL, 17).ToList(); Console.WriteLine(); }
public void GetByCardTypeAndMaximumDamage_ShouldThrow_OnMissingSender() { //Arrange IArena RA = new RoyaleArena(); Battlecard cd1 = new Battlecard(2, CardType.SPELL, "joro", 5, 1); Battlecard cd2 = new Battlecard(1, CardType.SPELL, "valq", 5, 14.8); Battlecard cd3 = new Battlecard(4, CardType.SPELL, "valq", 13, 15.6); Battlecard cd4 = new Battlecard(3, CardType.SPELL, "valq", 6, 15.6); Battlecard cd5 = new Battlecard(8, CardType.RANGED, "valq", 123, 17.8); //Act RA.Add(cd1); RA.Add(cd3); RA.Add(cd2); RA.Add(cd4); RA.Add(cd5); //Assert Assert.Throws <InvalidOperationException>(() => { RA.GetByCardTypeAndMaximumDamage(CardType.MELEE, 15.5).ToList(); }); }
public void GetByCardTypeAndMaximumDamage_ShouldThrow_OnEmptyCollection() { //Arrange IArena RA = new RoyaleArena(); Battlecard cd1 = new Battlecard(2, CardType.SPELL, "valq", 14.8, 6); Battlecard cd2 = new Battlecard(1, CardType.SPELL, "valq", 14.8, 7); Battlecard cd3 = new Battlecard(4, CardType.SPELL, "valq", 15.6, 8); Battlecard cd4 = new Battlecard(3, CardType.SPELL, "valq", 15.6, 9); Battlecard cd5 = new Battlecard(8, CardType.RANGED, "valq", 17.8, 10); //Act RA.Add(cd1); RA.Add(cd3); RA.Add(cd2); RA.Add(cd4); RA.Add(cd5); //Assert Assert.Throws <InvalidOperationException>( () => RA.GetByCardTypeAndMaximumDamage(CardType.BUILDING, 5) ); RA = new RoyaleArena(); }