File size: 2,999 Bytes
9997d13
 
9fdbbcb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9997d13
9fdbbcb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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,
        },
    },
]