// Copyright (C) 2019-2020 Zilliz. All rights reserved. // // 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 #include "query/Relational.h" #include "common/Utils.h" #include TEST(Relational, Basic) { using namespace milvus::query; int64_t i64 = 4; int64_t another_i64 = 5; std::string s = "str4"; std::string another_s = "str5"; ASSERT_EQ(Relational{})>()(i64, another_i64), i64 == another_i64); ASSERT_EQ(Relational{})>()(i64, another_i64), i64 != another_i64); ASSERT_EQ(Relational{})>()(i64, another_i64), i64 >= another_i64); ASSERT_EQ(Relational{})>()(i64, another_i64), i64 > another_i64); ASSERT_EQ(Relational{})>()(i64, another_i64), i64 <= another_i64); ASSERT_EQ(Relational{})>()(i64, another_i64), i64 < another_i64); ASSERT_EQ(Relational{})>()(s, another_s), s == another_s); ASSERT_EQ(Relational{})>()(s, another_s), s != another_s); ASSERT_EQ(Relational{})>()(s, another_s), s >= another_s); ASSERT_EQ(Relational{})>()(s, another_s), s > another_s); ASSERT_EQ(Relational{})>()(s, another_s), s <= another_s); ASSERT_EQ(Relational{})>()(s, another_s), s < another_s); ASSERT_EQ(Relational{})>()(s, another_s), milvus::PrefixMatch(s, another_s)); ASSERT_EQ(Relational{})>()(s, another_s), milvus::PostfixMatch(s, another_s)); } TEST(Relational, DifferentFundamentalType) { using namespace milvus::query; int32_t i32 = 3; int64_t i64 = 4; ASSERT_EQ(Relational{})>()(i64, i32), i64 == i32); ASSERT_EQ(Relational{})>()(i64, i32), i64 != i32); ASSERT_EQ(Relational{})>()(i64, i32), i64 >= i32); ASSERT_EQ(Relational{})>()(i64, i32), i64 > i32); ASSERT_EQ(Relational{})>()(i64, i32), i64 <= i32); ASSERT_EQ(Relational{})>()(i64, i32), i64 < i32); } TEST(Relational, DifferentInCompatibleType) { using namespace milvus::query; int64_t i64 = 4; std::string s = "str4"; ASSERT_ANY_THROW(Relational{})>()(s, i64)); ASSERT_ANY_THROW(Relational{})>()(s, i64)); ASSERT_ANY_THROW(Relational{})>()(s, i64)); ASSERT_ANY_THROW(Relational{})>()(s, i64)); ASSERT_ANY_THROW(Relational{})>()(s, i64)); ASSERT_ANY_THROW(Relational{})>()(s, i64)); ASSERT_ANY_THROW(Relational{})>()(s, i64)); ASSERT_ANY_THROW(Relational{})>()(s, i64)); ASSERT_ANY_THROW(Relational{})>()(i64, s)); ASSERT_ANY_THROW(Relational{})>()(i64, s)); ASSERT_ANY_THROW(Relational{})>()(i64, s)); ASSERT_ANY_THROW(Relational{})>()(i64, s)); ASSERT_ANY_THROW(Relational{})>()(i64, s)); ASSERT_ANY_THROW(Relational{})>()(i64, s)); ASSERT_ANY_THROW(Relational{})>()(i64, s)); ASSERT_ANY_THROW(Relational{})>()(i64, s)); }