示例#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();
        }
示例#2
0
        private void BinarySearchButton_Click(object sender, EventArgs e)
        {
            if (!File.Exists(_binaryFile))
            {
                ShowMessage("Vyhledávání není možné provést!\nBinární soubor není inicializován!\n\nPrvnì ho inicializujte!", MessageBoxIcon.Warning, "Chyba");
                return;
            }

            BinaryStorage <VertexData> bs     = new BinaryStorage <VertexData>(_binaryFile);
            BinaryFindRemoveDialog     dialog = new BinaryFindRemoveDialog();

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    VertexData item = bs.Find(dialog.Key, dialog.Method);
                    if (item != null)
                    {
                        ShowMessage("Prvek s klíèem '" + dialog.Key + "' byl Nalezen!\nSouøadnice: [" + item.X + ", " + item.Y + "]", MessageBoxIcon.Information, "Vyhledání");
                    }
                    else
                    {
                        ShowMessage("Prvek s klíèem '" + dialog.Key + "' nebylo možné odstranit!\nJe možné že již byl odstranìn!", MessageBoxIcon.Warning, "Vyhledání");
                    }
                }
                catch (Exception ex)
                {
                    ShowMessage(ex.Message, MessageBoxIcon.Error, "Chyba");
                }
            }
        }
示例#3
0
        public void Find_Interpolation_1Items_Test()
        {
            List <DataItem>          data = Random(1);
            BinaryStorage <DataItem> bw   = new BinaryStorage <DataItem>(_testFile, 100);

            bw.WriteBinaryFile(data);

            DataItem find;

            foreach (DataItem expect in data)
            {
                find = bw.Find(expect.Key, SearchMethod.Interpolation);
                Assert.IsNotNull(find);
            }
        }
示例#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));
            }
        }
示例#5
0
        public void Find_Binary_1500Items_500NotFound_Test()
        {
            List <DataItem> data   = Random(1500);
            List <DataItem> search = Random(2000);

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

            bw.WriteBinaryFile(data);

            DataItem find;

            for (int i = 1; i <= 2000; i++)
            {
                find = bw.Find(search[i - 1].Key, SearchMethod.Binary);
                if (i > 1500)
                {
                    Assert.IsNull(find);
                }
                else
                {
                    Assert.IsNotNull(find);
                }
            }
        }