public void FindWillRetrieveTheFirstValueThatMathcesPredicateBasedOnOrderOfInsertion() { var testSet2 = new SecureSortedSet <int, float>(); testSet2.Add(1, 33f); testSet2.Add(2, 54f); testSet2.Add(3, 55f); testSet2.Add(4, 15f); Assert.AreEqual(33f, testSet2.Find((x) => x < 50)); Assert.AreEqual(54f, testSet2.Find((x) => x > 50)); testSet2.Remove((int)1); Assert.AreEqual(15f, testSet2.Find((x) => x < 50)); }
private bool LoadDrone(SDrone data, HashSet <uint> free) { if (data.hub == UID) { Drone drone = Drone.Load(data); drones.Add(drone.UID, drone); if (!data.inHub) { drone.transform.SetParent(Drone.ActiveDrones); } if (free.Contains(drone.UID)) { freeDrones.Add(drone.UID, drone); } return(true); } return(false); }
private bool LoadBattery(SBattery data, HashSet <uint> free, HashSet <uint> charging) { if (data.hub == UID) { var bat = new Battery(data); batteries.Add(bat.UID, bat); if (free.Contains(bat.UID)) { freeBatteries.Add(bat.UID, bat); } if (charging.Contains(bat.UID)) { chargingBatteries.Add(bat.UID, bat); } return(true); } return(false); }
private void SetUpCollectionEvents() { batteries.ItemAdded += delegate(Battery bat) { AllBatteries.Add(bat.UID, bat); bat.AssignHub(_source); }; batteries.ItemRemoved += delegate(Battery bat) { BatteriesWithNoDrones.Remove(bat.UID); AllBatteries.Remove(bat.UID); }; drones.ItemAdded += delegate(IDataSource drone) { ((Drone)drone).AssignHub(_source); AllDrones.Add(drone.UID, drone); DronesWithNoJobs.Add(drone.UID, (Drone)drone); }; drones.ItemRemoved += delegate(IDataSource drone) { AllDrones.Remove(drone); DronesWithNoJobs.Remove((Drone)drone); }; DronesWithNoJobs.ItemAdded += (drone) => { drone.transform.SetParent(_source.transform); }; DronesWithNoJobs.ItemRemoved += (drone) => { drone.transform.SetParent(Drone.ActiveDrones); }; completedJobs.ItemAdded += delegate(IDataSource job) { incompleteJobs.Remove(job); AllCompleteJobs.Add(job.UID, job); }; completedJobs.ItemRemoved += (job) => AllCompleteJobs.Remove(job); incompleteJobs.ItemAdded += delegate(IDataSource job) { AllJobs.Add(job.UID, (Job)job); AllIncompleteJobs.Add(job.UID, job); }; incompleteJobs.ItemRemoved += (job) => AllIncompleteJobs.Remove(job); }
public RetiredDroneData(SRetiredDrone data) { UID = data.uid; isDroneCollision = data.isDroneCollision; hub = data.hub; packageWorth = data.packageworth; destroyedTime = new TimeKeeper.Chronos(data.destroyed); collisionLocation = data.location; waypoint = data.waypoint; otherUID = data.otherUID; otherDrone = data.otherDroneName; batteryCharge = data.charge; job = data.assignedJob; completedJobs = new SecureSortedSet <uint, IDataSource>((x, y) => (((Job)x).CompletedOn >= ((Job)y).CompletedOn) ? -1 : 1) { MemberCondition = (IDataSource obj) => { return(obj is Job); } }; foreach (uint j in data.completedJobs) { completedJobs.Add(j, AllCompleteJobs[j]); } }
public void GetMaxOrGetMinOnlyReSortsWhenArgIsTrue() { var testSet2 = new SecureSortedSet <int, float[]>((float[] x, float[] y) => Sum(x) <= Sum(y) ? -1 : 1); float[] b = { 0.4f, 0.4f, 0.4f }; float[] d = { 1.4f, 1.4f, 1.4f }; testSet2.Add(1, new float[] { 0.1f, 0.1f, 0.1f }); testSet2.Add(2, b); testSet2.Add(3, new float[] { 0.8f, 0.8f, 0.8f }); testSet2.Add(4, d); Assert.AreSame(d, testSet2.GetMax(false)); b[0] = 20; Assert.AreSame(b, testSet2.GetMax(true)); testSet2.Add(2, b); b[0] = 0.01f; b[1] = 0.02f; b[2] = 0.02f; Assert.AreSame(b, testSet2.GetMin(true)); testSet2.Add(2, b); b[0] = 200; Assert.AreSame(b, testSet2.GetMin(false)); }
public void CanAddAndRemoveKeyAndValue() { testSet.Add(1, "a"); testSet.Add(2, "b"); testSet.Add(3, "c"); Assert.AreEqual(3, testSet.Count); testSet.Remove("b"); Assert.AreEqual(2, testSet.Count); testSet.Remove(3); Assert.AreEqual(1, testSet.Count); testSet.Clear(); Assert.AreEqual(0, testSet.Count); }