diff --git a/imap.h b/imap.h index 62bf4b88..41007672 100644 --- a/imap.h +++ b/imap.h @@ -4,6 +4,7 @@ The MIT License(MIT) Embedded Template Library. +https://github.com/ETLCPP/etl Copyright(c) 2014 jwellbelove, rlindeman @@ -56,8 +57,8 @@ namespace etl { public: + typedef TKey key_type; typedef std::pair value_type; - typedef const TKey key_type; typedef TMapped mapped_type; typedef TKeyCompare key_compare; typedef value_type& reference; @@ -71,7 +72,7 @@ namespace etl //************************************************************************* struct key_comp { - bool operator ()(key_type& key1, key_type& key2) const + bool operator ()(const key_type& key1, const key_type& key2) const { return key_compare()(key1, key2); } @@ -1739,7 +1740,7 @@ namespace etl balance_parent = replace_parent; balance = replace; } - + // Keep searching for the replacement node replace_parent = replace; replace = replace->children[replace->dir]; @@ -1909,7 +1910,7 @@ namespace etl void rotate_3node(Node*& position, uint8_t dir, uint8_t third) { // __A__ __E__ __A__ __D__ - // _B_ C -> B A OR B _C_ -> A C + // _B_ C -> B A OR B _C_ -> A C // D E D F G C D E B F G E // F G F G // E (new position) becomes the root diff --git a/test/codeblocks/ETL.cbp b/test/codeblocks/ETL.cbp index 8d8fcf4d..31be0c4f 100644 --- a/test/codeblocks/ETL.cbp +++ b/test/codeblocks/ETL.cbp @@ -154,6 +154,7 @@ + @@ -172,6 +173,8 @@ + + @@ -215,6 +218,7 @@ + diff --git a/test/codeblocks/ETL.depend b/test/codeblocks/ETL.depend index 5b8ff89e..6ce46ec6 100644 --- a/test/codeblocks/ETL.depend +++ b/test/codeblocks/ETL.depend @@ -359,6 +359,18 @@ "../map.h" +1423387319 source:u:\users\john\documents\programming\github\etl\test\test_set.cpp + + + + + + + + + + "../set.h" + 1421962897 u:\users\john\documents\programming\github\etl\test\extracheckmacros.h diff --git a/test/codeblocks/ETL.layout b/test/codeblocks/ETL.layout index 54b23a2a..f0ef022a 100644 --- a/test/codeblocks/ETL.layout +++ b/test/codeblocks/ETL.layout @@ -66,6 +66,11 @@ + + + + + @@ -191,6 +196,11 @@ + + + + + diff --git a/test/test_map.cpp b/test/test_map.cpp index 41a0c3e2..d0af7b2d 100644 --- a/test/test_map.cpp +++ b/test/test_map.cpp @@ -2,6 +2,7 @@ The MIT License(MIT) Embedded Template Library. +https://github.com/ETLCPP/etl Copyright(c) 2014 jwellbelove, rlindeman @@ -34,6 +35,8 @@ SOFTWARE. #include #include +#include + #include "../map.h" static const size_t SIZE = 10; @@ -53,7 +56,7 @@ typedef Compare_Data::iterator Compare_Data_iterator; typedef Compare_Data::const_iterator Compare_Data_const_iterator; //************************************************************************* -std::ostream& operator << (std::ostream& os, const Data_iterator& it) +static std::ostream& operator << (std::ostream& os, const Data_iterator& it) { os << (*it).first << " " << (*it).second; @@ -61,7 +64,7 @@ std::ostream& operator << (std::ostream& os, const Data_iterator& it) } //************************************************************************* -std::ostream& operator << (std::ostream& os, const Data_const_iterator& it) +static std::ostream& operator << (std::ostream& os, const Data_const_iterator& it) { os << (*it).first << " " << (*it).second; @@ -69,7 +72,7 @@ std::ostream& operator << (std::ostream& os, const Data_const_iterator& it) } //************************************************************************* -std::ostream& operator << (std::ostream& os, const Compare_Data_iterator& it) +static std::ostream& operator << (std::ostream& os, const Compare_Data_iterator& it) { os << (*it).first << " " << (*it).second; @@ -77,7 +80,7 @@ std::ostream& operator << (std::ostream& os, const Compare_Data_iterator& it) } //************************************************************************* -std::ostream& operator << (std::ostream& os, const Compare_Data_const_iterator& it) +static std::ostream& operator << (std::ostream& os, const Compare_Data_const_iterator& it) { os << (*it).first << " " << (*it).second; @@ -88,11 +91,6 @@ namespace { SUITE(test_map) { - std::vector initial_data; - std::vector excess_data; - std::vector different_data; - std::vector random_data; - //************************************************************************* template bool Check_Equal(T1 begin1, T1 end1, T2 begin2) @@ -114,69 +112,62 @@ namespace //************************************************************************* struct SetupFixture { + // Maps of predefined data from which to constuct maps used in each test + std::map initial_data; + std::map excess_data; + std::map different_data; + std::map random_data; + SetupFixture() { - Data::value_type n[] = - { - { std::string("0"), 0 }, - { std::string("1"), 1 }, - { std::string("2"), 2 }, - { std::string("3"), 3 }, - { std::string("4"), 4 }, - { std::string("5"), 5 }, - { std::string("6"), 6 }, - { std::string("7"), 7 }, - { std::string("8"), 8 }, - { std::string("9"), 9 }, - }; + // Create a map of initial data + initial_data["0"] = 0; + initial_data["1"] = 1; + initial_data["2"] = 2; + initial_data["3"] = 3; + initial_data["4"] = 4; + initial_data["5"] = 5; + initial_data["6"] = 6; + initial_data["7"] = 7; + initial_data["8"] = 8; + initial_data["9"] = 9; - Data::value_type n2[] = - { - { std::string("0"), 0 }, - { std::string("1"), 1 }, - { std::string("2"), 2 }, - { std::string("3"), 3 }, - { std::string("4"), 4 }, - { std::string("5"), 5 }, - { std::string("6"), 6 }, - { std::string("7"), 7 }, - { std::string("8"), 8 }, - { std::string("9"), 9 }, - { std::string("10"), 10 }, - }; + // Create a map of excess data + excess_data["0"] = 0; + excess_data["1"] = 1; + excess_data["2"] = 2; + excess_data["3"] = 3; + excess_data["4"] = 4; + excess_data["5"] = 5; + excess_data["6"] = 6; + excess_data["7"] = 7; + excess_data["8"] = 8; + excess_data["9"] = 9; + excess_data["10"] = 10; - Data::value_type n3[] = - { - { std::string("10"), 10 }, - { std::string("11"), 11 }, - { std::string("12"), 12 }, - { std::string("13"), 13 }, - { std::string("14"), 14 }, - { std::string("15"), 15 }, - { std::string("16"), 16 }, - { std::string("17"), 17 }, - { std::string("18"), 18 }, - { std::string("19"), 19 }, - }; + // Create a map of different data + different_data["10"] = 10; + different_data["11"] = 11; + different_data["12"] = 12; + different_data["13"] = 13; + different_data["14"] = 14; + different_data["15"] = 15; + different_data["16"] = 16; + different_data["17"] = 17; + different_data["18"] = 18; + different_data["19"] = 19; - Data::value_type n4[] = - { - { std::string("6"), 6 }, - { std::string("5"), 5 }, - { std::string("0"), 0 }, - { std::string("8"), 8 }, - { std::string("9"), 9 }, - { std::string("2"), 2 }, - { std::string("1"), 1 }, - { std::string("3"), 3 }, - { std::string("7"), 7 }, - { std::string("4"), 4 }, - }; - - initial_data.assign(std::begin(n), std::end(n)); - excess_data.assign(std::begin(n2), std::end(n2)); - different_data.assign(std::begin(n3), std::end(n3)); - random_data.assign(std::begin(n4), std::end(n4)); + // Create a map of random data + random_data["6"] = 6; + random_data["5"] = 5; + random_data["0"] = 0; + random_data["8"] = 8; + random_data["9"] = 9; + random_data["2"] = 2; + random_data["1"] = 1; + random_data["3"] = 3; + random_data["7"] = 7; + random_data["4"] = 4; } }; diff --git a/test/test_set.cpp b/test/test_set.cpp index f48d2ee2..cb9b5c2c 100644 --- a/test/test_set.cpp +++ b/test/test_set.cpp @@ -80,11 +80,6 @@ namespace { SUITE(test_set) { - std::vector initial_data; - std::vector excess_data; - std::vector different_data; - std::vector random_data; - //************************************************************************* template bool Check_Equal(T1 begin1, T1 end1, T2 begin2) @@ -106,9 +101,14 @@ namespace //************************************************************************* struct SetupFixture { + std::vector initial_data; + std::vector excess_data; + std::vector different_data; + std::vector random_data; + SetupFixture() { - Data::value_type n[] = + int n[] = { { 0 }, { 1 }, @@ -137,7 +137,7 @@ namespace { 10 }, }; - Data::value_type n3[] = + int n3[] = { { 10 }, { 11 }, @@ -151,7 +151,7 @@ namespace { 19 }, }; - Data::value_type n4[] = + int n4[] = { { 6 }, { 5 },