Esempio n. 1
0
        static void Main(string[] args)
        {
            int         cnt  = 1;
            List <Item> data = Random(cnt);

            BinaryStorage <Item> bw = new BinaryStorage <Item>("./data.bin");

            bw.WriteBinaryFile(data);

            bw.Find("K_1");

            bool res = bw.RemoveItem("K_1");

            bw.Find("K_1");


            List <Item> output = bw.ReadBinaryFile();

            foreach (var i in output)
            {
                Console.WriteLine(i.Key);
            }

            /*for(int i = 1; i <= cnt; i++)
             * {
             *  string search = "K_" + i;
             *  Item val = bw.Find(search, SearchMethod.Interpolation);
             *  if(val == null || val.Key != search)
             *  {
             *      break;
             *  }
             * }*/

            Console.ReadLine();
        }
Esempio n. 2
0
        public void BuildAndRead_OneItem_Test()
        {
            List <DataItem>          data = Random(1);
            BinaryStorage <DataItem> bw   = new BinaryStorage <DataItem>(_testFile, 100);

            bw.WriteBinaryFile(data);

            List <DataItem> readed = bw.ReadBinaryFile();

            ListContainSameValues(data, readed);
        }
Esempio n. 3
0
        public void BuildAndRead_OneThousandItem_Test()
        {
            List <DataItem>          data = Random(1000);
            BinaryStorage <DataItem> bw   = new BinaryStorage <DataItem>(_testFile, 100);

            bw.WriteBinaryFile(data);

            List <DataItem> readed = bw.ReadBinaryFile();

            ListContainSameValues(data, readed);
            Assert.AreEqual(data.Count, readed.Count);
        }
Esempio n. 4
0
        public void Full_Interpolation_Test()
        {
            int             valid = 500;
            int             full  = 700;
            List <DataItem> data  = Random(valid);
            List <DataItem> test  = Random(full);
            var             rand  = new Random((int)DateTime.UtcNow.Ticks);

            BinaryStorage <DataItem> bw = new BinaryStorage <DataItem>(_testFile, 100);

            bw.WriteBinaryFile(data);

            bool state;

            for (int i = 1; i <= full; i++)
            {
                int      idx = rand.Next(0, test.Count - 1);
                DataItem it  = test[idx];

                test.RemoveAt(idx);

                DataItem fi  = bw.Find(it.Key);
                bool     del = bw.RemoveItem(it.Key, SearchMethod.Interpolation);

                if (it.KeyVal > valid)
                {
                    Assert.IsNull(fi);
                    Assert.IsFalse(del);
                }
                else
                {
                    Assert.IsNotNull(fi);
                    Assert.IsTrue(del);
                    data = data.Where(k => k.KeyVal != it.KeyVal).ToList();
                }

                List <DataItem> loaded = bw.ReadBinaryFile();

                Assert.IsTrue(ListContainSameValues(data, loaded));
            }
        }