float _do(int low, int high) { if (high - low == 1) { return _dist_(arr[low], arr[high]); } if (high - low < 1) { return INF; } int mid = (low + high) / 2; float a = _do(low, mid); float b = _do(mid, high); float c = _min(a, b); assert(c>-1e-8); float midx = arr[mid].x; int low_id = get_id_low(low, mid, high, midx - c); int i, j; float min_v = c; for (i = low_id; i < mid; ++i) { for (j = mid; j <= high; ++j) { assert(_dist_(arr[i], arr[j]) > 0.0f); min_v = _min(min_v, _dist_(arr[i], arr[j])); } } return min_v; }
END_TEST START_TEST(test_config_invalid_cbs_max_age) { _do(CBS_MAX); ck_assert_uint_eq(cfg_clients_cb_max_age, 15); }
END_TEST START_TEST(test_config_invalid_sub_min_size_1) { _do(SUB_MIN_SIZE_1); ck_assert_uint_eq(cfg_sub_min_size, 8192); }
int main(int argc, char *argv[]) { _init(argc, argv); _do(); _destroy(); return 0; }
/** * Request a URL using the GET method */ static inline Request GET( const std::string &url, const std::map<std::string,std::string> &headers, unsigned int timeout, void (*handler)(void *,int,const std::string &,bool,const std::string &), void *arg) { return _do("GET",url,headers,timeout,handler,arg); }
END_TEST START_TEST(test_config_invalid_public_address) { // Don't make this depend on the network qev_mock_add("_validate_public_address", "getaddrinfo", EAI_NONAME, NULL, EINVAL); _do(PUBLIC_ADDRESS); ck_assert_ptr_eq(cfg_public_address, NULL); }
int main() { printf("Enter n\n"); int n, i; scanf("%d", &n); printf("type 0 to generate points randomly else type otherwise"); scanf("%d", &i); if(i == 0) { gen_rand(n); } else { printf("Enter all points (x y)\n"); for(i=0;i<n;++i) scanf("%f%f", &arr[i].x, &arr[i].y); } qsort(arr, n, sizeof(point), cmpX); printf("Minimum distance is:\n%f\n", _do(0, n - 1)); return 0; }
/** * Make HTTP DELETE request * * The caller must set all headers, including Host. * * @return HTTP status code or 0 on error (responseBody will contain error message) */ static inline unsigned int DEL( unsigned long maxResponseSize, unsigned long timeout, const struct sockaddr *remoteAddress, const char *path, const std::map<std::string,std::string> &requestHeaders, std::map<std::string,std::string> &responseHeaders, std::string &responseBody) { return _do( "DELETE", maxResponseSize, timeout, remoteAddress, path, requestHeaders, (const void *)0, 0, responseHeaders, responseBody); }
/** * Make HTTP PUT request * * It is the responsibility of the caller to set all headers. With PUT, the * Content-Length and Content-Type headers must be set or the PUT will not * work. * * @return HTTP status code or 0 on error (responseBody will contain error message) */ static inline unsigned int PUT( unsigned long maxResponseSize, unsigned long timeout, const struct sockaddr *remoteAddress, const char *path, const std::map<std::string,std::string> &requestHeaders, const void *postData, unsigned long postDataLength, std::map<std::string,std::string> &responseHeaders, std::string &responseBody) { return _do( "PUT", maxResponseSize, timeout, remoteAddress, path, requestHeaders, postData, postDataLength, responseHeaders, responseBody); }