当前位置: 首页>>代码示例>>C++>>正文


C++ TArray::nthAddr方法代码示例

本文整理汇总了C++中TArray::nthAddr方法的典型用法代码示例。如果您正苦于以下问题:C++ TArray::nthAddr方法的具体用法?C++ TArray::nthAddr怎么用?C++ TArray::nthAddr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TArray的用法示例。


在下文中一共展示了TArray::nthAddr方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: test_insert_remove

    void test_insert_remove(void)
    {
        TArray<int> arr;

        arr.initialize(2);
        CPPUNIT_ASSERT_EQUAL((hyu32)0, arr.size());
        HMD_ASSERT_HALT(arr.insert(1));
        arr.insert(0) = 10;
        CPPUNIT_ASSERT_EQUAL((hyu32)1, arr.size());
        CPPUNIT_ASSERT_EQUAL(10, arr[0]);
        arr.insert(0) = 20;
        CPPUNIT_ASSERT_EQUAL((hyu32)2, arr.size());
        CPPUNIT_ASSERT_EQUAL(20, arr[0]);
        CPPUNIT_ASSERT_EQUAL(10, arr[1]);
        arr.insert(1) = 30;
        CPPUNIT_ASSERT_EQUAL((hyu32)3, arr.size());
        CPPUNIT_ASSERT_EQUAL(20, arr[0]);
        CPPUNIT_ASSERT_EQUAL(30, arr[1]);
        CPPUNIT_ASSERT_EQUAL(10, arr[2]);
        arr.insert(3) = 40;
        CPPUNIT_ASSERT_EQUAL((hyu32)4, arr.size());
        CPPUNIT_ASSERT_EQUAL(20, arr[0]);
        CPPUNIT_ASSERT_EQUAL(30, arr[1]);
        CPPUNIT_ASSERT_EQUAL(10, arr[2]);
        CPPUNIT_ASSERT_EQUAL(40, arr[3]);
        arr.insert(-1) = 50;
        CPPUNIT_ASSERT_EQUAL((hyu32)5, arr.size());
        CPPUNIT_ASSERT_EQUAL(20, arr[0]);
        CPPUNIT_ASSERT_EQUAL(30, arr[1]);
        CPPUNIT_ASSERT_EQUAL(10, arr[2]);
        CPPUNIT_ASSERT_EQUAL(50, arr[3]);
        CPPUNIT_ASSERT_EQUAL(40, arr[4]);

        arr.remove(2);
        CPPUNIT_ASSERT_EQUAL((hyu32)4, arr.size());
        CPPUNIT_ASSERT_EQUAL(20, arr[0]);
        CPPUNIT_ASSERT_EQUAL(30, arr[1]);
        CPPUNIT_ASSERT_EQUAL(50, arr[2]);
        CPPUNIT_ASSERT_EQUAL(40, arr[3]);
        arr.remove(-3);
        CPPUNIT_ASSERT_EQUAL((hyu32)3, arr.size());
        CPPUNIT_ASSERT_EQUAL(20, arr[0]);
        CPPUNIT_ASSERT_EQUAL(50, arr[1]);
        CPPUNIT_ASSERT_EQUAL(40, arr[2]);
        HMD_ASSERT_HALT(arr.remove(3));
        HMD_ASSERT_HALT(arr.remove(-4));

        int* p = arr.nthAddr(3);
        int* q = arr.addSpaces(2);
        CPPUNIT_ASSERT_EQUAL((hyu32)5, arr.size());
        CPPUNIT_ASSERT_EQUAL(p, q);
    }
开发者ID:FUKUZAWA-Tadashi,项目名称:Hayat,代码行数:52,代码来源:Test_hyArray.cpp

示例2: test_array

    void test_array(void)
    {
        int dat[10] = { 100, 110, 120, -130, 140, -15000, 16000, 1700, 18, 19000 };
        TArray<int> arr;

        arr.initialize(0);
        CPPUNIT_ASSERT_EQUAL((int*)NULL, arr.m_contents);
        CPPUNIT_ASSERT_EQUAL((hyu32)0, arr.size());
        CPPUNIT_ASSERT_EQUAL((hyu32)0, arr.m_capacity);

        arr.initialize(2);
        CPPUNIT_ASSERT(arr.m_contents != NULL);
        CPPUNIT_ASSERT_EQUAL((hyu32)0, arr.size());
        CPPUNIT_ASSERT_EQUAL((hyu32)2, arr.m_capacity);
        arr.add(dat, 5);
        CPPUNIT_ASSERT_EQUAL((hyu32)5, arr.size());
        CPPUNIT_ASSERT_EQUAL(100, arr[0]);
        CPPUNIT_ASSERT_EQUAL(140, arr[4]);
        arr.fill(7);
        CPPUNIT_ASSERT_EQUAL(7, arr[0]);
        CPPUNIT_ASSERT_EQUAL(7, arr[4]);

        CPPUNIT_ASSERT(arr.checkIndex(100));
        CPPUNIT_ASSERT(arr.checkIndex(-5));
        CPPUNIT_ASSERT(! arr.checkIndex(-6));

        arr[2] = 222;
        CPPUNIT_ASSERT_EQUAL(222, *(arr.nthAddr(2)));

        arr.subst(20, 202020, -1);
        CPPUNIT_ASSERT_EQUAL((hyu32)21, arr.size());
        CPPUNIT_ASSERT_EQUAL(-1, arr[5]);
        CPPUNIT_ASSERT_EQUAL(-1, arr[19]);
        CPPUNIT_ASSERT_EQUAL(202020, arr[20]);

        arr.add(&dat[5], 5);
        arr.add(123);
        arr.add(456);
        CPPUNIT_ASSERT_EQUAL((hyu32)28, arr.size());
        CPPUNIT_ASSERT_EQUAL(-15000, arr[21]);
        CPPUNIT_ASSERT_EQUAL(19000, arr[25]);
        CPPUNIT_ASSERT_EQUAL(123, arr[26]);
        CPPUNIT_ASSERT_EQUAL(456, arr[27]);

        int x = 222;
        CPPUNIT_ASSERT_EQUAL(2, arr.issue(x));
        x = 202020;
        CPPUNIT_ASSERT_EQUAL(20, arr.issue(x));
        x = 123;
        CPPUNIT_ASSERT_EQUAL(26, arr.issue(x));
        CPPUNIT_ASSERT_EQUAL((hyu32)28, arr.size());
        x = 98765;
        CPPUNIT_ASSERT_EQUAL(28, arr.issue(x));
        CPPUNIT_ASSERT_EQUAL(98765, arr[28]);

        arr.clear();
        CPPUNIT_ASSERT_EQUAL((hyu32)0, arr.size());

        hyu32 capa = arr.m_capacity;
        arr.reserve(capa);
        CPPUNIT_ASSERT(capa != arr.m_capacity);
    }
开发者ID:FUKUZAWA-Tadashi,项目名称:Hayat,代码行数:62,代码来源:Test_hyArray.cpp


注:本文中的TArray::nthAddr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。