public void ReadAcrossSectorsTest() { var readRange = new SectorRange(500, 1500); var firstRange = new SectorRange(100, 800); var secondRange = new SectorRange(900, 1100); var thirdRange = new SectorRange(1200, 2000); var firstSector = CreateMock <ISector>(); var secondSector = CreateMock <ISector>(); var thirdSector = CreateMock <ISector>(); When(firstSector.Size).ThenReturn(700); When(secondSector.Size).ThenReturn(200); When(thirdSector.Size).ThenReturn(800); When(sectors.GetSectorsForRange(readRange)).ThenReturn(new[] { firstRange.PairValue(firstSector), secondRange.PairValue(secondSector), thirdRange.PairValue(thirdSector) }); var buffer = testObj.Read(readRange.startInclusive, readRange.Size); Verify(sectors).GetSectorsForRange(readRange); Verify(firstSector).Read(400, 300, buffer, 0); Verify(secondSector).Read(0, 200, buffer, 400); Verify(thirdSector).Read(0, 300, buffer, 700); Verify(firstSector).Size.Wrap(); Verify(secondSector).Size.Wrap(); Verify(thirdSector, AnyOrNoneTimes()).Size.Wrap(); VerifyNoMoreInteractions(); }
public void ChopMiddleTest() { var initial = new SectorRange(1000, 2000); var chopResults = initial.Chop(new SectorRange(1250, 1750)).ToArray(); AssertEquals(2, chopResults.Length); AssertEquals(new SectorRange(1000, 1250), chopResults[0]); AssertEquals(new SectorRange(1750, 2000), chopResults[1]); }
public void ContainsTest() { var a = new SectorRange(10, 20); AssertFalse(a.Contains(9)); AssertTrue(a.Contains(10)); AssertTrue(a.Contains(15)); AssertTrue(a.Contains(19)); AssertFalse(a.Contains(20)); AssertFalse(a.Contains(22)); }
public void ReadNothingFromEmptyFileTest() { var readRange = new SectorRange(0, 0); When(sectors.GetSectorsForRange(readRange)).ThenReturn(new KeyValuePair <SectorRange, ISector> [0]); var output = testObj.Read(0, 0); Verify(sectors).GetSectorsForRange(readRange); VerifyNoMoreInteractions(); AssertEquals(0, output.Length); }
public void ContainsTest() { var a = new SectorRange(10, 20); AssertFalse(a.Contains(9)); AssertTrue(a.Contains(10)); AssertTrue(a.Contains(15)); AssertTrue(a.Contains(19)); AssertFalse(a.Contains(20)); AssertFalse(a.Contains(22)); }
public void ChopFrontTest() { var initial = new SectorRange(1000, 2000); var chopResults1 = initial.Chop(new SectorRange(1000, 1500)).ToArray(); var chopResults2 = initial.Chop(new SectorRange(500, 1500)).ToArray(); AssertEquals(1, chopResults1.Length); AssertEquals(1, chopResults2.Length); AssertEquals(chopResults1[0], chopResults2[0]); AssertEquals(new SectorRange(1500, 2000), chopResults1[0]); }
public void ChopFrontTest() { var initial = new SectorRange(1000, 2000); var chopResults1 = initial.Chop(new SectorRange(1000, 1500)).ToArray(); var chopResults2 = initial.Chop(new SectorRange(500, 1500)).ToArray(); AssertEquals(1, chopResults1.Length); AssertEquals(1, chopResults2.Length); AssertEquals(chopResults1[0], chopResults2[0]); AssertEquals(new SectorRange(1500, 2000), chopResults1[0]); }
public void AssignSectorTest() { var range = new SectorRange(1000, 2000); var sector = CreateMock<ISector>(); var collection = new SectorCollection(); collection.AssignSector(range, sector); var sectors = collection.EnumerateSectors().ToList(); AssertEquals(1, sectors.Count); AssertEquals(sector, sectors[0]); VerifyNoMoreInteractions(); }
public void IntersectsTest() { var a = new SectorRange(0, 10); var b = new SectorRange(0, 11); var c = new SectorRange(10, 20); var d = new SectorRange(19, 30); var e = new SectorRange(20, 30); AssertFalse(c.Intersects(a)); AssertTrue(c.Intersects(b)); AssertTrue(c.Intersects(c)); AssertTrue(c.Intersects(d)); AssertFalse(c.Intersects(e)); }
public void DeleteRange(SectorRange range) { var kvpsToTouch = GetSectorsForRange(range); foreach (var kvp in kvpsToTouch) { sectors.Remove(kvp.Key); if (!range.FullyContains(kvp.Key)) { var newPieces = kvp.Key.Chop(range); var newRangeAndSectors = kvp.Value.Segment(kvp.Key, newPieces); foreach (var rangeAndSector in newRangeAndSectors) { sectors.Add(rangeAndSector.Key, rangeAndSector.Value); } } } }
public void DeletePastEndDoesNothingTest() { var initialRange = new SectorRange(0, 1000); var initialSector = CreateMock<ISector>(); var collection = new SectorCollection(initialRange.PairValue(initialSector).Wrap()); collection.DeleteRange(new SectorRange(1000, 2000)); var pairs = collection.EnumerateSectorPairs(); AssertEquals(1, pairs.Count); AssertEquals(0, pairs[0].Key.startInclusive); AssertEquals(1000, pairs[0].Key.endExclusive); AssertEquals(initialSector, pairs[0].Value); VerifyNoMoreInteractions(); }
public void AssignSectorTest() { var range = new SectorRange(1000, 2000); var sector = CreateMock <ISector>(); var collection = new SectorCollection(); collection.AssignSector(range, sector); var sectors = collection.EnumerateSectors().ToList(); AssertEquals(1, sectors.Count); AssertEquals(sector, sectors[0]); VerifyNoMoreInteractions(); }
public void IntersectsTest() { var a = new SectorRange(0, 10); var b = new SectorRange(0, 11); var c = new SectorRange(10, 20); var d = new SectorRange(19, 30); var e = new SectorRange(20, 30); AssertFalse(c.Intersects(a)); AssertTrue(c.Intersects(b)); AssertTrue(c.Intersects(c)); AssertTrue(c.Intersects(d)); AssertFalse(c.Intersects(e)); }
public void AssignToSectorEndTest() { var firstRange = new SectorRange(0, 1000); var secondRange = new SectorRange(1000, 2000); var firstSector = CreateMock<ISector>(); var secondSector = CreateMock<ISector>(); var collection = new SectorCollection(); collection.AssignSector(firstRange, firstSector); collection.AssignSector(secondRange, secondSector); var sectorPairs = collection.EnumerateSectorPairs().ToList(); AssertEquals(2, sectorPairs.Count); AssertEquals(new SectorRange(0, 1000), sectorPairs[0].Key); AssertEquals(firstSector, sectorPairs[0].Value); AssertEquals(new SectorRange(1000, 2000), sectorPairs[1].Key); AssertEquals(secondSector, sectorPairs[1].Value); VerifyNoMoreInteractions(); }
public void ReadWithinSectorTest() { var readRange = new SectorRange(250, 750); var sectorRange = new SectorRange(0, 1000); var sector = CreateMock <ISector>(); When(sector.Size).ThenReturn(1000); When(sectors.GetSectorsForRange(readRange)).ThenReturn(new[] { sectorRange.PairValue(sector) }); var buffer = testObj.Read(readRange.startInclusive, readRange.Size); Verify(sectors).GetSectorsForRange(readRange); Verify(sector).Read(250, 500, buffer, 0); Verify(sector, AnyOrNoneTimes()).Size.Wrap(); VerifyNoMoreInteractions(); }
public void DeletePastEndDoesNothingTest() { var initialRange = new SectorRange(0, 1000); var initialSector = CreateMock <ISector>(); var collection = new SectorCollection(initialRange.PairValue(initialSector).Wrap()); collection.DeleteRange(new SectorRange(1000, 2000)); var pairs = collection.EnumerateSectorPairs(); AssertEquals(1, pairs.Count); AssertEquals(0, pairs[0].Key.startInclusive); AssertEquals(1000, pairs[0].Key.endExclusive); AssertEquals(initialSector, pairs[0].Value); VerifyNoMoreInteractions(); }
public void AssignToSectorEndTest() { var firstRange = new SectorRange(0, 1000); var secondRange = new SectorRange(1000, 2000); var firstSector = CreateMock <ISector>(); var secondSector = CreateMock <ISector>(); var collection = new SectorCollection(); collection.AssignSector(firstRange, firstSector); collection.AssignSector(secondRange, secondSector); var sectorPairs = collection.EnumerateSectorPairs().ToList(); AssertEquals(2, sectorPairs.Count); AssertEquals(new SectorRange(0, 1000), sectorPairs[0].Key); AssertEquals(firstSector, sectorPairs[0].Value); AssertEquals(new SectorRange(1000, 2000), sectorPairs[1].Key); AssertEquals(secondSector, sectorPairs[1].Value); VerifyNoMoreInteractions(); }
public void DeleteRangeTest() { var initialRange = new SectorRange(0, 1000); var initialSector = CreateMock<ISector>(); var chopRange = new SectorRange(250, 750); var leftSector = CreateMock<ISector>(); var leftRange = new SectorRange(0, 250); var rightSector = CreateMock<ISector>(); var rightRange = new SectorRange(750, 1000); var leftAndRightRange = new[] { leftRange, rightRange }; var leftAndRightSectors = new[] { leftSector, rightSector }; var leftAndRightRangeAndSectors = new[] { leftRange.PairValue(leftSector), rightRange.PairValue(rightSector) }; When(initialSector.Segment(Eq(initialRange), EqSequence(leftAndRightRange))).ThenReturn(leftAndRightRangeAndSectors); var collection = new SectorCollection(new KeyValuePair<SectorRange, ISector>(initialRange, initialSector).Wrap()); collection.DeleteRange(chopRange); Verify(initialSector).Segment(Eq(initialRange), Any<IEnumerable<SectorRange>>(x => x.SequenceEqual(leftAndRightRange))); VerifyNoMoreInteractions(); AssertTrue(leftAndRightSectors.SequenceEqual(collection.EnumerateSectors())); }
public void FullyContainsTest() { var a = new SectorRange(0, 10); var b = new SectorRange(8, 12); var c = new SectorRange(10, 12); var d = new SectorRange(10, 20); var e = new SectorRange(14, 16); var f = new SectorRange(18, 20); var g = new SectorRange(18, 22); var h = new SectorRange(20, 30); AssertFalse(d.FullyContains(a)); AssertFalse(d.FullyContains(b)); AssertTrue(d.FullyContains(c)); AssertTrue(d.FullyContains(d)); AssertTrue(d.FullyContains(e)); AssertTrue(d.FullyContains(f)); AssertFalse(d.FullyContains(g)); AssertFalse(d.FullyContains(h)); }
public void FullyContainsTest() { var a = new SectorRange(0, 10); var b = new SectorRange(8, 12); var c = new SectorRange(10, 12); var d = new SectorRange(10, 20); var e = new SectorRange(14, 16); var f = new SectorRange(18, 20); var g = new SectorRange(18, 22); var h = new SectorRange(20, 30); AssertFalse(d.FullyContains(a)); AssertFalse(d.FullyContains(b)); AssertTrue(d.FullyContains(c)); AssertTrue(d.FullyContains(d)); AssertTrue(d.FullyContains(e)); AssertTrue(d.FullyContains(f)); AssertFalse(d.FullyContains(g)); AssertFalse(d.FullyContains(h)); }
public void DeleteRangeTest() { var initialRange = new SectorRange(0, 1000); var initialSector = CreateMock <ISector>(); var chopRange = new SectorRange(250, 750); var leftSector = CreateMock <ISector>(); var leftRange = new SectorRange(0, 250); var rightSector = CreateMock <ISector>(); var rightRange = new SectorRange(750, 1000); var leftAndRightRange = new[] { leftRange, rightRange }; var leftAndRightSectors = new[] { leftSector, rightSector }; var leftAndRightRangeAndSectors = new[] { leftRange.PairValue(leftSector), rightRange.PairValue(rightSector) }; When(initialSector.Segment(Eq(initialRange), EqSequence(leftAndRightRange))).ThenReturn(leftAndRightRangeAndSectors); var collection = new SectorCollection(new KeyValuePair <SectorRange, ISector>(initialRange, initialSector).Wrap()); collection.DeleteRange(chopRange); Verify(initialSector).Segment(Eq(initialRange), Any <IEnumerable <SectorRange> >(x => x.SequenceEqual(leftAndRightRange))); VerifyNoMoreInteractions(); AssertTrue(leftAndRightSectors.SequenceEqual(collection.EnumerateSectors())); }
public IEnumerable<KeyValuePair<SectorRange, ISector>> Segment(SectorRange currentRange, IEnumerable<SectorRange> newRanges) { return newRanges.Select(range => range.PairValue((ISector)new NullSector(range.Size))); }
public void ChopMiddleTest() { var initial = new SectorRange(1000, 2000); var chopResults = initial.Chop(new SectorRange(1250, 1750)).ToArray(); AssertEquals(2, chopResults.Length); AssertEquals(new SectorRange(1000, 1249), chopResults[0]); AssertEquals(new SectorRange(1750, 2000), chopResults[1]); }
public void AssignSector(SectorRange range, ISector sector) { DeleteRange(range); sectors.Add(range, sector); }
public KeyValuePair<SectorRange, ISector>[] GetSectorsForRange(SectorRange range) { return sectors.Where(kvp => range.Intersects(kvp.Key)).ToArray(); }