blob: 22fd91d5f54f84163462547742f58cd0dd24d887 (
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
|
#include "udf_counter.h"
#include <library/cpp/testing/unittest/registar.h>
using namespace NYql::NUdf;
Y_UNIT_TEST_SUITE(TUdfCounter) {
Y_UNIT_TEST(NullCounter) {
TCounter c;
c.Inc();
c.Dec();
c.Add(1);
c.Sub(2);
c.Set(3);
}
Y_UNIT_TEST(RealCounter) {
i64 value = 10;
TCounter c(&value);
c.Inc();
UNIT_ASSERT_VALUES_EQUAL(value, 11);
c.Dec();
UNIT_ASSERT_VALUES_EQUAL(value, 10);
c.Add(1);
UNIT_ASSERT_VALUES_EQUAL(value, 11);
c.Sub(2);
UNIT_ASSERT_VALUES_EQUAL(value, 9);
c.Set(3);
UNIT_ASSERT_VALUES_EQUAL(value, 3);
}
Y_UNIT_TEST(Copy) {
i64 value = 1;
TCounter c1(&value);
TCounter c2(c1); // copy ctor
c2.Inc();
UNIT_ASSERT_VALUES_EQUAL(value, 2);
TCounter c3;
c3 = c1; // assign
c3.Inc();
UNIT_ASSERT_VALUES_EQUAL(value, 3);
TCounter c4(std::move(c1)); // move ctor
c4.Inc();
UNIT_ASSERT_VALUES_EQUAL(value, 4);
TCounter c5;
c5 = std::move(c3); // move assign
c5.Inc();
UNIT_ASSERT_VALUES_EQUAL(value, 5);
}
}
|