private void InitCommand() { Open = new CommandBase(obj => { DictionaryOperation?.Invoke(this, new CommandArgs(obj, nameof(Open))); }); ReName = new CommandBase(obj => { DictionaryOperation?.Invoke(this, new CommandArgs(obj, nameof(ReName))); }); ReMove = new CommandBase(obj => { DictionaryOperation?.Invoke(this, new CommandArgs(obj, nameof(ReMove))); }); Select = new CommandBase(obj => { DictionaryOperation?.Invoke(this, new CommandArgs(obj, nameof(Select))); }); }
// tests if all dicts return the same result for random operations public static void ParallelTest <T>(T[] dicts) where T : Dictionary { if (dicts.Length == 0) { return; } Console.WriteLine("----- Parallel Testing {0} -----", typeof(T).Name); testCount++; DictionaryOperation[][] operations = new DictionaryOperation[dicts.Length][]; for (int i = 0; i < dicts.Length; i++) { operations[i] = new DictionaryOperation[] { dicts[i].Search, dicts[i].Insert, dicts[i].Delete }; } bool[] results = new bool[dicts.Length]; var rng = new Random(); for (int i = 0; i < 30; i++) { int element = rng.Next(1000); int opIndex = rng.Next(operations[0].Length); for (int j = 0; j < dicts.Length; j++) { var operation = operations[j][opIndex]; Console.WriteLine(operation.Method + " - " + element); results[j] = operation(element); } if (!results.Aggregate((a, b) => a == b)) { Console.WriteLine("ParallelTest failed"); foreach (var dict in dicts) { Console.WriteLine(dict.GetType().Name); dict.Print(); Console.WriteLine(); } Console.WriteLine("Results: {0}", String.Join(", ", results)); failedTestCount++; break; } } }
public static void TestOperation(DictionaryOperation op, int element, bool expectedResult) { bool result = op(element); testCount++; if (result != expectedResult) { failedTestCount++; Console.WriteLine("{0}.{1}({2}) returned {3} should be {4}", op.Target.GetType().FullName, op.GetMethodInfo().Name, element, result, expectedResult); } }
private void NotifyDictionaryOperation(TKey key, TValue value, TDictionaryOperation operation) { DictionaryOperation?.Invoke(this, new DictionaryOperationEventArgs <TKey, TValue>(key, value, operation)); }