public List <MoveContext> getHighestPriorityMoves() { MovePriority highestPrio = null; List <MoveContext> highestPrioList = new List <MoveContext>(); foreach (MoveContext mc in remainingMoveRequests) { if (highestPrio == null) { highestPrio = mc.getMovePriority(); highestPrioList.Add(mc); } else { if (mc.getMovePriority().Equals(highestPrio)) { highestPrioList.Add(mc); } else if (mc.getMovePriority().CompareTo(highestPrio) < 0) { highestPrio = mc.getMovePriority(); highestPrioList.Clear(); highestPrioList.Add(mc); } } } return(highestPrioList); }
public void testMovePriorityComparison() { MovePriority mp1 = new MovePriority(0, 100); MovePriority mp2 = new MovePriority(0, 100); MovePriority mp3 = new MovePriority(-1, 50); MovePriority mp4 = new MovePriority(2, 500); MovePriority mp5 = new MovePriority(0, 103); //These two are equal in every way Assert.That(mp1.Equals(mp2)); Assert.That(mp1.CompareTo(mp2) == 0); //Lower priority values mean that mp3 should go before mp1 regardless of speed Assert.That(mp1.Equals(mp3) == false); Assert.That(mp3.CompareTo(mp1) < 0); //Higher priority values mean that mp4 should go after mp1 regardless of speed Assert.That(mp1.Equals(mp4) == false); Assert.That(mp4.CompareTo(mp1) > 0); //Higher speed when priority is equal means that mp5 goes before mp1 Assert.That(mp1.Equals(mp5) == false); Assert.That(mp5.CompareTo(mp1) < 0); }