Skip to content

Commit

Permalink
C++ client: clean up some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kosak committed Jun 27, 2024
1 parent 98b62cb commit 8f3c384
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 53 deletions.
2 changes: 1 addition & 1 deletion cpp-client/deephaven/tests/src/add_drop_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace deephaven::client::tests {

TEST_CASE("Drop all columns", "[adddrop]") {
TEST_CASE("Drop some columns", "[adddrop]") {
auto tm = TableMakerForTests::Create();
auto table = tm.Table();
auto t = table.Update("II = ii").Where("Ticker == `AAPL`");
Expand Down
2 changes: 1 addition & 1 deletion cpp-client/deephaven/tests/src/attributes_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ TEST_CASE("TableHandle Created By DoPut", "[attributes]") {
CHECK(table.IsStatic());
// The columns all have the same size, so look at the source data for any one of them and get its size
auto expected_size = static_cast<int64_t>(tm.ColumnData().ImportDate().size());
CHECK(table.NumRows() == expected_size);
CHECK(expected_size == table.NumRows());
}
} // namespace deephaven::client::tests
11 changes: 0 additions & 11 deletions cpp-client/deephaven/tests/src/join_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ TEST_CASE("Aj", "[join]") {

TEST_CASE("Raj", "[join]") {
auto tm = TableMakerForTests::Create();
auto q = arrow::timestamp(arrow::TimeUnit::NANO, "UTC");

TableHandle trades;
{
std::vector<std::string> ticker_data = {"AAPL", "AAPL", "AAPL", "IBM", "IBM"};
Expand Down Expand Up @@ -206,15 +204,6 @@ TEST_CASE("Raj", "[join]") {
std::vector<std::optional<int32_t>> bid_size_data = {10, {}, {}, 5, 13};
std::vector<std::optional<double>> ask_data = {2.5, {}, {}, 105, 110};
std::vector<std::optional<int32_t>> ask_size_data = {83, {}, {}, 47, 15};
TableMaker table_maker;
table_maker.AddColumn("Ticker", ticker_data);
table_maker.AddColumn("Timestamp", timestamp_data);
table_maker.AddColumn("Price", price_data);
table_maker.AddColumn("Size", size_data);
table_maker.AddColumn("Bid", bid_data);
table_maker.AddColumn("BidSize", bid_size_data);
table_maker.AddColumn("Ask", ask_data);
table_maker.AddColumn("AskSize", ask_size_data);

CompareTable(
result,
Expand Down
6 changes: 0 additions & 6 deletions cpp-client/deephaven/tests/src/sort_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@ TEST_CASE("Sort temp Table", "[sort]") {

auto sorted = temp_table.Sort(SortPair::Descending("IntValue3"), SortPair::Ascending("IntValue2"));

std::vector<std::string> import_date_data = {"2017-11-01", "2017-11-01", "2017-11-01"};
std::vector<std::string> ticker_data = {"AAPL", "AAPL", "AAPL"};
std::vector<double> open_data = {22.1, 26.8, 31.5};
std::vector<double> close_data = {23.5, 24.2, 26.7};
std::vector<int64_t> vol_data = {100000, 250000, 19000};

std::vector<int32_t> sid0{8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7};
std::vector<int32_t> sid1{4, 4, 5, 5, 6, 6, 7, 7, 0, 0, 1, 1, 2, 2, 3, 3};
std::vector<int32_t> sid2{2, 2, 2, 2, 3, 3, 3, 3, 0, 0, 0, 0, 1, 1, 1, 1};
Expand Down
1 change: 0 additions & 1 deletion cpp-client/deephaven/tests/src/update_by_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ TEST_CASE("UpdateBy: Multiple Ops", "[update_by]") {

namespace {
std::vector<TableHandle> MakeTables(const Client &client) {
std::vector<TableHandle> result;
auto tm = client.GetManager();
auto static_table = MakeRandomTable(client).Update("Timestamp=now()");
auto ticking_table = tm.TimeTable(std::chrono::seconds(1))
Expand Down
55 changes: 22 additions & 33 deletions cpp-client/deephaven/tests/src/validation_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ using deephaven::dhcore::utility::separatedList;

namespace deephaven::client::tests {
namespace {
void TestWheres(const TableHandleManager &scope);
void TestSelects(const TableHandleManager &scope);
void TestWheresHelper(std::string_view what, const TableHandle &table,
const std::vector<std::string> &bad_wheres,
const std::vector<std::string> &good_wheres);
Expand All @@ -26,19 +24,26 @@ void TestSelectsHelper(std::string_view what, const TableHandle &table,
} // namespace

TEST_CASE("Validate selects", "[validation]") {
auto tm = TableMakerForTests::Create();
auto table = tm.Table();
TestSelects(tm.Client().GetManager());
}
std::vector<std::vector<std::string>> bad_selects = {
{ "X = 3)" },
{ "S = `hello`", "T = java.util.regex.Pattern.quote(S)" }, // Pattern.quote not on whitelist
{ "X = Math.min(3, 4)" } // Math.min not on whitelist
};
std::vector<std::vector<std::string>> good_selects = {
{"X = 3"},
{"S = `hello`", "T = S.length()"}, // instance methods of String ok
{"X = min(3, 4)"}, // "builtin" from GroovyStaticImports
{"X = isFinite(3)"}, // another builtin from GroovyStaticImports
};

TEST_CASE("Validate wheres", "[validation]") {
auto tm = TableMakerForTests::Create();
auto table = tm.Table();
TestWheres(tm.Client().GetManager());
auto thm = tm.Client().GetManager();
auto static_table = thm.EmptyTable(10)
.Update("X = 12", "S = `hello`");
TestSelectsHelper("static Table", static_table, bad_selects, good_selects);
}

namespace {
void TestWheres(const TableHandleManager &scope) {
TEST_CASE("Validate wheres", "[validation]") {
std::vector<std::string> bad_wheres = {
"X > 3)", // syntax error
"S = new String(`hello`)", // new not allowed
Expand All @@ -55,11 +60,14 @@ void TestWheres(const TableHandleManager &scope) {
"X in 3, 4, 5",
};

auto static_table = scope.EmptyTable(10)
auto tm = TableMakerForTests::Create();
auto thm = tm.Client().GetManager();
auto static_table = thm.EmptyTable(10)
.Update("X = 12", "S = `hello`");
TestWheresHelper("static Table", static_table, bad_wheres, good_wheres);
}

namespace {
void TestWheresHelper(std::string_view what, const TableHandle &table,
const std::vector<std::string> &bad_wheres,
const std::vector<std::string> &good_wheres) {
Expand All @@ -81,37 +89,18 @@ void TestWheresHelper(std::string_view what, const TableHandle &table,
}
}

void TestSelects(const TableHandleManager &scope) {
std::vector<std::vector<std::string>> bad_selects = {
{ "X = 3)" },
{ "S = `hello`", "T = java.util.regex.Pattern.quote(S)" }, // Pattern.quote not on whitelist
{ "X = Math.min(3, 4)" } // Math.min not on whitelist
};
std::vector<std::vector<std::string>> good_selects = {
{"X = 3"},
{"S = `hello`", "T = S.length()"}, // instance methods of String ok
{"X = min(3, 4)"}, // "builtin" from GroovyStaticImports
{"X = isFinite(3)"}, // another builtin from GroovyStaticImports
};
auto static_table = scope.EmptyTable(10)
.Update("X = 12", "S = `hello`");
TestSelectsHelper("static Table", static_table, bad_selects, good_selects);
}

void TestSelectsHelper(std::string_view what, const TableHandle &table,
const std::vector<std::vector<std::string>> &bad_selects,
const std::vector<std::vector<std::string>> &good_selects) {
for (const auto &bs : bad_selects) {
SimpleOstringstream selection;
selection << separatedList(bs.begin(), bs.end());
try {
(void)table.Select(bs);
} catch (const std::exception &e) {
fmt::print(std::cerr, "{}: {}: Failed as expected with: {}\n", what, selection.str(), e.what());
fmt::print(std::cerr, "{}: {}: Failed as expected with: {}\n", what, bs, e.what());
continue;
}
throw std::runtime_error(fmt::format("{}: {}: Expected to fail, but succeeded",
what, selection.str()));
what, bs));
}

for (const auto &gs : good_selects) {
Expand Down

0 comments on commit 8f3c384

Please sign in to comment.