Beispiel #1
0
        /// <exception cref="System.IO.IOException"/>
        internal virtual void CheckRecNums()
        {
            long fileLen = fs.GetFileStatus(path).GetLen();

            TFile.Reader reader    = new TFile.Reader(fs.Open(path), fileLen, conf);
            long         totalRecs = reader.GetEntryCount();
            long         begin     = random.NextLong() % (totalRecs / 2);

            if (begin < 0)
            {
                begin += (totalRecs / 2);
            }
            long end = random.NextLong() % (totalRecs / 2);

            if (end < 0)
            {
                end += (totalRecs / 2);
            }
            end += (totalRecs / 2) + 1;
            Assert.Equal("RecNum for offset=0 should be 0", 0, reader.GetRecordNumNear
                             (0));
            foreach (long x in new long[] { fileLen, fileLen + 1, 2 * fileLen })
            {
                Assert.Equal("RecNum for offset>=fileLen should be total entries"
                             , totalRecs, reader.GetRecordNumNear(x));
            }
            for (long i = 0; i < 100; ++i)
            {
                Assert.Equal("Locaton to RecNum conversion not symmetric", i,
                             reader.GetRecordNumByLocation(reader.GetLocationByRecordNum(i)));
            }
            for (long i_1 = 1; i_1 < 100; ++i_1)
            {
                long x_1 = totalRecs - i_1;
                Assert.Equal("Locaton to RecNum conversion not symmetric", x_1
                             , reader.GetRecordNumByLocation(reader.GetLocationByRecordNum(x_1)));
            }
            for (long i_2 = begin; i_2 < end; ++i_2)
            {
                Assert.Equal("Locaton to RecNum conversion not symmetric", i_2
                             , reader.GetRecordNumByLocation(reader.GetLocationByRecordNum(i_2)));
            }
            for (int i_3 = 0; i_3 < 1000; ++i_3)
            {
                long x_1 = random.NextLong() % totalRecs;
                if (x_1 < 0)
                {
                    x_1 += totalRecs;
                }
                Assert.Equal("Locaton to RecNum conversion not symmetric", x_1
                             , reader.GetRecordNumByLocation(reader.GetLocationByRecordNum(x_1)));
            }
        }