/* tests for single bucket operations */ static void test_leak_bucket(void) { /* set initial value */ bkt.avg = 150; bkt.max = 15; bkt.level = 1.5; /* leak an op work of time */ throttle_leak_bucket(&bkt, NANOSECONDS_PER_SECOND / 150); g_assert(bkt.avg == 150); g_assert(bkt.max == 15); g_assert(double_cmp(bkt.level, 0.5)); /* leak again emptying the bucket */ throttle_leak_bucket(&bkt, NANOSECONDS_PER_SECOND / 150); g_assert(bkt.avg == 150); g_assert(bkt.max == 15); g_assert(double_cmp(bkt.level, 0)); /* check that the bucket level won't go lower */ throttle_leak_bucket(&bkt, NANOSECONDS_PER_SECOND / 150); g_assert(bkt.avg == 150); g_assert(bkt.max == 15); g_assert(double_cmp(bkt.level, 0)); }
static bool do_test_accounting(bool is_ops, /* are we testing bps or ops */ int size, /* size of the operation to do */ double avg, /* io limit */ uint64_t op_size, /* ideal size of an io */ double total_result, double read_result, double write_result) { BucketType to_test[2][3] = { { THROTTLE_BPS_TOTAL, THROTTLE_BPS_READ, THROTTLE_BPS_WRITE, }, { THROTTLE_OPS_TOTAL, THROTTLE_OPS_READ, THROTTLE_OPS_WRITE, } }; ThrottleConfig cfg; BucketType index; int i; for (i = 0; i < 3; i++) { BucketType index = to_test[is_ops][i]; cfg.buckets[index].avg = avg; } cfg.op_size = op_size; throttle_init(&ts); throttle_timers_init(&tt, ctx, QEMU_CLOCK_VIRTUAL, read_timer_cb, write_timer_cb, &ts); throttle_config(&ts, &tt, &cfg); /* account a read */ throttle_account(&ts, false, size); /* account a write */ throttle_account(&ts, true, size); /* check total result */ index = to_test[is_ops][0]; if (!double_cmp(ts.cfg.buckets[index].level, total_result)) { return false; } /* check read result */ index = to_test[is_ops][1]; if (!double_cmp(ts.cfg.buckets[index].level, read_result)) { return false; } /* check write result */ index = to_test[is_ops][2]; if (!double_cmp(ts.cfg.buckets[index].level, write_result)) { return false; } throttle_timers_destroy(&tt); return true; }
/** * Uses double_cmp to compare an array element-by-element using a specified tolerance. * Returns a number less than, equal to, or greater than zero. */ int double_cmp_array(double *a, double *b, double tol, size_t nelem) { for(size_t i = 0; i < nelem; i++) { int res = double_cmp(a[i], b[i], tol); if(res != 0) return res; } return 0; }
bool point_in_convex(Polygon &a, Point peg) //point should be counter-clockwise { for (int i = 0; i < a.point_num; i++) { Point p1 = a.point[(i + 1) % a.point_num] - a.point[i]; Point p2 = peg - a.point[(i + 1) % a.point_num]; if (double_cmp(cross_product(p1, p2)) <= 0) return false; } return true; }
int test_131() { size_t m = 1; size_t n = 3; size_t p = 1; double a[3] = {1, 2, 3}; double b[3] = {1, 2, 3}; double c[1]; matrix_multiply(a, b, c, m, n, p); ASSERT(!double_cmp(c[0], 14.0, TOLERANCE)); return 1; }
void Compare::set_val() { if(m_v1.is_bool() && m_v2.is_bool()) VarBase::operator=(bool_cmp(bool(m_v1), bool(m_v2))); else if(m_v1.is_int() && m_v2.is_int()) VarBase::operator=(int_cmp(int(m_v1), int(m_v2))); else if(m_v1.is_double() && m_v2.is_double()) VarBase::operator=(double_cmp(double(m_v1), double(m_v2))); else if(m_v1.is_string() && m_v2.is_string()) { std::string s1 = std::string(m_v1), s2 = std::string(m_v2); VarBase::operator=(string_cmp(s1, s2)); } else VarBase::operator=(VarBase()); // Set it invalid }
bool point_online_exclusive(Point p, Line l) { return zero(cross_product(p, l.a, l.b)) && double_cmp(dot_product(p, l.a, l.b)) < 0; }
bool same_side(Point p1, Point p2, Line l) { return double_cmp(cross_product(l.a, p1, l.b) * cross_product(l.a, p2, l.b)) > 0; }
bool graham_ok(Point &a, Point &b, Point &c) { return double_cmp(cross_product(a, b, c)) >= 0; }