From 83394a2b0535da86930c2d9d07fb9f997d3f0e57 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 1 Dec 2012 22:59:52 +0200 Subject: [PATCH] Improve maputils test cases --- tests/maputils.cpp | 46 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/tests/maputils.cpp b/tests/maputils.cpp index 78cdaad..31c2232 100644 --- a/tests/maputils.cpp +++ b/tests/maputils.cpp @@ -13,28 +13,56 @@ public: static const char *get_name() { return "maputils"; } private: - void success(); - void error(); + void get_item(); + void insert_unique(); + void nonexistent_item(); + void key_collision(); + void uncastable_key(); }; MapUtilTests::MapUtilTests() { - add(&MapUtilTests::success, "success"); - add(&MapUtilTests::error, "error").expect_throw(); + add(&MapUtilTests::get_item, "get_item"); + add(&MapUtilTests::insert_unique, "insert_unique"); + add(&MapUtilTests::nonexistent_item, "nonexistent item").expect_throw(); + add(&MapUtilTests::key_collision, "key collision").expect_throw(); + add(&MapUtilTests::uncastable_key, "uncastable key").expect_throw(); } -void MapUtilTests::success() +void MapUtilTests::get_item() { map m; m[1] = "foo"; m[3] = "bar"; - EXPECT_EQUAL(get_item(m, 1), "foo"); - EXPECT_EQUAL(get_item(m, 3), "bar"); + EXPECT_EQUAL(::get_item(m, 1), "foo"); + EXPECT_EQUAL(::get_item(m, 3), "bar"); } -void MapUtilTests::error() +void MapUtilTests::insert_unique() { map m; - get_item(m, 0); + ::insert_unique(m, 1, "foo"); + ::insert_unique(m, 3, "bar"); + EXPECT_EQUAL(m.count(1), 1); + EXPECT_EQUAL(m.count(3), 1); +} + +void MapUtilTests::nonexistent_item() +{ + map m; + ::get_item(m, 0); +} + +void MapUtilTests::key_collision() +{ + map m; + ::insert_unique(m, 1, "foo"); + ::insert_unique(m, 1, "bar"); +} + +void MapUtilTests::uncastable_key() +{ + map, string> m; + ::get_item(m, make_pair(0, 0)); } -- 2.45.2