class TestList : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(TestList);
- CPPUNIT_TEST(testList);
+ CPPUNIT_TEST(testAppend);
+ CPPUNIT_TEST(testDetach);
CPPUNIT_TEST_SUITE_END();
public:
- void testList()
+ void testAppend()
{
List<int> l1;
List<int> l2;
l3.append(2);
l3.append(3);
l3.append(4);
+ CPPUNIT_ASSERT_EQUAL(4U, l1.size());
CPPUNIT_ASSERT(l1 == l3);
+ }
+
+ void testDetach()
+ {
+ List<int> l1;
+ l1.append(1);
+ l1.append(2);
+ l1.append(3);
+ l1.append(4);
- List<int> l4 = l1;
- List<int>::Iterator it = l4.find(3);
+ List<int> l2 = l1;
+ List<int>::Iterator it = l2.find(3);
*it = 33;
- CPPUNIT_ASSERT_EQUAL(l1[2], 3);
- CPPUNIT_ASSERT_EQUAL(l4[2], 33);
+ CPPUNIT_ASSERT_EQUAL(3, l1[2]);
+ CPPUNIT_ASSERT_EQUAL(33, l2[2]);
}
+
};
CPPUNIT_TEST_SUITE_REGISTRATION(TestList);
{
CPPUNIT_TEST_SUITE(TestMap);
CPPUNIT_TEST(testInsert);
+ CPPUNIT_TEST(testDetach);
CPPUNIT_TEST_SUITE_END();
public:
{
Map<String, int> m1;
m1.insert("foo", 3);
+ m1.insert("bar", 5);
+ CPPUNIT_ASSERT_EQUAL(2U, m1.size());
CPPUNIT_ASSERT_EQUAL(3, m1["foo"]);
+ CPPUNIT_ASSERT_EQUAL(5, m1["bar"]);
m1.insert("foo", 7);
+ CPPUNIT_ASSERT_EQUAL(2U, m1.size());
CPPUNIT_ASSERT_EQUAL(7, m1["foo"]);
+ CPPUNIT_ASSERT_EQUAL(5, m1["bar"]);
+ }
- m1.insert("alice", 5);
- m1.insert("bob", 9);
+ void testDetach()
+ {
+ Map<String, int> m1;
+ m1.insert("alice", 5);
+ m1.insert("bob", 9);
m1.insert("carol", 11);
Map<String, int> m2 = m1;
Map<String, int>::Iterator it = m2.find("bob");
(*it).second = 99;
- CPPUNIT_ASSERT_EQUAL(m1["bob"], 9);
- CPPUNIT_ASSERT_EQUAL(m2["bob"], 99);
+ CPPUNIT_ASSERT_EQUAL(9, m1["bob"]);
+ CPPUNIT_ASSERT_EQUAL(99, m2["bob"]);
}
};