aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/threading/queue/tune_ut.cpp
blob: 34086ccf0fe520d603c0dcbf1d0d08fd104b8791 (plain) (blame)
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include <library/cpp/testing/unittest/registar.h>
#include "tune.h"

struct TDefaultStructA {
};

struct TDefaultStructB {
};

struct TDefaults {
    using TStructA = TDefaultStructA;
    using TStructB = TDefaultStructB;
    static constexpr ui32 Param1 = 42;
    static constexpr ui32 Param2 = 42;
};

DeclareTuneTypeParam(TweakStructA, TStructA);
DeclareTuneTypeParam(TweakStructB, TStructB);
DeclareTuneValueParam(TweakParam1, ui32, Param1);
DeclareTuneValueParam(TweakParam2, ui32, Param2);

Y_UNIT_TEST_SUITE(TestTuning) { 
    Y_UNIT_TEST(Defaults) { 
        using TTuned = TTune<TDefaults>;
        using TunedA = TTuned::TStructA;
        using TunedB = TTuned::TStructB;
        auto sameA = std::is_same<TDefaultStructA, TunedA>::value;
        auto sameB = std::is_same<TDefaultStructB, TunedB>::value;
        auto param1 = TTuned::Param1;
        auto param2 = TTuned::Param2;

        UNIT_ASSERT(sameA);
        UNIT_ASSERT(sameB);
        UNIT_ASSERT_EQUAL(param1, 42);
        UNIT_ASSERT_EQUAL(param2, 42);
    }

    Y_UNIT_TEST(TuneStructA) { 
        struct TMyStruct {
        };

        using TTuned = TTune<TDefaults, TweakStructA<TMyStruct>>;

        using TunedA = TTuned::TStructA;
        using TunedB = TTuned::TStructB;
        //auto sameA = std::is_same<TDefaultStructA, TunedA>::value;
        auto sameB = std::is_same<TDefaultStructB, TunedB>::value;
        auto param1 = TTuned::Param1;
        auto param2 = TTuned::Param2;

        auto sameA = std::is_same<TMyStruct, TunedA>::value;

        UNIT_ASSERT(sameA);
        UNIT_ASSERT(sameB);
        UNIT_ASSERT_EQUAL(param1, 42);
        UNIT_ASSERT_EQUAL(param2, 42);
    }

    Y_UNIT_TEST(TuneParam1) { 
        using TTuned = TTune<TDefaults, TweakParam1<24>>;

        using TunedA = TTuned::TStructA;
        using TunedB = TTuned::TStructB;
        auto sameA = std::is_same<TDefaultStructA, TunedA>::value;
        auto sameB = std::is_same<TDefaultStructB, TunedB>::value;
        auto param1 = TTuned::Param1;
        auto param2 = TTuned::Param2;

        UNIT_ASSERT(sameA);
        UNIT_ASSERT(sameB);
        UNIT_ASSERT_EQUAL(param1, 24);
        UNIT_ASSERT_EQUAL(param2, 42);
    }

    Y_UNIT_TEST(TuneStructAAndParam1) { 
        struct TMyStruct {
        };

        using TTuned =
            TTune<TDefaults, TweakStructA<TMyStruct>, TweakParam1<24>>;

        using TunedA = TTuned::TStructA;
        using TunedB = TTuned::TStructB;
        //auto sameA = std::is_same<TDefaultStructA, TunedA>::value;
        auto sameB = std::is_same<TDefaultStructB, TunedB>::value;
        auto param1 = TTuned::Param1;
        auto param2 = TTuned::Param2;

        auto sameA = std::is_same<TMyStruct, TunedA>::value;

        UNIT_ASSERT(sameA);
        UNIT_ASSERT(sameB);
        UNIT_ASSERT_EQUAL(param1, 24);
        UNIT_ASSERT_EQUAL(param2, 42);
    }

    Y_UNIT_TEST(TuneParam1AndStructA) { 
        struct TMyStruct {
        };

        using TTuned =
            TTune<TDefaults, TweakParam1<24>, TweakStructA<TMyStruct>>;

        using TunedA = TTuned::TStructA;
        using TunedB = TTuned::TStructB;
        //auto sameA = std::is_same<TDefaultStructA, TunedA>::value;
        auto sameB = std::is_same<TDefaultStructB, TunedB>::value;
        auto param1 = TTuned::Param1;
        auto param2 = TTuned::Param2;

        auto sameA = std::is_same<TMyStruct, TunedA>::value;

        UNIT_ASSERT(sameA);
        UNIT_ASSERT(sameB);
        UNIT_ASSERT_EQUAL(param1, 24);
        UNIT_ASSERT_EQUAL(param2, 42);
    }
}