Skip to content

Commit 3b098a5

Browse files
custom type conversion test
1 parent 6f1dde6 commit 3b098a5

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

req/test/req_sketch_test.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,38 @@ TEST_CASE("req sketch: type conversion - several levels", "[req_sketch]") {
519519
REQUIRE(sv_double_it == sv_double.end());
520520
}
521521

522+
class A {
523+
int val;
524+
public:
525+
A(int val): val(val) {}
526+
int get_val() const { return val; }
527+
};
528+
529+
struct less_A {
530+
bool operator()(const A& a1, const A& a2) const { return a1.get_val() < a2.get_val(); }
531+
};
532+
533+
class B {
534+
int val;
535+
public:
536+
explicit B(const A& a): val(a.get_val()) {}
537+
int get_val() const { return val; }
538+
};
539+
540+
struct less_B {
541+
bool operator()(const B& b1, const B& b2) const { return b1.get_val() < b2.get_val(); }
542+
};
543+
544+
TEST_CASE("req sketch: type conversion - custom types") {
545+
req_sketch<A, less_A> sa(4);
546+
sa.update(1);
547+
sa.update(2);
548+
sa.update(3);
549+
550+
req_sketch<B, less_B> sb(sa);
551+
REQUIRE(sb.get_n() == 3);
552+
}
553+
522554
//TEST_CASE("for manual comparison with Java") {
523555
// req_sketch<float> sketch(12, false);
524556
// for (size_t i = 0; i < 100000; ++i) sketch.update(i);

0 commit comments

Comments
 (0)