public void TestLoadLimitNextSequential(IMAGEDB_LOAD_METHOD loadMethod, int nLoadLimit)
        {
            List <string> rgDs = new List <string>()
            {
                "MNIST", "CIFAR-10", "MNIST"
            };
            IXImageDatabase db = new MyCaffeImageDatabase();

            foreach (string strDs in rgDs)
            {
                DatasetFactory df  = new DatasetFactory();
                int            nDs = df.GetDatasetID(strDs);
                if (nDs == 0)
                {
                    throw new Exception("The dataset '" + strDs + "' does not exist - you need to load it.");
                }

                SettingsCaffe settings = new SettingsCaffe();
                settings.ImageDbLoadMethod = loadMethod;
                settings.ImageDbLoadLimit  = nLoadLimit;

                Stopwatch sw = new Stopwatch();

                sw.Start();
                db.InitializeWithDsName(settings, strDs);
                db.SetSelectionMethod(IMGDB_LABEL_SELECTION_METHOD.NONE, IMGDB_IMAGE_SELECTION_METHOD.NONE);
                string str = sw.ElapsedMilliseconds.ToString();
                Trace.WriteLine(strDs + " Initialization Time: " + str + " ms.");

                DatasetDescriptor ds = db.GetDatasetByName(strDs);
                Dictionary <int, List <SimpleDatum> > rg      = new Dictionary <int, List <SimpleDatum> >();
                Dictionary <int, List <SimpleDatum> > rgFirst = new Dictionary <int, List <SimpleDatum> >();

                int    nTotal    = ds.TrainingSource.ImageCount;
                int    nCount    = 0;
                double dfTotalMs = 0;

                while (nCount < nTotal)
                {
                    for (int i = 0; i < nLoadLimit; i++)
                    {
                        sw.Reset();
                        sw.Start();
                        SimpleDatum d1 = db.QueryImage(ds.TrainingSource.ID, i);
                        dfTotalMs += sw.ElapsedMilliseconds;
                        sw.Stop();

                        if (!rg.Keys.Contains(d1.Index))
                        {
                            rg.Add(d1.Index, new List <SimpleDatum>()
                            {
                                d1
                            });
                        }
                        else
                        {
                            rg[d1.Index].Add(d1);
                        }

                        if (nCount == 0)
                        {
                            if (!rgFirst.Keys.Contains(d1.Index))
                            {
                                rgFirst.Add(d1.Index, new List <SimpleDatum>()
                                {
                                    d1
                                });
                            }
                            else
                            {
                                rgFirst[d1.Index].Add(d1);
                            }
                        }
                    }

                    db.LoadNextSet(null);
                    nCount += nLoadLimit;
                }

                str = (dfTotalMs / (double)nCount).ToString();
                Trace.WriteLine("Average Query Time: " + str + " ms.");

                // Verify that all items have been queried
                Assert.AreEqual(nTotal, rg.Count);

                Dictionary <int, List <SimpleDatum> > rgWrapAround = new Dictionary <int, List <SimpleDatum> >();

                for (int i = 0; i < nLoadLimit; i++)
                {
                    SimpleDatum d1 = db.QueryImage(ds.TrainingSource.ID, i);

                    if (!rgWrapAround.Keys.Contains(d1.Index))
                    {
                        rgWrapAround.Add(d1.Index, new List <SimpleDatum>()
                        {
                            d1
                        });
                    }
                    else
                    {
                        rgWrapAround[d1.Index].Add(d1);
                    }
                }

                // Verify that the reads wrap around to the start.
                Assert.AreEqual(rgWrapAround.Count, rgFirst.Count);

                List <KeyValuePair <int, List <SimpleDatum> > > rg1 = new List <KeyValuePair <int, List <SimpleDatum> > >();
                List <KeyValuePair <int, List <SimpleDatum> > > rg2 = new List <KeyValuePair <int, List <SimpleDatum> > >();

                foreach (KeyValuePair <int, List <SimpleDatum> > kv in rgWrapAround)
                {
                    rg1.Add(kv);
                }

                foreach (KeyValuePair <int, List <SimpleDatum> > kv in rgFirst)
                {
                    rg2.Add(kv);
                }

                for (int i = 0; i < rg1.Count; i++)
                {
                    Assert.AreEqual(rg1[i].Key, rg2[i].Key);
                    Assert.AreEqual(rg1[i].Value.Count, rg2[i].Value.Count);

                    for (int j = 0; j < rg1[i].Value.Count; j++)
                    {
                        Assert.AreEqual(rg1[i].Value[j].Label, rg2[i].Value[j].Label);
                    }
                }
            }

            db.CleanUp();

            IDisposable idisp = db as IDisposable;

            if (idisp != null)
            {
                idisp.Dispose();
            }
        }