Exemple #1
0
        public void SegmentCollectionGetSegmentTest()
        {
            // test for all indices

            for (Int32 rowIndex = 0; rowIndex < _raster.Object.NumberOfRows; rowIndex++)
            {
                for (Int32 columnIndex = 0; columnIndex < _raster.Object.NumberOfColumns; columnIndex++)
                {
                    Segment segment = _collection.GetSegment(rowIndex, columnIndex);

                    Assert.AreEqual(1, segment.Count);
                    Assert.AreEqual(_raster.Object.NumberOfBands, segment.NumberOfBands);
                    Assert.AreEqual(_raster.Object.NumberOfColumns * _raster.Object.NumberOfRows, _collection.Count);
                    Assert.IsTrue(_collection.Contains(segment));
                }
            }


            // test repeating queries

            Random random = new Random(0);

            for (Int32 queryIndex = 0; queryIndex < 10; queryIndex++)
            {
                Int32   rowIndex    = random.Next(0, _raster.Object.NumberOfRows);
                Int32   columnIndex = random.Next(0, _raster.Object.NumberOfColumns);
                Segment segment     = _collection.GetSegment(rowIndex, columnIndex);

                Segment otherSegment = _collection.GetSegment(rowIndex, columnIndex);

                Assert.AreEqual(segment, otherSegment);

                for (Int32 otherQueryIndex = 0; otherQueryIndex < 10; otherQueryIndex++)
                {
                    otherSegment = _collection.GetSegment(random.Next(0, _raster.Object.NumberOfRows), random.Next(0, _raster.Object.NumberOfColumns));
                }

                otherSegment = _collection.GetSegment(rowIndex, columnIndex);

                Assert.AreEqual(segment, otherSegment);
            }

            // exceptions

            Assert.Throws <ArgumentOutOfRangeException>(() => _collection.GetSegment(-1, 0));
            Assert.Throws <ArgumentOutOfRangeException>(() => _collection.GetSegment(0, -1));
            Assert.Throws <ArgumentOutOfRangeException>(() => _collection.GetSegment(_raster.Object.NumberOfRows, 0));
            Assert.Throws <ArgumentOutOfRangeException>(() => _collection.GetSegment(0, _raster.Object.NumberOfColumns));
        }
Exemple #2
0
        public void SegmentCollectionMergeSegmentsTest()
        {
            // merge using segments

            SegmentCollection collection = new SegmentCollection(_raster.Object);
            Segment           segment    = collection.GetSegment(0, 0);
            Int32             count      = collection.Count;

            for (Int32 rowIndex = 0; rowIndex < _raster.Object.NumberOfRows; rowIndex++)
            {
                for (Int32 columnIndex = 0; columnIndex < _raster.Object.NumberOfColumns; columnIndex++)
                {
                    Segment otherSegment = collection.GetSegment(rowIndex, columnIndex);
                    collection.MergeSegments(segment, otherSegment);

                    Assert.IsFalse(segment != otherSegment && collection.Contains(segment) && collection.Contains(otherSegment));

                    segment = collection.GetSegment(rowIndex, columnIndex);

                    Assert.AreEqual(count, collection.Count);
                    count--;
                }
            }

            Assert.AreEqual(_raster.Object.NumberOfColumns * _raster.Object.NumberOfRows, segment.Count);


            // merge using segment and indices

            collection = new SegmentCollection(_raster.Object);
            segment    = collection.GetSegment(0, 0);
            count      = collection.Count;

            for (Int32 rowIndex = 0; rowIndex < _raster.Object.NumberOfRows; rowIndex++)
            {
                for (Int32 columnIndex = 0; columnIndex < _raster.Object.NumberOfColumns; columnIndex++)
                {
                    collection.MergeSegments(segment, rowIndex, columnIndex);

                    Segment otherSegment = collection.GetSegment(rowIndex, columnIndex);

                    Assert.AreEqual(segment, otherSegment);
                    Assert.AreEqual(count, collection.Count);
                    count--;
                }
            }

            Assert.AreEqual(_raster.Object.NumberOfColumns * _raster.Object.NumberOfRows, segment.Count);


            // merge using indices

            collection = new SegmentCollection(_raster.Object);
            segment    = collection.GetSegment(0, 0);
            count      = collection.Count;

            for (Int32 rowIndex = 0; rowIndex < _raster.Object.NumberOfRows; rowIndex++)
            {
                for (Int32 columnIndex = 0; columnIndex < _raster.Object.NumberOfColumns; columnIndex++)
                {
                    collection.MergeSegments(0, 0, rowIndex, columnIndex);

                    Segment otherSegment = collection.GetSegment(rowIndex, columnIndex);

                    Assert.AreEqual(segment, otherSegment);
                    Assert.AreEqual(count, collection.Count);
                    count--;
                }
            }

            Assert.AreEqual(_raster.Object.NumberOfColumns * _raster.Object.NumberOfRows, segment.Count);
        }