private static List <string> Instantiate(int count, int dataLenght, int repeat) { List <string> results = new List <string>(); // create data for constructor List <bool[]> constructorData = CreateContructorData(count, dataLenght); results.Add("[INFO] Instantiating " + count + " objects of type 'BoolArrayKey' with data lenght " + dataLenght); results.Add("[REPEAT] " + repeat); Stopwatch s = new Stopwatch(); s.Start(); for (int k = 0; k < repeat; k++) { for (int i = 0; i < count; i++) { // instantiate object BoolArrayKey obj = new BoolArrayKey(constructorData[i]); } } s.Stop(); results.Add("[AVG TIME] " + s.ElapsedMilliseconds / repeat + " ms"); return(results); }
public override bool Equals(object obj) { BoolArrayKey other = obj as BoolArrayKey; if (other == null) { return(false); } return(other.data.SequenceEqual(data)); }
public void AddToHashSet_CheckIfAddedByReference() { // arrange - add 1 item to hashset bool[] data = { true, true, false, false }; BoolArrayKey item = new BoolArrayKey(data); HashSet <BoolArrayKey> set = new HashSet <BoolArrayKey>(); set.Add(item); // assert - check if hashet contains item Assert.IsTrue(set.Contains(item)); }
public void AddToHashSet_CheckIfAddedByData() { // arrange - add 1 item to hashset bool[] data = { true, true, false, false }; BoolArrayKey item = new BoolArrayKey(data); HashSet <BoolArrayKey> set = new HashSet <BoolArrayKey>(); set.Add(item); // arrange create another item with the same data bool[] data2 = { true, true, false, false }; BoolArrayKey item2 = new BoolArrayKey(data2); // assert - check if hashet contains the second item Assert.IsTrue(set.Contains(item2)); }