PageRenderTime 24ms CodeModel.GetById 14ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/libs/unordered/examples/case_insensitive_test.cpp

http://hadesmem.googlecode.com/
C++ | 82 lines | 60 code | 19 blank | 3 comment | 30 complexity | fceed63c7d44371e3d7f49ce2c9102a9 MD5 | raw file
 1
 2// Copyright 2006-2009 Daniel James.
 3// Distributed under the Boost Software License, Version 1.0. (See accompanying
 4// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 5
 6#include "./case_insensitive.hpp"
 7#include <boost/detail/lightweight_test.hpp>
 8#include <boost/unordered_map.hpp>
 9
10struct word_info {
11    int tag;
12    explicit word_info(int t = 0) : tag(t) {}
13};
14
15void test1() {
16    boost::unordered_map<std::string, word_info,
17        hash_examples::ihash, hash_examples::iequal_to> idictionary;
18
19    BOOST_TEST(idictionary.empty());
20
21    idictionary["one"] = word_info(1);
22    BOOST_TEST(idictionary.size() == 1);
23    BOOST_TEST(idictionary.find("ONE") != idictionary.end() &&
24        idictionary.find("ONE") == idictionary.find("one"));
25
26    idictionary.insert(std::make_pair("ONE", word_info(2)));
27    BOOST_TEST(idictionary.size() == 1);
28    BOOST_TEST(idictionary.find("ONE") != idictionary.end() &&
29            idictionary.find("ONE")->first == "one" &&
30            idictionary.find("ONE")->second.tag == 1);
31
32    idictionary["One"] = word_info(3);
33    BOOST_TEST(idictionary.size() == 1);
34    BOOST_TEST(idictionary.find("ONE") != idictionary.end() &&
35            idictionary.find("ONE")->first == "one" &&
36            idictionary.find("ONE")->second.tag == 3);
37
38    idictionary["two"] = word_info(4);
39    BOOST_TEST(idictionary.size() == 2);
40    BOOST_TEST(idictionary.find("two") != idictionary.end() &&
41            idictionary.find("TWO")->first == "two" &&
42            idictionary.find("Two")->second.tag == 4);
43
44
45}
46
47void test2() {
48    boost::unordered_map<std::wstring, word_info,
49        hash_examples::ihash, hash_examples::iequal_to> idictionary;
50
51    BOOST_TEST(idictionary.empty());
52
53    idictionary[L"one"] = word_info(1);
54    BOOST_TEST(idictionary.size() == 1);
55    BOOST_TEST(idictionary.find(L"ONE") != idictionary.end() &&
56        idictionary.find(L"ONE") == idictionary.find(L"one"));
57
58    idictionary.insert(std::make_pair(L"ONE", word_info(2)));
59    BOOST_TEST(idictionary.size() == 1);
60    BOOST_TEST(idictionary.find(L"ONE") != idictionary.end() &&
61            idictionary.find(L"ONE")->first == L"one" &&
62            idictionary.find(L"ONE")->second.tag == 1);
63
64    idictionary[L"One"] = word_info(3);
65    BOOST_TEST(idictionary.size() == 1);
66    BOOST_TEST(idictionary.find(L"ONE") != idictionary.end() &&
67            idictionary.find(L"ONE")->first == L"one" &&
68            idictionary.find(L"ONE")->second.tag == 3);
69
70    idictionary[L"two"] = word_info(4);
71    BOOST_TEST(idictionary.size() == 2);
72    BOOST_TEST(idictionary.find(L"two") != idictionary.end() &&
73            idictionary.find(L"TWO")->first == L"two" &&
74            idictionary.find(L"Two")->second.tag == 4);
75}
76
77int main() {
78    test1();
79    test2();
80
81    return boost::report_errors();
82}