|
test_cases = [ |
|
{ |
|
"predictions": [ |
|
[ |
|
{ |
|
"base": r""" |
|
template <typename T> |
|
bool has_close_elements(T numbers, float threshold) { |
|
for (int i = 0; i < numbers.size(); i++) |
|
for (int j = i + 1; j < numbers.size(); j++) |
|
if (std::abs(numbers[i] - numbers[j]) < threshold) |
|
return true; |
|
|
|
return false; |
|
} |
|
""", |
|
"sfinae": r""" |
|
template < |
|
typename T, |
|
std::enable_if_t<std::is_same_v<typename T::value_type, float>, int> = 0> |
|
bool has_close_elements(T numbers, float threshold) { |
|
for (int i = 0; i < numbers.size(); i++) |
|
for (int j = i + 1; j < numbers.size(); j++) |
|
if (std::abs(numbers[i] - numbers[j]) < threshold) |
|
return true; |
|
|
|
return false; |
|
} |
|
""", |
|
"concepts": r""" |
|
template <typename T> |
|
requires std::same_as<typename T::value_type, float> |
|
bool has_close_elements(T numbers, float threshold) { |
|
for (int i = 0; i < numbers.size(); i++) |
|
for (int j = i + 1; j < numbers.size(); j++) |
|
if (std::abs(numbers[i] - numbers[j]) < threshold) |
|
return true; |
|
|
|
return false; |
|
} |
|
""", |
|
} |
|
] |
|
], |
|
"references": [ |
|
{ |
|
"tests": r""" |
|
#define ASSERT(...) \ |
|
do { \ |
|
if (!(__VA_ARGS__)) { \ |
|
std::exit(-1); \ |
|
} \ |
|
} while (false) |
|
|
|
#define TEST_ON_TYPE(_type_) \ |
|
do { \ |
|
_type_ a = {1.0, 2.0, 3.9, 4.0, 5.0, 2.2}; \ |
|
ASSERT(has_close_elements(a, 0.3) == true); \ |
|
ASSERT(has_close_elements(a, 0.05) == false); \ |
|
ASSERT(has_close_elements(_type_{1.0, 2.0, 5.9, 4.0, 5.0}, 0.95) == true); \ |
|
ASSERT(has_close_elements(_type_{1.0, 2.0, 5.9, 4.0, 5.0}, 0.8) == false); \ |
|
ASSERT(has_close_elements(_type_{1.0, 2.0, 3.0, 4.0, 5.0}, 2.0) == true); \ |
|
ASSERT(has_close_elements(_type_{1.1, 2.2, 3.1, 4.1, 5.1}, 1.0) == true); \ |
|
ASSERT(has_close_elements(_type_{1.1, 2.2, 3.1, 4.1, 5.1}, 0.5) == false); \ |
|
} while (false) |
|
|
|
int main() { |
|
TEST_ON_TYPE(std::vector<float>); |
|
TEST_ON_TYPE(std::deque<float>); |
|
} |
|
""", |
|
"invalids": r""" |
|
int main() { |
|
std::string s{}; |
|
has_close_elements(s, 3.4); |
|
} |
|
""", |
|
} |
|
], |
|
"result": { |
|
"base_run_passed@1": 1.0, |
|
"base_run_compiled@1": 1.0, |
|
"sfinae_run_passed@1": 1.0, |
|
"sfinae_run_compiled@1": 1.0, |
|
"concepts_run_passed@1": 1.0, |
|
"concepts_run_compiled@1": 1.0, |
|
}, |
|
}, |
|
] |
|
|