Exemplo n.º 1
0
        /// <summary>
        /// Gets a block from the cache at the specified index.
        /// </summary>
        /// <param name="index">The zero-based index of the block.</param>
        /// <returns>The cached sequence block.</returns>
        private CacheBox <byte[]> GetCacheBlock(int index)
        {
            CacheBox <byte[]> block = _virtualData.FirstOrDefault(C => index >= C.StartRange && index <= C.EndRange);

            if (block != null)
            {
                return(block);
            }
            else
            {
                int    startIndex = index - (index % BlockSize);
                byte[] seq        = _parser.ParseRange(startIndex, BlockSize, SequencePointerInstance);

                if (seq == null)
                {
                    return(null);
                }
                else
                {
                    block = new CacheBox <byte[]>(seq.Length)
                    {
                        StartRange = startIndex
                    };
                    block.EndRange = block.StartRange + seq.Length - 1;
                    block.Data     = seq;

                    _virtualData.Add(block);
                    return(block);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets a block from the cache at the specified index.
        /// </summary>
        /// <param name="index">The zero-based index of the block.</param>
        /// <returns>The cached sequence block.</returns>
        private CacheBox <byte[]> GetCacheBlock(int index)
        {
            CacheBox <byte[]> block = _virtualData.FirstOrDefault(C => index >= C.StartRange && index <= C.EndRange);

            if (block != null)
            {
                return(block);
            }
            else
            {
                int startIndex         = index;
                int blockStartingIndex = index - (index % BlockSize);
                int sequenceLength     = (int)(SequencePointerInstance.IndexOffsets[1] - SequencePointerInstance.IndexOffsets[0]);
                int count = sequenceLength > BlockSize ? BlockSize : sequenceLength;

                if (sequenceLength > BlockSize && _sidecarProvider != null)
                {
                    blockStartingIndex = _sidecarProvider.GetBlockToLoad(_sequenceIndex, index, ref startIndex, ref count);
                }
                else
                {
                    blockStartingIndex = 0;
                    startIndex         = 0;
                }

                byte[] seq = _parser.ParseRange(blockStartingIndex, count, SequencePointerInstance);

                if (seq == null)
                {
                    return(null);
                }
                else
                {
                    block = new CacheBox <byte[]>(seq.Length)
                    {
                        StartRange = startIndex
                    };
                    block.EndRange = block.StartRange + seq.Length - 1;
                    block.Data     = seq;

                    _virtualData.Add(block);
                    return(block);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// General method to validate virtual data class.
        /// <param name="addParam">Additional parameter.</param>
        /// </summary>
        static void ValidateGeneralVirtualDataTestCases(AdditionalParameters addParam)
        {
            VirtualData <Sequence> vdObj = new VirtualData <Sequence>();

            // Sets the Initial Properties and required Cache box
            vdObj.MaxNumberOfBlocks = 5;
            vdObj.BlockSize         = 5;
            CacheBox <Sequence> cb1 = new CacheBox <Sequence>(11);

            cb1.StartRange = 0;
            cb1.EndRange   = 10;
            cb1.Data       = new Sequence(Alphabets.DNA, "GGGGGGGGGGGGG");

            CacheBox <Sequence> cb2 = new CacheBox <Sequence>(11);

            cb2.StartRange = 0;
            cb2.EndRange   = 10;
            cb2.Data       = new Sequence(Alphabets.DNA, "TTTTTTTTTTTTT");

            CacheBox <Sequence> cb3 = new CacheBox <Sequence>(11);

            cb3.StartRange = 0;
            cb3.EndRange   = 10;
            cb3.Data       = new Sequence(Alphabets.DNA, "CCCCCCCCCCCCC");

            CacheBox <Sequence> cb4 = new CacheBox <Sequence>(11);

            cb4.StartRange = 0;
            cb4.EndRange   = 10;
            cb4.Data       = new Sequence(Alphabets.DNA, "AAAAAAAAAAAAAA");

            List <CacheBox <Sequence> > cbList = new List <CacheBox <Sequence> >();

            cbList.Add(cb1);
            cbList.Add(cb2);
            cbList.Add(cb3);
            cbList.Add(cb4);

            switch (addParam)
            {
            case AdditionalParameters.Add:
                vdObj.Add(cb1);
                vdObj.Add(cb2);
                vdObj.Add(cb3);
                vdObj.Add(cb4);

                for (int i = 0; i < vdObj.Count; i++)
                {
                    Assert.AreEqual(cbList[i].Data, vdObj[i].Data);
                }

                // Logs to the NUnit GUI (Console.Out) window
                Console.WriteLine(
                    "Virtual Data BVT : Successfully validated the Add() method.");
                ApplicationLog.WriteLine(
                    "Virtual Data BVT : Successfully validated the Add() method.");
                break;

            case AdditionalParameters.AddData:
                vdObj.AddData(new Sequence(Alphabets.DNA, "GGGGGGGGGGGGG"), 0, 10);
                vdObj.AddData(new Sequence(Alphabets.DNA, "TTTTTTTTTTTTT"), 0, 10);
                vdObj.AddData(new Sequence(Alphabets.DNA, "CCCCCCCCCCCCC"), 0, 10);
                vdObj.AddData(new Sequence(Alphabets.DNA, "AAAAAAAAAAAAAA"), 0, 10);

                for (int i = 0; i < vdObj.Count; i++)
                {
                    Assert.AreEqual(cbList[i].Data.ToString(), vdObj[i].Data.ToString());
                }

                // Logs to the NUnit GUI (Console.Out) window
                Console.WriteLine(
                    "Virtual Data BVT : Successfully validated the AddData() method.");
                ApplicationLog.WriteLine(
                    "Virtual Data BVT : Successfully validated the AddData() method.");
                break;

            case AdditionalParameters.AddDelay:
                vdObj.MaxNumberOfBlocks = 2;
                vdObj.Add(cb1);
                vdObj.Add(cb2);
                // Sleep for 20 seconds so that the cache box would be cleared
                // and the count of items in the VirtualData would be reduced
                Thread.Sleep(20000);
                vdObj.Add(cb3);
                vdObj.Add(cb4);

                for (int i = 0; i < vdObj.Count; i++)
                {
                    Assert.AreEqual(cbList[i + 2].Data, vdObj[i].Data);
                }

                // Logs to the NUnit GUI (Console.Out) window
                Console.WriteLine(
                    "Virtual Data BVT : Successfully validated the Add() method.");
                ApplicationLog.WriteLine(
                    "Virtual Data BVT : Successfully validated the Add() method.");
                break;

            case AdditionalParameters.AddDataDelay:
                vdObj.MaxNumberOfBlocks = 2;
                vdObj.AddData(new Sequence(Alphabets.DNA, "GGGGGGGGGGGGG"), 0, 10);
                vdObj.AddData(new Sequence(Alphabets.DNA, "TTTTTTTTTTTTT"), 0, 10);
                // Sleep for 20 seconds so that the cache box would be cleared
                // and the count of items in the VirtualData would be reduced
                Thread.Sleep(20000);
                vdObj.AddData(new Sequence(Alphabets.DNA, "CCCCCCCCCCCCC"), 0, 10);
                vdObj.AddData(new Sequence(Alphabets.DNA, "AAAAAAAAAAAAAA"), 0, 10);

                for (int i = 0; i < vdObj.Count; i++)
                {
                    Assert.AreEqual(cbList[i + 2].Data.ToString(), vdObj[i].Data.ToString());
                }

                // Logs to the NUnit GUI (Console.Out) window
                Console.WriteLine(
                    "Virtual Data BVT : Successfully validated the AddData() method.");
                ApplicationLog.WriteLine(
                    "Virtual Data BVT : Successfully validated the AddData() method.");
                break;

            case AdditionalParameters.Clear:
                vdObj.Add(cb1);
                vdObj.Add(cb2);
                vdObj.Add(cb3);
                vdObj.Add(cb4);
                vdObj.Clear();
                Assert.AreEqual(0, vdObj.Count);
                // Logs to the NUnit GUI (Console.Out) window
                Console.WriteLine(
                    "Virtual Data BVT : Successfully validated the Clear() method.");
                ApplicationLog.WriteLine(
                    "Virtual Data BVT : Successfully validated the Clear() method.");
                break;

            case AdditionalParameters.ClearStaleData:
                vdObj.MaxNumberOfBlocks = 2;
                vdObj.Add(cb1);
                vdObj.Add(cb2);
                // Sleep for 20 seconds so that the cache box would be cleared
                // and the count of items in the VirtualData would be reduced
                Thread.Sleep(20000);
                vdObj.Add(cb3);
                vdObj.Add(cb4);
                Assert.IsTrue(3 > vdObj.Count);
                // Logs to the NUnit GUI (Console.Out) window
                Console.WriteLine(
                    "Virtual Data BVT : Successfully validated the ClearStaleData() method.");
                ApplicationLog.WriteLine(
                    "Virtual Data BVT : Successfully validated the ClearStaleData() method.");
                break;

            case AdditionalParameters.GetAllData:
                vdObj.Add(cb1);
                vdObj.Add(cb2);
                vdObj.Add(cb3);
                vdObj.Add(cb4);
                // Gets all the data in Virtual data object
                IList <Sequence> allSeqData = vdObj.GetAllData();
                for (int i = 0; i < allSeqData.Count; i++)
                {
                    Assert.AreEqual(cbList[i].Data.ToString(), allSeqData[i].ToString());
                }

                // Logs to the NUnit GUI (Console.Out) window
                Console.WriteLine(
                    "Virtual Data BVT : Successfully validated the GetAllData() method.");
                ApplicationLog.WriteLine(
                    "Virtual Data BVT : Successfully validated the GetAllData() method.");
                break;

            case AdditionalParameters.GetData:
                vdObj.Add(cb1);
                vdObj.Add(cb2);
                vdObj.Add(cb3);
                vdObj.Add(cb4);
                // Gets the data in Virtual data object
                for (int i = 0; i < vdObj.Count; i++)
                {
                    Assert.AreEqual(cbList[i].Data.ToString(), vdObj.GetData(i).ToString());
                }

                // Logs to the NUnit GUI (Console.Out) window
                Console.WriteLine(
                    "Virtual Data BVT : Successfully validated the GetData() method.");
                ApplicationLog.WriteLine(
                    "Virtual Data BVT : Successfully validated the GetData() method.");
                break;

            case AdditionalParameters.GetEnumerator:
                vdObj.Add(cb1);
                vdObj.Add(cb2);
                IEnumerator <CacheBox <Sequence> > enumObj = vdObj.GetEnumerator();
                Assert.IsTrue(null != enumObj);
                Assert.AreEqual(cb1, vdObj.FirstOrDefault(C => 0 >= C.StartRange && 0 <= C.EndRange));
                // Logs to the NUnit GUI (Console.Out) window
                Console.WriteLine(
                    "Virtual Data BVT : Successfully validated the GetEnumerator() method.");
                ApplicationLog.WriteLine(
                    "Virtual Data BVT : Successfully validated the GetEnumerator() method.");
                break;

            case AdditionalParameters.Insert:
                vdObj.Add(cb1);
                vdObj.Add(cb2);
                vdObj.Add(cb3);
                // Inserts the cache box in Virtual data object
                vdObj.Insert(3, cb4);
                for (int i = 0; i < vdObj.Count; i++)
                {
                    Assert.AreEqual(cbList[i].Data, vdObj[i].Data);
                }

                // Logs to the NUnit GUI (Console.Out) window
                Console.WriteLine(
                    "Virtual Data BVT : Successfully validated the Insert() method.");
                ApplicationLog.WriteLine(
                    "Virtual Data BVT : Successfully validated the Insert() method.");
                break;

            case AdditionalParameters.Remove:
                vdObj.Add(cb1);
                vdObj.Add(cb2);
                vdObj.Add(cb3);
                vdObj.Add(cb4);

                // Add a Cache Box and remove the same
                CacheBox <Sequence> cb5 = new CacheBox <Sequence>(11);
                cb5.StartRange = 0;
                cb5.EndRange   = 10;
                cb5.Data       = new Sequence(Alphabets.DNA, "AAAAAATTTTTTT");
                vdObj.Add(cb5);
                vdObj.Remove(cb5);
                // Removes the cache box from the virtual data list
                for (int i = 0; i < cbList.Count; i++)
                {
                    Assert.AreEqual(cbList[i].Data, vdObj[i].Data);
                }

                // Logs to the NUnit GUI (Console.Out) window
                Console.WriteLine(
                    "Virtual Data BVT : Successfully validated the Remove() method.");
                ApplicationLog.WriteLine(
                    "Virtual Data BVT : Successfully validated the Remove() method.");
                break;

            case AdditionalParameters.RemoveAt:
                vdObj.Add(cb1);
                vdObj.Add(cb2);
                vdObj.Add(cb3);
                vdObj.Add(cb4);

                // Add a Cache Box and remove the same
                CacheBox <Sequence> cbRemove = new CacheBox <Sequence>(11);
                cbRemove.StartRange = 0;
                cbRemove.EndRange   = 10;
                cbRemove.Data       = new Sequence(Alphabets.DNA, "AAAAAATTTTTTT");
                vdObj.Add(cbRemove);
                vdObj.RemoveAt(4);

                for (int i = 0; i < cbList.Count; i++)
                {
                    Assert.AreEqual(cbList[i].Data, vdObj[i].Data);
                }

                // Logs to the NUnit GUI (Console.Out) window
                Console.WriteLine(
                    "Virtual Data BVT : Successfully validated the RemoveAt() method.");
                ApplicationLog.WriteLine(
                    "Virtual Data BVT : Successfully validated the RemoveAt() method.");
                break;

            case AdditionalParameters.Contains:
                vdObj.Add(cb1);
                vdObj.Add(cb2);
                vdObj.Add(cb3);
                vdObj.Add(cb4);
                // Validates the contains block
                Assert.IsTrue(vdObj.Contains(cb4));

                // Logs to the NUnit GUI (Console.Out) window
                Console.WriteLine(
                    "Virtual Data BVT : Successfully validated the Contains() method.");
                ApplicationLog.WriteLine(
                    "Virtual Data BVT : Successfully validated the Contains() method.");
                break;

            case AdditionalParameters.CopyTo:
                vdObj.Add(cb1);
                vdObj.Add(cb2);
                vdObj.Add(cb3);
                vdObj.Add(cb4);
                CacheBox <Sequence>[] cbArray = new CacheBox <Sequence> [vdObj.Count];
                vdObj.CopyTo(cbArray, 0);

                for (int i = 0; i < vdObj.Count; i++)
                {
                    Assert.AreEqual(cbArray[i].Data, vdObj[i].Data);
                }

                // Logs to the NUnit GUI (Console.Out) window
                Console.WriteLine(
                    "Virtual Data BVT : Successfully validated the CopyTo() method.");
                ApplicationLog.WriteLine(
                    "Virtual Data BVT : Successfully validated the CopyTo() method.");
                break;

            default:
                break;
            }
        }