#define CODE_ERROR_LOCATIONS #include #include #include #include #include namespace nb { TEST(UtilsTest, TestFindAndReplace) { ASSERT_STREQ( find_and_replace("Jeff", "e", "efe").c_str(), "Jefeff" ); std::string tmp = find_and_replace("Naif", "a", "afa"); ASSERT_STREQ( find_and_replace(tmp, "i", "ifi").c_str(), "Nafaifif" ); tmp = find_and_replace("aeiou", "a", "afa"); tmp = find_and_replace(tmp, "e", "efe"); tmp = find_and_replace(tmp, "i", "ifi"); tmp = find_and_replace(tmp, "o", "ofo"); tmp = find_and_replace(tmp, "u", "ufu"); ASSERT_STREQ( tmp.c_str(), "afaefeifiofoufu" ); tmp = find_and_replace(tmp, "afa", "a"); tmp = find_and_replace(tmp, "efe", "e"); tmp = find_and_replace(tmp, "ifi", "i"); tmp = find_and_replace(tmp, "ofo", "o"); tmp = find_and_replace(tmp, "ufu", "u"); ASSERT_STREQ( tmp.c_str(), "aeiou" ); } TEST(UtilsTest, TestFindAndReplaceWstr) { ASSERT_STREQ( find_and_replace(L"Jeff", L"e", L"efe").c_str(), L"Jefeff" ); std::wstring tmp = find_and_replace(L"Naif", L"a", L"afa"); ASSERT_STREQ( find_and_replace(tmp, L"i", L"ifi").c_str(), L"Nafaifif" ); tmp = find_and_replace(L"aeiou", L"a", L"afa"); tmp = find_and_replace(tmp, L"e", L"efe"); tmp = find_and_replace(tmp, L"i", L"ifi"); tmp = find_and_replace(tmp, L"o", L"ofo"); tmp = find_and_replace(tmp, L"u", L"ufu"); ASSERT_STREQ( tmp.c_str(), L"afaefeifiofoufu" ); tmp = find_and_replace(tmp, L"afa", L"a"); tmp = find_and_replace(tmp, L"efe", L"e"); tmp = find_and_replace(tmp, L"ifi", L"i"); tmp = find_and_replace(tmp, L"ofo", L"o"); tmp = find_and_replace(tmp, L"ufu", L"u"); ASSERT_STREQ( tmp.c_str(), L"aeiou" ); } struct A { bool x(); }; struct B { bool y(); }; struct C { bool x(); bool y; }; struct D : C {}; template using has_x = decltype(T::x); template using has_y = decltype(T::y); TEST(UtilsTest, TestIsDetected) { auto ret = is_detected::value; ASSERT_TRUE(ret); ret = is_detected::value; ASSERT_FALSE(ret); ret = is_detected::value; ASSERT_TRUE(ret); ret = is_detected::value; ASSERT_FALSE(ret); ret = is_detected::value; ASSERT_TRUE(ret); ret = is_detected::value; ASSERT_TRUE(ret); ret = is_detected::value; ASSERT_TRUE(ret); ret = is_detected::value; ASSERT_TRUE(ret); } TEST(DataTypesTests, TestNDArray) { float* data_f = new float[9] {0,1,2,3,4,5,6,7,8}; nb::NDArray arr({3, 3}, data_f); ASSERT_FLOAT_EQ(data_f[4], arr.at({1,1})); arr.at({1,1}) = 0.5; ASSERT_FLOAT_EQ(0.5, arr.at({1,1})); delete[] data_f; unsigned int* data_ui = new unsigned int[8] {0,1,2,3,4,5,6,7}; nb::NDArray arr3d({2,2,2}, data_ui); ASSERT_EQ(data_ui[5], arr3d.at({1,0,1})); arr3d.at({0,1,1}) = 23; ASSERT_EQ(23, arr3d.at({0,1,1})); delete[] data_ui; } } // namespace nb