コード例 #1
0
TEST_F(TypeRegistryTest, VerifyExteriorModuleRegistration) {
  // Verify that there are a bunch of registered types in the test application by looking
  // at the length of the linked list.  We expect that there will be at least 2, because of
  // our declarations in the earlier test in this module, but we also expect there to be
  // (to choose arbitrarily) around 8, because this is a number of autofired fields known
  // to exist at one point.
  //
  // If the number of autowired members in this unit test drops below 10 at some point, it
  // might be necessary to reduce the count from 8 to something lower.
  size_t nTypes = 0;

  for(auto p = g_pFirstTypeEntry; p; p = p->pFlink)
    nTypes++;

  ASSERT_LT(8UL, nTypes) << "Registration failed to pick up the expected minimum number of types in this test";
  ASSERT_EQ(g_typeEntryCount, nTypes) << "Linked list did not contain the same number of entries as reported in g_entryCount";
}
コード例 #2
0
ファイル: EnumerateTest.cpp プロジェクト: JacobMao/folly
TEST(Enumerate, Cpp17Support) {
  std::array<char, 5> test = {"test"};
  // Can't use range based for loop until C++17, so test manually
  // Equivalent to:
  // for (const auto&& it : folly::enumerate(CStringRange{test.data()})) { ... }
  {
    auto&& enumerate = folly::enumerate(CStringRange{test.data()});
    auto begin = enumerate.begin();
    auto end = enumerate.end();
    for (; begin != end; ++begin) {
      const auto&& it = *begin;

      ASSERT_LT(it.index, test.size());
      EXPECT_EQ(*it, test[it.index]);
    }
  }
}
コード例 #3
0
ファイル: util.cpp プロジェクト: lmurray/rendasaurus
// Does the PRNG generate random floats with approximately even distribution?
TEST(UtilTest, CanGenerateRandomFloats)
{
    const int num_tests = 100000;

    double avg = 0.0f;
    for(size_t i = 0; i < num_tests; i++) {
        float res = rend_randf();
        ASSERT_LT(0.0f, res);
        ASSERT_GE(1.0f, res);
        avg += res;
    }
    avg /= (float)num_tests;
    double mid = 0.5f;
    double err = mid / 100.0f; // Test for +/-1% accuracy
    ASSERT_LE(mid - err, avg);
    ASSERT_GE(mid + err, avg);
}
コード例 #4
0
ファイル: ChangeTest.cpp プロジェクト: mgalushka/cpp-start
TEST(MoneyTest, comparisons) {
  ASSERT_LT(change::Money(10, 99), change::Money(11, 10));
  ASSERT_LE(change::Money(10, 99), change::Money(11, 10));
  ASSERT_EQ(change::Money(10, 99), change::Money(10, 99));
  ASSERT_LE(change::Money(10, 99), change::Money(10, 99));
  ASSERT_GE(change::Money(10, 99), change::Money(10, 99));
  ASSERT_GT(change::Money(11, 00), change::Money(10, 99));
  ASSERT_GE(change::Money(11, 00), change::Money(10, 99));

  EXPECT_TRUE(change::Money(10, 99) < change::Money(11, 10));
  EXPECT_TRUE(change::Money(10, 99) <= change::Money(11, 10));
  EXPECT_TRUE(change::Money(10, 99) == change::Money(10, 99));
  EXPECT_TRUE(change::Money(10, 99) <= change::Money(10, 99));
  EXPECT_TRUE(change::Money(10, 99) >= change::Money(10, 99));
  EXPECT_TRUE(change::Money(11, 00) > change::Money(10, 99));
  EXPECT_TRUE(change::Money(11, 00) >= change::Money(10, 99)); 
}
コード例 #5
0
// Some basic formula tests with confidence = 0.0
TEST_VM(G1Predictions, basic_predictions) {
  G1Predictions predictor(0.0);
  TruncatedSeq s;

  double p0 = predictor.get_new_prediction(&s);
  ASSERT_LT(p0, epsilon) << "Initial prediction of empty sequence must be 0.0";

  s.add(5.0);
  double p1 = predictor.get_new_prediction(&s);
  ASSERT_NEAR(p1, 5.0, epsilon);

  for (int i = 0; i < 40; i++) {
    s.add(5.0);
  }
  double p2 = predictor.get_new_prediction(&s);
  ASSERT_NEAR(p2, 5.0, epsilon);
}
コード例 #6
0
void
Setup::stop_ganesha()
{
    // The child_pid_ is not necessarily ganesha's - it could be gdbserver's.
    // So in order to shut things down more or less orderly we send a signal to ganesha
    // and wait for gdbserver to exit.
    const boost::optional<pid_t> maybe_pid(ganesha_pid());

    if (maybe_pid)
    {
        // 2 possibilities:
        // - gdbserver + ganesha still alive
        // - ganesha still alive
        ASSERT_LT(0, child_pid_);
        LOG_TRACE("Shutting down ganesha @ pid " << *maybe_pid);
        // For now we need to use SIGKILL as the orderly shutdown with SIGTERM
        // gets stuck in the shutdown path (cf. OVS-555).
        int ret = ::kill(*maybe_pid, SIGTERM);
        ASSERT_EQ(0, ret) << "failed to kill ganesha @ " << *maybe_pid << ": " <<
            strerror(errno);

        ASSERT_EQ(child_pid_, ::waitpid(child_pid_, &ret, 0));
        child_pid_ = -1;
    }
    else if (child_pid_ > 0)
    {
        // 2 possibilities:
        // - gdbserver + ganesha not alive anymore
        // - ganesha not alive anymore (-> zombie)
        LOG_WARN("We do seem to have a leftover child @ pid " <<
                 child_pid_ << " - killing it");

        int ret = ::kill(child_pid_, SIGKILL);
        ASSERT_EQ(0, ret) << "failed to kill ganesha @ pid " <<
            *maybe_pid << ": " << strerror(errno);

        ASSERT_EQ(child_pid_, ::waitpid(child_pid_, &ret, 0));
        child_pid_ = -1;
    }
    else
    {
        // forking off gdbserver / ganesha failed / never happened
        LOG_WARN("ganesha not running!?");
    }
}
コード例 #7
0
ファイル: bbw.cpp プロジェクト: qnzhou/libigl-unit-tests
TEST(bbw, decimated_knight)
{
  Eigen::MatrixXd V,C;
  Eigen::MatrixXi T,F,E;
  igl::readMESH(test_common::data_path("decimated-knight.mesh"),V,T,F);
  igl::readTGF(test_common::data_path("decimated-knight.tgf"),C,E);
  Eigen::MatrixXd W_groundtruth, Was, Wmo;
  igl::readDMAT(
    test_common::data_path("decimated-knight-matlab-active-set.dmat"),W_groundtruth);
  Eigen::VectorXi b;
  Eigen::MatrixXd bc;
  igl::boundary_conditions(V,T,C,Eigen::VectorXi(),E,Eigen::MatrixXi(),b,bc);
  igl::BBWData params;
  params.active_set_params.max_iter = 100;
  igl::bbw(V,T,b,bc,params,Was);
  igl::writeDMAT("decimated-knight-as.dmat",Was);
  ASSERT_LT( (Was-W_groundtruth).array().abs().maxCoeff() ,1e-4);
}
コード例 #8
0
// Test temperature companding for non-volatile storage.
//
// 20161016 moved from OpenTRV-Arduino-V0p2 Unit_Tests.cpp testTempCompand().
TEST(Stats,TempCompand)
{
  // Ensure that all (whole) temperatures from 0C to 100C are correctly compressed and expanded.
  for(int16_t i = 0; i <= 100; ++i)
    {
    //DEBUG_SERIAL_PRINT(i<<4); DEBUG_SERIAL_PRINT(" => "); DEBUG_SERIAL_PRINT(compressTempC16(i<<4)); DEBUG_SERIAL_PRINT(" => "); DEBUG_SERIAL_PRINT(expandTempC16(compressTempC16(i<<4))); DEBUG_SERIAL_PRINTLN();
    ASSERT_EQ(i<<4, OTV0P2BASE::expandTempC16(OTV0P2BASE::compressTempC16(int16_t(i<<4))));
    }
  // Ensure that out-of-range inputs are coerced to the limits.
  ASSERT_EQ(0, OTV0P2BASE::expandTempC16(OTV0P2BASE::compressTempC16(-1)));
  ASSERT_EQ((100<<4), OTV0P2BASE::expandTempC16(OTV0P2BASE::compressTempC16(101<<4)));
  ASSERT_EQ(OTV0P2BASE::COMPRESSION_C16_CEIL_VAL_AFTER, OTV0P2BASE::compressTempC16(102<<4)); // Verify ceiling.
  ASSERT_LT(OTV0P2BASE::COMPRESSION_C16_CEIL_VAL_AFTER, 0xff);
  // Ensure that 'unset' compressed value expands to 'unset' uncompressed value.
  const int16_t ui = OTV0P2BASE::NVByHourByteStatsBase::UNSET_INT;
  const uint8_t ub = OTV0P2BASE::NVByHourByteStatsBase::UNSET_BYTE;
  ASSERT_EQ(ui, OTV0P2BASE::expandTempC16(ub));
}
コード例 #9
0
ファイル: test_uuid.cpp プロジェクト: zigzed/common
TEST(uuid, generator)
{
    cxx::sys::uuid u1 = cxx::sys::nil_uuid()();
    printf("u1=%s\n", cxx::sys::to_string(u1).c_str());
    ASSERT_EQ(u1.is_null(), true);

    cxx::sys::uuid u2 = cxx::sys::sys_uuid()();
    printf("u2=%s\n", cxx::sys::to_string(u2).c_str());
    ASSERT_EQ(u2.is_null(), false);


    ASSERT_NE(u1, u2);
    ASSERT_LT(u1, u2);

    std::size_t h1 = u1.hash();
    std::size_t h2 = u2.hash();
    ASSERT_NE(h1, h2);
}
コード例 #10
0
ファイル: PhyloTreeTest.cpp プロジェクト: ehamberg/phyloea
TEST_F(PhyloTreeTest, PrefixCoding) {
    vector<PhyloTreeNode*> nodes1 = Fasta::readFastaFile("tests/aligned.fasta");
    PhyloTree t;
    t.setEvolutionModel(new Kimura(10.0));
    t.buildRandomTree(nodes1);

    double lh1 = t.logLikelihood();
    ASSERT_LT(lh1, 0.0);

    string prefixCoded = PhyloTreeNode::prefixRepresentation(t.getRoot());

    vector<PhyloTreeNode*> nodes2 = Fasta::readFastaFile("tests/aligned.fasta");
    PhyloTree t2 = PhyloTree::decodePrefixNotation(nodes2, prefixCoded, new Kimura(10.0));

    double lh2 = t.logLikelihood();

    ASSERT_DOUBLE_EQ(lh1, lh2);
}
コード例 #11
0
TEST(liblog, concurrent_name(__android_log_buf_print, NUM_CONCURRENT)) {
    pthread_t t[NUM_CONCURRENT];
    int i;
    for (i=0; i < NUM_CONCURRENT; i++) {
        ASSERT_EQ(0, pthread_create(&t[i], NULL,
                                    ConcurrentPrintFn,
                                    reinterpret_cast<void *>(i)));
    }
    int ret = 0;
    for (i=0; i < NUM_CONCURRENT; i++) {
        void* result;
        ASSERT_EQ(0, pthread_join(t[i], &result));
        if ((0 == ret) && (0 != reinterpret_cast<int>(result))) {
            ret = reinterpret_cast<int>(result);
        }
    }
    ASSERT_LT(0, ret);
}
コード例 #12
0
TEST(liblog, __android_log_btwrite__android_logger_list_read) {
    struct logger_list *logger_list;

    pid_t pid = getpid();

    ASSERT_EQ(0, NULL == (logger_list = android_logger_list_open(
        LOG_ID_EVENTS, O_RDONLY | O_NDELAY, 1000, pid)));

    log_time ts(CLOCK_MONOTONIC);

    ASSERT_LT(0, __android_log_btwrite(0, EVENT_TYPE_LONG, &ts, sizeof(ts)));
    usleep(1000000);

    int count = 0;

    for (;;) {
        log_msg log_msg;
        if (android_logger_list_read(logger_list, &log_msg) <= 0) {
            break;
        }

        ASSERT_EQ(log_msg.entry.pid, pid);

        if ((log_msg.entry.len != (4 + 1 + 8))
         || (log_msg.id() != LOG_ID_EVENTS)) {
            continue;
        }

        char *eventData = log_msg.msg();

        if (eventData[4] != EVENT_TYPE_LONG) {
            continue;
        }

        log_time tx(eventData + 4 + 1);
        if (ts == tx) {
            ++count;
        }
    }

    ASSERT_EQ(1, count);

    android_logger_list_close(logger_list);
}
コード例 #13
0
    TEST(xphoto_DenoisingBm3dGrayscale, regression_L2_8x8)
    {
        std::string folder = std::string(cvtest::TS::ptr()->get_data_path()) + "cv/xphoto/bm3d_image_denoising/";
        std::string original_path = folder + "lena_noised_gaussian_sigma=10.png";
        std::string expected_path = folder + "lena_noised_denoised_bm3d_grayscale_l2_tw=8_sw=16_h=10_bm=2500.png";

        cv::Mat original = cv::imread(original_path, cv::IMREAD_GRAYSCALE);
        cv::Mat expected = cv::imread(expected_path, cv::IMREAD_GRAYSCALE);

        ASSERT_FALSE(original.empty()) << "Could not load input image " << original_path;
        ASSERT_FALSE(expected.empty()) << "Could not load reference image " << expected_path;

        cv::Mat result;
        cv::xphoto::bm3dDenoising(original, result, 10, 8, 16, 2500, -1, 8, 1, 0.0f, cv::NORM_L2, cv::xphoto::BM3D_STEP1);

        DUMP(result, expected_path + ".res.png");

        ASSERT_LT(cvtest::norm(result, expected, cv::NORM_L2), 200);
    }
コード例 #14
0
ファイル: MPIProfileTest.cpp プロジェクト: bgeltz/geopm
TEST_F(MPIProfileTest, outer_sync)
{
    struct geopm_prof_c *prof;
    uint64_t region_id[4];
    int rank;
    int num_node = 0;

    (void) geopm_comm_num_node(MPI_COMM_WORLD, &num_node);
    ASSERT_LT(1, num_node);

    MPI_Comm_rank(MPI_COMM_WORLD, &rank);

    ASSERT_EQ(0, geopm_prof_create("outer_sync_test", m_shm_key, MPI_COMM_WORLD, &prof));

    for (int i = 0; i < 3; i++) {
        ASSERT_EQ(0, geopm_prof_outer_sync(prof));

        ASSERT_EQ(0, geopm_prof_region(prof, "loop_one", GEOPM_POLICY_HINT_UNKNOWN, &region_id[0]));
        ASSERT_EQ(0, geopm_prof_enter(prof, region_id[0]));
        sleep_exact(1.0);
        ASSERT_EQ(0, geopm_prof_exit(prof, region_id[0]));

        ASSERT_EQ(0, geopm_prof_region(prof, "loop_two", GEOPM_POLICY_HINT_UNKNOWN, &region_id[1]));
        ASSERT_EQ(0, geopm_prof_enter(prof, region_id[1]));
        sleep_exact(2.0);
        ASSERT_EQ(0, geopm_prof_exit(prof, region_id[1]));

        ASSERT_EQ(0, geopm_prof_region(prof, "loop_three", GEOPM_POLICY_HINT_UNKNOWN, &region_id[2]));
        ASSERT_EQ(0, geopm_prof_enter(prof, region_id[2]));
        sleep_exact(3.0);
        ASSERT_EQ(0, geopm_prof_exit(prof, region_id[2]));

        MPI_Barrier(MPI_COMM_WORLD);
    }

    ASSERT_EQ(0, geopm_prof_print(prof, m_log_file.c_str(), 0));

    if (m_is_node_root) {
        ASSERT_EQ(0, parse_log_loop());
    }

    ASSERT_EQ(0, geopm_prof_destroy(prof));
}
コード例 #15
0
void block_writer::open_segment(size_t segmentid, std::string filename) {
  ASSERT_LT(segmentid, m_index_info.nsegments);
  ASSERT_TRUE(m_output_files[segmentid] == nullptr);
  m_output_files[segmentid].reset(new general_ofstream(filename, 
                                                    /* must not compress! 
                                                     * We need the blocks!*/
                                                     false));
  m_index_info.segment_files[segmentid] = filename;
  // update the per column segment file
  for (size_t col = 0;col < m_index_info.columns.size(); ++col) {
    m_index_info.columns[col].segment_files[segmentid] = 
        m_index_info.segment_files[segmentid] + ":" + std::to_string(col);
  }

  if (m_output_files[segmentid]->fail()) {
    log_and_throw("Unable to open segment data file " + filename);
  }

}
コード例 #16
0
ファイル: time_test.cpp プロジェクト: nfxosp/platform_bionic
TEST(time, clock_gettime) {
  // Try to ensure that our vdso clock_gettime is working.
  timespec ts1;
  ASSERT_EQ(0, clock_gettime(CLOCK_MONOTONIC, &ts1));
  timespec ts2;
  ASSERT_EQ(0, syscall(__NR_clock_gettime, CLOCK_MONOTONIC, &ts2));

  // What's the difference between the two?
  ts2.tv_sec -= ts1.tv_sec;
  ts2.tv_nsec -= ts1.tv_nsec;
  if (ts2.tv_nsec < 0) {
    --ts2.tv_sec;
    ts2.tv_nsec += NS_PER_S;
  }

  // Should be less than (a very generous, to try to avoid flakiness) 1000000ns.
  ASSERT_EQ(0, ts2.tv_sec);
  ASSERT_LT(ts2.tv_nsec, 1000000);
}
コード例 #17
0
ファイル: testTKfit.C プロジェクト: gdesvignes/tempo2
TEST(testTKpoly, quadratic){
    const int m=3;
    const int n=1024;
    const double A = 1.0;
    const double B = 100.0;
    const double C = 1123.123;
    double x[n];
    double y[n];
    double Y[n];
    double p[m];
    double q[m];
    q[0]=q[1]=q[2]=0;
    long double d = 1.0L/static_cast<long double>(n);
    for (int i = 0; i < n; i++){
        long double ix = static_cast<long double>(i-n/2) * d;
        x[i] = static_cast<double>(ix);
        y[i] = A + ix*B + ix*ix*C;
        Y[i] = A + ix*B + ix*ix*C;
    }
    useT2accel=1;
    int itr=1;
    while(itr < 10){
        TKfindPoly_d(x,y,n,m,p);

        q[0] += p[0];
        q[1] += p[1];
        q[2] += p[2];
        if (
                (fabs(q[0] - A) < FIT_EPSILON) && 
                (fabs(q[1] - B) < FIT_EPSILON) && 
                (fabs(q[2] - C) < FIT_EPSILON)
           ) break;

        for (int i = 0; i < n; i++){
            long double ix = static_cast<long double>(i-n/2) * d;
            y[i] = Y[i] - (q[0] + ix*q[1] + ix*ix*q[2]);
        }
        itr++;

    }
    ASSERT_LT(itr,3);
}
コード例 #18
0
TEST(MallocTests, HeapInformation) {
    HANDLE heap = GetProcessHeap();
    ASSERT_NE(heap, (HANDLE)NULL);
    ULONG heap_type;
    SIZE_T got;
    BOOL res = HeapQueryInformation(heap, HeapCompatibilityInformation, &heap_type,
                                    sizeof(heap_type), &got);
    ASSERT_EQ(res, TRUE);
    ASSERT_EQ(got, sizeof(heap_type));
    ASSERT_LT(heap_type, 3); /* 0, 1, 2 are the only valid values */

    heap_type = 2;
    res = HeapSetInformation(heap, HeapCompatibilityInformation, &heap_type,
                             sizeof(heap_type));
    ASSERT_EQ(res, TRUE);
    heap_type = 2;

    res = HeapSetInformation(heap, HeapEnableTerminationOnCorruption, NULL, 0);
    ASSERT_EQ(res, TRUE);
}
コード例 #19
0
ファイル: test_dxt.cpp プロジェクト: AliMiraftab/opencv
TEST(Core_DFT, complex_output2)
{
    for( int i = 0; i < 100; i++ )
    {
        int type = theRNG().uniform(0, 2) ? CV_64F : CV_32F;
        int m = theRNG().uniform(1, 10);
        int n = theRNG().uniform(1, 10);
        Mat x(m, n, type), out;
        randu(x, -1., 1.);
        dft(x, out, DFT_ROWS | DFT_COMPLEX_OUTPUT);
        double nrm = cvtest::norm(out, NORM_INF);
        double thresh = n*m*2;
        if( nrm > thresh )
        {
            cout << "x: " << x << endl;
            cout << "out: " << out << endl;
            ASSERT_LT(nrm, thresh);
        }
    }
}
コード例 #20
0
TEST_VM(LogDecorations, uptime) {
  // Verify the format of the decoration
  int a, b;
  char decimal_point;
  LogDecorations decorations(LogLevel::Info, tagset, default_decorators);
  const char* uptime = decorations.decoration(LogDecorators::uptime_decorator);
  int read = sscanf(uptime, "%d%c%ds", &a, &decimal_point, &b);
  EXPECT_EQ(3, read) << "Invalid uptime decoration: " << uptime;
  EXPECT_TRUE(decimal_point == '.' || decimal_point == ',') << "Invalid uptime decoration: " << uptime;

  // Verify that uptime increases
  double prev = 0;
  for (int i = 0; i < 3; i++) {
    os::naked_short_sleep(10);
    LogDecorations d(LogLevel::Info, tagset, default_decorators);
    double cur = strtod(d.decoration(LogDecorators::uptime_decorator), NULL);
    ASSERT_LT(prev, cur);
    prev = cur;
  }
}
コード例 #21
0
ファイル: PhyloTreeTest.cpp プロジェクト: ehamberg/phyloea
TEST_F(PhyloTreeTest, RandomTree) {
    vector<PhyloTreeNode*> leaves;
    unsigned int n = 30;

    for (unsigned int i = 0; i < n; i++) {
        leaves.push_back(new PhyloTreeNode());
    }

    PhyloTree t;
    t.buildRandomTree(leaves);

    ASSERT_LT(log2(n), t.height()); // |tree| must be ≥ log₂(n)
    ASSERT_GE(n+1, t.height());     // |tree| must be ≤ n+1
    ASSERT_TRUE(t.getRoot()->isRoot()); // there should be a parentless root node

    // all leaves should now have a parent
    for (unsigned int i = 0; i < n; i++) {
        ASSERT_TRUE(!leaves.at(i)->isRoot());
    }
}
TEST(sysdeps_thread, join) {
    std::atomic<int> counter(0);
    std::vector<adb_thread_t> threads(500);
    for (size_t i = 0; i < threads.size(); ++i) {
        ASSERT_TRUE(adb_thread_create(increment_atomic_int, &counter, &threads[i]));
    }

    int current = counter.load();
    ASSERT_GE(current, 0);
    // Make sure that adb_thread_create actually creates threads, and doesn't do something silly
    // like synchronously run the function passed in. The sleep in increment_atomic_int should be
    // enough to keep this from being flakey.
    ASSERT_LT(current, 500);

    for (const auto& thread : threads) {
        ASSERT_TRUE(adb_thread_join(thread));
    }

    ASSERT_EQ(500, counter.load());
}
コード例 #23
0
TEST(TextSearcherICUTest, FindSubstring) {
  TextSearcherICU searcher;
  const String& pattern = makeUTF16("substring");
  searcher.setPattern(pattern, true);

  const String& text = makeUTF16("Long text with substring content.");
  searcher.setText(text.characters16(), text.length());

  MatchResult result;

  EXPECT_TRUE(searcher.nextMatchResult(result));
  EXPECT_NE(0u, result.start);
  EXPECT_NE(0u, result.length);
  ASSERT_LT(result.length, text.length());
  EXPECT_EQ(pattern, text.substring(result.start, result.length));

  EXPECT_FALSE(searcher.nextMatchResult(result));
  EXPECT_EQ(0u, result.start);
  EXPECT_EQ(0u, result.length);
}
    // Insert multiple keys and try to iterate through all of them
    // using a forward cursor while calling savePosition() and
    // restorePosition() in succession.
    TEST( SortedDataInterface, SaveAndRestorePositionWhileIterateCursor ) {
        const std::unique_ptr<HarnessHelper> harnessHelper( newHarnessHelper() );
        const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( false ) );

        {
            const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
            ASSERT( sorted->isEmpty( opCtx.get() ) );
        }

        int nToInsert = 10;
        for ( int i = 0; i < nToInsert; i++ ) {
            const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
            {
                WriteUnitOfWork uow( opCtx.get() );
                BSONObj key = BSON( "" << i );
                RecordId loc( 42, i * 2 );
                ASSERT_OK( sorted->insert( opCtx.get(), key, loc, true ) );
                uow.commit();
            }
        }

        {
            const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
            ASSERT_EQUALS( nToInsert, sorted->numEntries( opCtx.get() ) );
        }

        {
            const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
            const std::unique_ptr<SortedDataInterface::Cursor> cursor( sorted->newCursor(opCtx.get()) );
            int i = 0;
            for (auto entry = cursor->seek(minKey, true); entry; i++, entry = cursor->next()) {
                ASSERT_LT(i, nToInsert);
                ASSERT_EQ(entry, IndexKeyEntry(BSON( "" << i), RecordId(42, i * 2)));

                cursor->savePositioned();
                cursor->restore( opCtx.get() );
            }
            ASSERT( !cursor->next() );
            ASSERT_EQ(i, nToInsert);
        }
    }
コード例 #25
0
TEST_F(WingComponentSegment2, tiglWingComponentGetEtaXsi_success)
{
    double eta = 0.3336;
    double xsi = 0.;
    char * wingUID = NULL;
    char * segmentUID = NULL;
    double segmentEta = 0., segmentXsi = 0.;
    double errorDistance = 0;

    TiglReturnCode ret = tiglWingComponentSegmentPointGetSegmentEtaXsi(tiglHandle, "D250_wing_CS", eta, xsi, &wingUID, &segmentUID, &segmentEta, &segmentXsi, &errorDistance);
    ASSERT_EQ(TIGL_SUCCESS, ret);
    ASSERT_LT(errorDistance, 1e-2);
    ASSERT_STREQ("D250_wing", wingUID);

    eta = 0.;
    xsi = 0.5;

    ret = tiglWingComponentSegmentPointGetSegmentEtaXsi(tiglHandle, "D250_wing_CS", eta, xsi, &wingUID, &segmentUID, &segmentEta, &segmentXsi, &errorDistance);
    ASSERT_EQ(TIGL_SUCCESS, ret);
    ASSERT_STREQ("D250_wing", wingUID);
}
コード例 #26
0
    TEST(xphoto_DenoisingBm3dGrayscale, regression_L2)
    {
        std::string folder = std::string(cvtest::TS::ptr()->get_data_path()) + "cv/xphoto/bm3d_image_denoising/";
        std::string original_path = folder + "lena_noised_gaussian_sigma=10.png";
        std::string expected_path = folder + "lena_noised_denoised_bm3d_wiener_grayscale_l2_tw=4_sw=16_h=10_bm=400.png";

        cv::Mat original = cv::imread(original_path, cv::IMREAD_GRAYSCALE);
        cv::Mat expected = cv::imread(expected_path, cv::IMREAD_GRAYSCALE);

        ASSERT_FALSE(original.empty()) << "Could not load input image " << original_path;
        ASSERT_FALSE(expected.empty()) << "Could not load reference image " << expected_path;

        // BM3D: two different calls doing exactly the same thing
        cv::Mat result, resultSec;
        cv::xphoto::bm3dDenoising(original, cv::Mat(), resultSec, 10, 4, 16, 2500, 400, 8, 1, 0.0f, cv::NORM_L2, cv::xphoto::BM3D_STEPALL);
        cv::xphoto::bm3dDenoising(original, result, 10, 4, 16, 2500, 400, 8, 1, 0.0f, cv::NORM_L2, cv::xphoto::BM3D_STEPALL);

        DUMP(result, expected_path + ".res.png");

        ASSERT_EQ(cvtest::norm(result, resultSec, cv::NORM_L2), 0);
        ASSERT_LT(cvtest::norm(result, expected, cv::NORM_L2), 200);
    }
コード例 #27
0
// The following tests checks that the initial predictions are based on
// the average of the sequence and not on the stddev (which is 0).
TEST_VM(G1Predictions, average_not_stdev_predictions) {
  G1Predictions predictor(0.5);
  TruncatedSeq s;

  s.add(1.0);
  double p1 = predictor.get_new_prediction(&s);
  ASSERT_GT(p1, s.davg()) << "First prediction must be greater than average";

  s.add(1.0);
  double p2 = predictor.get_new_prediction(&s);
  ASSERT_GT(p1, p2) << "First prediction must be greater than second";

  s.add(1.0);
  double p3 = predictor.get_new_prediction(&s);
  ASSERT_GT(p2, p3) << "Second prediction must be greater than third";

  s.add(1.0);
  s.add(1.0); // Five elements are now in the sequence.
  double p4 = predictor.get_new_prediction(&s);
  ASSERT_LT(p4, p3) << "Fourth prediction must be smaller than third";
  ASSERT_NEAR(p4, 1.0, epsilon);
}
コード例 #28
0
	TEST_F(CTestInterfaceBase, incr_TestCase_15_overflow) {
		data_entry key("13_15_key_01");

		int area = 1;
		int retValue = 0;
		int count = 0x7FFFFFFF;
		int ret;

		client_handle.remove(area, key);

		DO_WITH_RETRY(client_handle.incr(area, key, count, &retValue), ret, TAIR_RETURN_SUCCESS);
		ASSERT_EQ(TAIR_RETURN_SUCCESS, ret);
		ASSERT_EQ(count, retValue);

		count = 1;
		int initValue = 1;
		DO_WITH_RETRY(client_handle.incr(area, key, count, &retValue, initValue, 0), ret, TAIR_RETURN_SUCCESS);
		ASSERT_EQ(TAIR_RETURN_SUCCESS, ret);
		ASSERT_LT(retValue, 0);

		client_handle.remove(area, key);
	};
コード例 #29
0
ファイル: amf.cpp プロジェクト: mishira/libbroadcast
TEST(AMF0Test, DecodeStringLongUtf8)
{
	// Generate long (>65535 bytes) UTF-8 string
	QString str =
		QStringLiteral("\xE3\x81\x82 \xE3\x81\x84 "); // Japanese A and I
	str.append(QString(21845, QChar(0x3046))); // Japanese U
	str.append(QStringLiteral(" \xE3\x81\x88")); // Japanese E
	uint utf8Len = str.toUtf8().length();
	ASSERT_LT(65535U, utf8Len);

	AMFString val(str);
	QByteArray data = val.serialized();
	AMFType *out = NULL;
	uint outSize = AMFType::decode(data.constData(), &out);
	AMFString *outVal = out->asString();

	ASSERT_FALSE(outVal == NULL);
	EXPECT_EQ(5 + utf8Len, outSize);
	EXPECT_EQ(val, *outVal);

	delete out;
}
コード例 #30
0
ファイル: test.cpp プロジェクト: mlove-au/utils
// Not an ideal test, but try to check that the async version runs faster than the sync equivalent.
TEST(AsyncForEach, TestMapSpeed)
{
    typedef std::chrono::high_resolution_clock clock;
    auto testFunction = [](int)
    {
        std::this_thread::sleep_for(std::chrono::milliseconds(100));
    };

    std::vector<int> data(20);

    auto asyncStart = clock::now();
    async_for_each(data.begin(), data.end(), testFunction);
    auto asyncFinish = clock::now();
    auto asyncTime = std::chrono::duration_cast<std::chrono::microseconds>(asyncFinish - asyncStart).count();

    auto syncStart = clock::now();
    std::for_each(data.begin(), data.end(), testFunction);
    auto syncFinish = clock::now();
    auto syncTime = std::chrono::duration_cast<std::chrono::microseconds>(syncFinish - syncStart).count();

    ASSERT_LT(asyncTime, syncTime);
}