public void FindFirstLeastSwag_ShouldWorkCorrectly() { //Arrange IArena RA = new RoyaleArena(); Battlecard cd1 = new Battlecard(5, CardType.SPELL, "joro", 6, 1); Battlecard cd2 = new Battlecard(6, CardType.MELEE, "joro", 7, 5.5); Battlecard cd3 = new Battlecard(7, CardType.SPELL, "joro", 11, 5.5); Battlecard cd4 = new Battlecard(12, CardType.BUILDING, "joro", 12, 15.6); Battlecard cd5 = new Battlecard(15, CardType.BUILDING, "moro", 13, 7.8); List <Battlecard> expected = new List <Battlecard>() { cd1, cd2, cd3, cd5 }; //Act RA.Add(cd1); RA.Add(cd3); RA.Add(cd2); RA.Add(cd4); RA.Add(cd5); List <Battlecard> actual = RA .FindFirstLeastSwag(4) .ToList(); //Assert CollectionAssert.AreEqual(expected, actual); }
public void FindFirstLeastSwag_ShoudlThrowAfterRemove() { //Arrange IArena RA = new RoyaleArena(); Battlecard cd1 = new Battlecard(5, CardType.SPELL, "joro", 5, 1); Battlecard cd2 = new Battlecard(6, CardType.SPELL, "joro", 6, 5.5); Battlecard cd3 = new Battlecard(7, CardType.SPELL, "joro", 7, 5.5); Battlecard cd4 = new Battlecard(12, CardType.SPELL, "joro", 8, 15.6); Battlecard cd5 = new Battlecard(15, CardType.RANGED, "joro", 12, 7.8); //Act RA.Add(cd1); RA.Add(cd3); RA.Add(cd2); RA.Add(cd4); RA.Add(cd5); RA.RemoveById(5); RA.RemoveById(7); RA.RemoveById(6); RA.RemoveById(12); RA.RemoveById(15); //Assert Assert.Throws <InvalidOperationException>(() => { RA.FindFirstLeastSwag(1); }); }
public void FindFirstLeastSwag_ShouldWorkCorrectly() { //Arrange IArena RA = new RoyaleArena(); BattleCard cd1 = new BattleCard(5, CardType.SPELL, "joro", 6.0, 1.0); BattleCard cd2 = new BattleCard(6, CardType.MELEE, "joro", 7.0, 5.5); BattleCard cd3 = new BattleCard(7, CardType.SPELL, "joro", 11.0, 5.5); BattleCard cd4 = new BattleCard(12, CardType.BUILDING, "joro", 12.0, 15.6); BattleCard cd5 = new BattleCard(15, CardType.BUILDING, "moro", 13.0, 7.8); List <BattleCard> expected = new List <BattleCard>() { cd1, cd2, cd3, cd5 }; //Act RA.Add(cd1); RA.Add(cd3); RA.Add(cd2); RA.Add(cd4); RA.Add(cd5); IEnumerable <BattleCard> battlecards = RA.FindFirstLeastSwag(4); List <BattleCard> actual = new List <BattleCard>(); foreach (var b in battlecards) { actual.Add(b); } //Assert CollectionAssert.AreEqual(expected, actual); }
public void FindFirstLeastSwag_ShouldWorkFast() { IArena ar = new RoyaleArena(); List <Battlecard> cds = new List <Battlecard>(); for (int i = 0; i < 100000; i++) { Battlecard cd = new Battlecard(i, CardType.SPELL, i.ToString(), i, i); ar.Add(cd); cds.Add(cd); } cds = cds.OrderBy(x => x.Swag).ToList(); List <int> ns = new List <int>(); List <List <Battlecard> > expected = new List <List <Battlecard> >(); Random rand = new Random(); for (int i = 0; i < 100; i++) { int n = rand.Next(0, 5000); ns.Add(n); expected.Add(cds.Take(n).ToList()); } int count = ar.Count; cds = cds.OrderByDescending(x => x.Damage).ThenBy(x => x.Id).ToList(); Assert.AreEqual(100000, count); Stopwatch watch = new Stopwatch(); watch.Start(); List <IEnumerable <Battlecard> > actual = new List <IEnumerable <Battlecard> >(); for (int i = 0; i < 100; i++) { IEnumerable <Battlecard> all = ar.FindFirstLeastSwag(ns[i]); actual.Add(all); } watch.Stop(); long l1 = watch.ElapsedMilliseconds; Assert.Less(l1, 300); for (int i = 0; i < 100; i++) { CollectionAssert.AreEqual(expected[i], actual[i].ToList()); } }
public void FindFirstLeastSwag_OnNonExistantcds_ShouldThrow() { //Arrange IArena RA = new RoyaleArena(); Battlecard cd1 = new Battlecard(5, CardType.SPELL, "joro", 5, 1); Battlecard cd2 = new Battlecard(6, CardType.MELEE, "joro", 5, 5.5); Battlecard cd3 = new Battlecard(7, CardType.MELEE, "joro", 10, 5.5); Battlecard cd4 = new Battlecard(12, CardType.RANGED, "joro", 11, 15.6); Battlecard cd5 = new Battlecard(15, CardType.SPELL, "joro", 16, 7.8); //Act RA.Add(cd1); RA.Add(cd3); RA.Add(cd2); RA.Add(cd4); RA.Add(cd5); //Assert Assert.Throws <InvalidOperationException>( () => RA.FindFirstLeastSwag(150) ); }