private void BinaryRemoveButton_Click(object sender, EventArgs e) { if (!File.Exists(_binaryFile)) { ShowMessage("Odstranì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(false); if (dialog.ShowDialog() == DialogResult.OK) { try { if (bs.RemoveItem(dialog.Key, dialog.Method)) { ShowMessage("Prvek s klíèem '" + dialog.Key + "' byl odstranìn!", MessageBoxIcon.Information, "Odstranìní"); } else { ShowMessage("Prvek s klíèem '" + dialog.Key + "' nebylo možné odstranit!\nJe možné že již byl odstranìn!", MessageBoxIcon.Warning, "Odstranìní"); } } catch (Exception ex) { ShowMessage(ex.Message, MessageBoxIcon.Error, "Chyba"); } } }
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(); }
public void Remove_Binary_Test() { List <DataItem> data = Random(1000); BinaryStorage <DataItem> bw = new BinaryStorage <DataItem>(_testFile, 100); bw.WriteBinaryFile(data); bool state; foreach (var d in data) { state = bw.RemoveItem(d.Key, SearchMethod.Binary); Assert.IsTrue(state); } }
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)); } }
public void Remove_Binary_More_Test() { List <DataItem> data = Random(2000); List <DataItem> delete = Random(3000); BinaryStorage <DataItem> bw = new BinaryStorage <DataItem>(_testFile, 100); bw.WriteBinaryFile(data); bool state; for (int i = 1; i <= 3000; i++) { state = bw.RemoveItem(delete[i - 1].Key, SearchMethod.Binary); if (i > 2000) { Assert.IsFalse(state); } else { Assert.IsTrue(state); } } }