-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathSliceColTest.cpp
140 lines (116 loc) · 5.28 KB
/
SliceColTest.cpp
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
* Copyright 2021 The DAPHNE Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <runtime/local/datagen/GenGivenVals.h>
#include <runtime/local/datastructures/DataObjectFactory.h>
#include <runtime/local/datastructures/DenseMatrix.h>
#include <runtime/local/datastructures/Frame.h>
#include <runtime/local/kernels/CheckEq.h>
#include <runtime/local/kernels/SliceCol.h>
#include <tags.h>
#include <catch.hpp>
#include <vector>
#include <cstdint>
TEMPLATE_PRODUCT_TEST_CASE("SliceCol", TAG_KERNELS, (DenseMatrix, Matrix), (double, int64_t, uint32_t)) {
using DT = TestType;
std::vector<typename DT::VT> vals = {
0, 0, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 3, 4, 5, 0, 6, 7, 0, 8, 0, 0, 9, 0,
};
std::vector<typename DT::VT> valsExp = {
0, 1, 0, 0, 4, 5, 8, 0,
};
auto arg = genGivenVals<DT>(4, vals);
auto exp = genGivenVals<DT>(4, valsExp);
DT *res = nullptr;
sliceCol(res, arg, 1, 3, nullptr);
CHECK(*res == *exp);
DataObjectFactory::destroy(arg, exp, res);
}
TEMPLATE_PRODUCT_TEST_CASE("SliceCol - string specific", TAG_KERNELS, (DenseMatrix, Matrix), (ALL_STRING_VALUE_TYPES)) {
using DT = TestType;
using VT = typename DT::VT;
std::vector<VT> vals = {VT("a"), VT(""), VT("1"), VT("abc"), VT("e"), VT("j"), VT("abc"), VT("abcd"),
VT("ab"), VT("a"), VT("f"), VT("k"), VT("ABC"), VT("34ab"), VT("ac"), VT("b"),
VT("g"), VT("l"), VT("cd"), VT(" "), VT("ad"), VT("c"), VT("h"), VT(" ")};
std::vector<VT> valsExp = {VT(""), VT("1"), VT("abcd"), VT("ab"), VT("34ab"), VT("ac"), VT(" "), VT("ad")};
auto arg = genGivenVals<DT>(4, vals);
auto exp = genGivenVals<DT>(4, valsExp);
DT *res = nullptr;
sliceCol(res, arg, 1, 3, nullptr);
CHECK(*res == *exp);
DataObjectFactory::destroy(arg, exp, res);
}
TEMPLATE_PRODUCT_TEST_CASE("SliceCol - check throws", TAG_KERNELS, (DenseMatrix, Matrix), (double, int64_t)) {
using DT = TestType;
using VT = typename DT::VT;
auto arg = genGivenVals<DT>(4, {
0, 0, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 3, 4, 5, 0, 6, 7, 0, 8, 0, 0, 9, 0,
});
DT *res = nullptr;
SECTION("lowerIncl out of bounds - negative") {
REQUIRE_THROWS_AS((sliceCol(res, arg, -1, 3, nullptr)), std::out_of_range);
}
SECTION("lowerIncl greater than upperExcl") {
REQUIRE_THROWS_AS((sliceCol(res, arg, 3, 2, nullptr)), std::out_of_range);
}
SECTION("upperExcl out of bounds - too high") {
REQUIRE_THROWS_AS((sliceCol(res, arg, VT(1), VT(7.1), nullptr)), std::out_of_range);
}
DataObjectFactory::destroy(arg);
}
TEMPLATE_TEST_CASE("SliceCol", TAG_KERNELS, (Frame)) {
using VT = double;
auto c0 = genGivenVals<DenseMatrix<VT>>(4, {0.0, 1.1, 2.2, 3.3});
auto c1 = genGivenVals<DenseMatrix<VT>>(4, {4.4, 5.5, 6.6, 7.7});
auto c2 = genGivenVals<DenseMatrix<VT>>(4, {8.8, 9.9, 1.0, 2.0});
auto c3 = genGivenVals<DenseMatrix<VT>>(4, {3.0, 4.0, 5.0, 6.0});
std::vector<Structure *> cols1 = {c0, c1, c2, c3};
std::vector<Structure *> cols2 = {c1, c2};
std::string *labels1 = new std::string[4]{"ab", "cde", "fghi", "jkilm"};
std::string *labels2 = new std::string[4]{"cde", "fghi"};
auto arg = DataObjectFactory::create<Frame>(cols1, labels1);
auto exp = DataObjectFactory::create<Frame>(cols2, labels2);
Frame *res = nullptr;
sliceCol(res, arg, 1, 3, nullptr);
CHECK(*res == *exp);
delete[] labels1;
delete[] labels2;
DataObjectFactory::destroy(arg, exp, res);
}
TEMPLATE_TEST_CASE("SliceCol - check throws", TAG_KERNELS, (Frame)) {
using VT = double;
auto c0 = genGivenVals<DenseMatrix<VT>>(4, {0.0, 1.1, 2.2, 3.3});
auto c1 = genGivenVals<DenseMatrix<VT>>(4, {4.4, 5.5, 6.6, 7.7});
auto c2 = genGivenVals<DenseMatrix<VT>>(4, {8.8, 9.9, 1.0, 2.0});
auto c3 = genGivenVals<DenseMatrix<VT>>(4, {3.0, 4.0, 5.0, 6.0});
std::vector<Structure *> cols1 = {c0, c1, c2, c3};
std::string *labels1 = new std::string[4]{"ab", "cde", "fghi", "jkilm"};
auto arg = DataObjectFactory::create<Frame>(cols1, labels1);
Frame *res = nullptr;
SECTION("lowerIncl out of bounds - negative") {
REQUIRE_THROWS_AS((sliceCol(res, arg, -0.1, 3.0, nullptr)), std::out_of_range);
}
SECTION("lowerIncl greater than upperExcl") {
REQUIRE_THROWS_AS((sliceCol(res, arg, 3, 2, nullptr)), std::out_of_range);
}
SECTION("upperExcl out of bounds - too high") {
REQUIRE_THROWS_AS((sliceCol(res, arg, 1, 5, nullptr)), std::out_of_range);
}
SECTION("upperExcl out of bounds - too high FP") {
REQUIRE_THROWS_AS((sliceCol(res, arg, 1.0, 5.1, nullptr)), std::out_of_range);
}
delete[] labels1;
DataObjectFactory::destroy(arg);
}