public void CountTest() { int count = 0; SectorCollection target = new SectorCollection(); // TODO: Initialize to an appropriate value int actual; actual = target.Count; Assert.IsTrue(actual == count); Sector s = new Sector(4096); target.Add(s); Assert.IsTrue(target.Count == actual + 1); for (int i = 0; i < 5000; i++) target.Add(s); Assert.IsTrue(target.Count == actual + 1 + 5000); }
public void TEST_STREAM_VIEW() { Stream a = null; List<Sector> temp = new List<Sector>(); Sector s = new Sector(512); Buffer.BlockCopy(BitConverter.GetBytes((int)1), 0, s.GetData(), 0, 4); temp.Add(s); StreamView sv = new StreamView(temp, 512, 0, a); BinaryReader br = new BinaryReader(sv); Int32 t = br.ReadInt32(); Assert.IsTrue(t == 1); }
public void ItemTest() { int count = 37; SectorCollection target = new SectorCollection(); int index = 0; Sector expected = new Sector(4096); target.Add(null); Sector actual; target[index] = expected; actual = target[index]; Assert.AreEqual(expected, actual); Assert.IsNotNull(actual); Assert.IsTrue(actual.Id == expected.Id); actual = null; try { actual = target[count + 100]; } catch (Exception ex) { Assert.IsTrue(ex is ArgumentOutOfRangeException); } try { actual = target[-1]; } catch (Exception ex) { Assert.IsTrue(ex is ArgumentOutOfRangeException); } }
public void GetEnumeratorTest() { SectorCollection target = new SectorCollection(); for (int i = 0; i < 579; i++) { target.Add(null); } Sector item = new Sector(4096); target.Add(item); Assert.IsTrue(target.Count == 580); int cnt = 0; foreach (Sector s in target) { cnt++; } Assert.IsTrue(cnt == target.Count); }
public void AddTest() { SectorCollection target = new SectorCollection(); for (int i = 0; i < 579; i++) { target.Add(null); } Sector item = new Sector(4096); target.Add(item); Assert.IsTrue(target.Count == 580); }
public void SectorCollectionConstructorTest() { SectorCollection target = new SectorCollection(); Assert.IsNotNull(target); Assert.IsTrue(target.Count == 0); Sector s = new Sector(4096); target.Add(s); Assert.IsTrue(target.Count == 1); }
private void adjustLength(long value, Queue<Sector> availableSectors) { this.length = value; long delta = value - ((long)this.sectorChain.Count * (long)sectorSize); if (delta > 0) { // enlargment required int nSec = (int)Math.Ceiling(((double)delta / sectorSize)); while (nSec > 0) { Sector t = null; if (availableSectors == null || availableSectors.Count == 0) { t = new Sector(sectorSize, stream); } else { t = availableSectors.Dequeue(); } sectorChain.Add(t); nSec--; } //if (((int)delta % sectorSize) != 0) //{ // Sector t = new Sector(sectorSize); // sectorChain.Add(t); //} } else { // TODO: Freeing sector to avoid wasting space. // FREE Sectors //delta = Math.Abs(delta); //int nSec = (int)(length - delta) / sectorSize; //if (((int)(length - delta) % sectorSize) != 0) //{ // nSec++; //} //while (sectorChain.Count > nSec) //{ // sectorChain.RemoveAt(sectorChain.Count - 1); //} } }