//+------------------------------------------------------------------+ //| TestHashMap.mq5 | //| Copyright 2000-2025, MetaQuotes Ltd. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #include #include //+------------------------------------------------------------------+ //| TestMisc_Constructor. | //+------------------------------------------------------------------+ bool TestMisc_Constructor(const int count) { //--- create arrays int keys[]; string values[]; ArrayResize(keys,count); ArrayResize(values,count); for(int i=0; icomparer(); CHashMapmap_test(GetPointer(comparer)); for(int i=0; imap_copy(GetPointer(map_test)); //--- check if(map_copy.Count()!=map_test.Count()) return(false); if(map_test.Comparer()!=GetPointer(comparer)) return(false); if(map_copy.Comparer()==GetPointer(comparer)) return(false); //--- successful return(true); } //+------------------------------------------------------------------+ //| TestMisc_Contains. | //+------------------------------------------------------------------+ bool TestMisc_Contains(const int count) { //--- create arrays int keys[]; string values[]; ArrayResize(keys,count); ArrayResize(values,count); for(int i=0; imap_test(); for(int i=0; imap_test(); for(int i=0; ipair(keys[i],values[i]); if(!map_test.Remove(GetPointer(pair))) return(false); } //--- check if(map_test.Count()!=0) return(false); //--- successful return(true); } //+------------------------------------------------------------------+ //| TestMisc. | //+------------------------------------------------------------------+ bool TestMisc(const string test_name) { PrintFormat("%s started",test_name); //--- test 1 PrintFormat("%s: Test 1: Testing Constructor of map based on another map.",test_name); if(!TestMisc_Constructor(16)) return(false); //--- test 2 PrintFormat("%s: Test 2: Complex validation of Contains, ContainsKey and ContainsValues methods.",test_name); if(!TestMisc_Contains(16)) return(false); //--- test 3 PrintFormat("%s: Test 3: Complex validation of Remove method for elements which contains and does not conatains in the map.",test_name); if(!TestMisc_Remove(16)) return(false); //--- successful PrintFormat("%s passed",test_name); return(true); } //+------------------------------------------------------------------+ //| TestHashMap. | //+------------------------------------------------------------------+ void TestHashMap(int &tests_performed,int &tests_passed) { string test_name=""; //--- Misc functions tests_performed++; test_name="Misc functions test"; if(TestMisc(test_name)) tests_passed++; else PrintFormat("%s failed",test_name); } //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { MathSrand(0); string package_name="Generic"; PrintFormat("Unit tests for Package %s\n",package_name); //--- initial values int tests_performed=0; int tests_passed=0; //--- test distributions TestHashMap(tests_performed,tests_passed); //--- print statistics PrintFormat("\n%d of %d passed",tests_passed,tests_performed); } //+------------------------------------------------------------------+