public void UpdateAllNone() { IntObjectMinHeap heap = new IntObjectMinHeap(); IntObjectMinHeap.IntObject oneObject = new IntObjectMinHeap.IntObject(1); IntObjectMinHeap.IntObject twoObject = new IntObjectMinHeap.IntObject(2); IntObjectMinHeap.IntObject threeObject = new IntObjectMinHeap.IntObject(3); IntObjectMinHeap.IntObject fourObject = new IntObjectMinHeap.IntObject(4); heap.Add(oneObject); heap.Add(twoObject); heap.Add(threeObject); heap.Add(fourObject); // 到这里是 1-4 存入,列表也是 1234 heap.UpdateAll(); // 不修改直接更新,更新后也应该是 1234 Assert.AreEqual(oneObject, heap.GetList()[0]); Assert.AreEqual(twoObject, heap.GetList()[1]); Assert.AreEqual(threeObject, heap.GetList()[2]); Assert.AreEqual(fourObject, heap.GetList()[3]); }
public void UpdateUp() { IntObjectMinHeap heap = new IntObjectMinHeap(); IntObjectMinHeap.IntObject oneObject = new IntObjectMinHeap.IntObject(1); IntObjectMinHeap.IntObject twoObject = new IntObjectMinHeap.IntObject(2); IntObjectMinHeap.IntObject threeObject = new IntObjectMinHeap.IntObject(3); IntObjectMinHeap.IntObject fourObject = new IntObjectMinHeap.IntObject(4); heap.Add(oneObject); heap.Add(twoObject); heap.Add(threeObject); heap.Add(fourObject); // 到这里是 1-4 存入,列表也是 1234 oneObject.Value = 5; fourObject.Value = 0; heap.Update(obj => obj.Value == 0); // 1 换成 5,4 换成 0,但只更新换成 0 的,更新后应该是 0532 Assert.AreEqual(fourObject, heap.GetList()[0]); Assert.AreEqual(oneObject, heap.GetList()[1]); Assert.AreEqual(threeObject, heap.GetList()[2]); Assert.AreEqual(twoObject, heap.GetList()[3]); }
public void UpdateAllUpDown() { IntObjectMinHeap heap = new IntObjectMinHeap(); IntObjectMinHeap.IntObject oneObject = new IntObjectMinHeap.IntObject(1); IntObjectMinHeap.IntObject twoObject = new IntObjectMinHeap.IntObject(2); IntObjectMinHeap.IntObject threeObject = new IntObjectMinHeap.IntObject(3); IntObjectMinHeap.IntObject fourObject = new IntObjectMinHeap.IntObject(4); heap.Add(oneObject); heap.Add(twoObject); heap.Add(threeObject); heap.Add(fourObject); // 到这里是 1-4 存入,列表也是 1234 oneObject.Value = 5; fourObject.Value = 1; heap.UpdateAll(); // 1 换成 5,4 换成 1,更新后应该是 1235 Assert.AreEqual(fourObject, heap.GetList()[0]); Assert.AreEqual(twoObject, heap.GetList()[1]); Assert.AreEqual(threeObject, heap.GetList()[2]); Assert.AreEqual(oneObject, heap.GetList()[3]); }