TEST(test_math_random, generate_range_float) { for (size_t i = 0; i < 10000; ++i) { float value = sg_random_range_f(0.45, 0.46); EXPECT_PRED_FORMAT2(testing::FloatLE, 0.45, value); EXPECT_PRED_FORMAT2(testing::FloatLE, value, 0.46); } }
TYPED_TEST_P(GainTest, Vulnerability) { typedef TypeParam eT; BaseTest<eT>& t = *this; EXPECT_PRED_FORMAT2(equal2<eT>, eT(5)/10, g::vulnerability(t.id_2, t.unif_2)); EXPECT_PRED_FORMAT2(equal2<eT>, eT(1)/10, g::vulnerability(t.id_10, t.unif_10)); EXPECT_PRED_FORMAT2(equal2<eT>, 1, g::vulnerability(t.id_4, t.dirac_4)); EXPECT_PRED_FORMAT2(equal2<eT>, eT(8)/10, g::vulnerability(t.id_2, t.pi1)); }
TEST(FloatBoxTest, PositionTest) { FloatBox box(0, 0, 0, 4, 4, 4); box.move(FloatPoint3D(1, 2, 3)); EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, FloatBox(1, 2, 3, 4, 4, 4), box); box.setOrigin(FloatPoint3D(-1, -2, -3)); box.move(FloatPoint3D(-1, -2, -3)); EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, FloatBox(-2, -4, -6, 4, 4, 4), box); }
TYPED_TEST_P(GainTestReals, Mulg_leakage) { typedef TypeParam eT; BaseTest<eT>& t = *this; EXPECT_PRED_FORMAT2(equal2<eT>, 1, g::mulg_leakage(t.id_2, t.unif_2, t.id_2)); EXPECT_PRED_FORMAT2(equal2<eT>, qif::log2(10), g::mulg_leakage(t.id_10, t.unif_10, t.id_10)); EXPECT_PRED_FORMAT2(equal2<eT>, 0, g::mulg_leakage(t.id_10, t.unif_10, t.noint_10)); EXPECT_PRED_FORMAT2(equal2<eT>, qif::log2(1.5), g::mulg_leakage(t.id_2, t.unif_2, t.c1)); }
static void CheckStrToFloat(T fn(const char* s, char** end)) { FpUlpEq<0, T> pred; EXPECT_PRED_FORMAT2(pred, 9.0, fn("9.0", nullptr)); EXPECT_PRED_FORMAT2(pred, 9.0, fn("0.9e1", nullptr)); EXPECT_PRED_FORMAT2(pred, 9.0, fn("0x1.2p3", nullptr)); const char* s = " \t\v\f\r\n9.0"; char* p; EXPECT_PRED_FORMAT2(pred, 9.0, fn(s, &p)); EXPECT_EQ(s + strlen(s), p); EXPECT_TRUE(isnan(fn("+nan", nullptr))); EXPECT_TRUE(isnan(fn("nan", nullptr))); EXPECT_TRUE(isnan(fn("-nan", nullptr))); EXPECT_TRUE(isnan(fn("+nan(0xff)", nullptr))); EXPECT_TRUE(isnan(fn("nan(0xff)", nullptr))); EXPECT_TRUE(isnan(fn("-nan(0xff)", nullptr))); EXPECT_TRUE(isnan(fn("+nanny", &p))); EXPECT_STREQ("ny", p); EXPECT_TRUE(isnan(fn("nanny", &p))); EXPECT_STREQ("ny", p); EXPECT_TRUE(isnan(fn("-nanny", &p))); EXPECT_STREQ("ny", p); EXPECT_EQ(0, fn("muppet", &p)); EXPECT_STREQ("muppet", p); EXPECT_EQ(0, fn(" muppet", &p)); EXPECT_STREQ(" muppet", p); EXPECT_EQ(std::numeric_limits<T>::infinity(), fn("+inf", nullptr)); EXPECT_EQ(std::numeric_limits<T>::infinity(), fn("inf", nullptr)); EXPECT_EQ(-std::numeric_limits<T>::infinity(), fn("-inf", nullptr)); EXPECT_EQ(std::numeric_limits<T>::infinity(), fn("+infinity", nullptr)); EXPECT_EQ(std::numeric_limits<T>::infinity(), fn("infinity", nullptr)); EXPECT_EQ(-std::numeric_limits<T>::infinity(), fn("-infinity", nullptr)); EXPECT_EQ(std::numeric_limits<T>::infinity(), fn("+infinitude", &p)); EXPECT_STREQ("initude", p); EXPECT_EQ(std::numeric_limits<T>::infinity(), fn("infinitude", &p)); EXPECT_STREQ("initude", p); EXPECT_EQ(-std::numeric_limits<T>::infinity(), fn("-infinitude", &p)); EXPECT_STREQ("initude", p); // Check case-insensitivity. EXPECT_EQ(std::numeric_limits<T>::infinity(), fn("InFiNiTy", nullptr)); EXPECT_TRUE(isnan(fn("NaN", nullptr))); }
TEST(FloatBoxTest, UnionTest) { FloatBox box; EXPECT_TRUE(box.isEmpty()); FloatBox unionedBox(3, 5, 6, 5, 3, 9); box.unionBounds(unionedBox); EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, unionedBox, box); box.unionBounds(FloatBox()); EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, unionedBox, box); box.unionBounds(FloatBox(0, 0, 0, 1, 1, 1)); EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, FloatBox(0, 0, 0, 8, 8, 15), box); }
TEST(FloatSizeTest, DiagonalLengthTest) { // Sanity check the Pythagorean triples 3-4-5 and 5-12-13 FloatSize s1 = FloatSize(3.f, 4.f); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, s1.diagonalLength(), 5.f); FloatSize s2 = FloatSize(5.f, 12.f); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, s2.diagonalLength(), 13.f); // Test very small numbers. FloatSize s3 = FloatSize(.5e-20f, .5e-20f); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, s3.diagonalLength(), .707106781186548e-20f); // Test very large numbers. FloatSize s4 = FloatSize(.5e20f, .5e20f); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, s4.diagonalLength(), .707106781186548e20f); }
TEST(CoordinateCleanerTest, LongerRun) { auto pos_list = std::vector<pos> { {1,0,8,0,0,1,0,0,4}, {4}, {0,0,0,0,0,3,0,0,0,0,0,1}, {-31,0,14,7,0,1,0,0,4,9,1,0,1}, {0,0,0,0,0,0,0}, {4,0,0,9,0,7} }; auto cleaner = Manipulator::CoordinateCleaner{}; cleaner.execute(pos_list.begin(), pos_list.end()); auto expected = std::vector<pos> { { 1, 8,0,1,4,0,0,0,0}, { 4, 0,0,0,0,0,0,0,0}, { 0, 0,0,3,0,0,0,1,0}, {-31,14,7,1,4,9,1,0,1}, { 0, 0,0,0,0,0,0,0,0}, { 4, 0,9,7,0,0,0,0,0} }; ASSERT_EQ(expected.size(), pos_list.size()); for(std::size_t index = 0; index < expected.size(); ++index) { EXPECT_PRED_FORMAT2(UnitTest::ContainerCompare, expected.at(index), pos_list.at(index)); } }
TEST(Imgcodecs_Tiff_Modes, write_multipage) { const string root = cvtest::TS::ptr()->get_data_path(); const string filename = root + "readwrite/multipage.tif"; const string page_files[] = { "readwrite/multipage_p1.tif", "readwrite/multipage_p2.tif", "readwrite/multipage_p3.tif", "readwrite/multipage_p4.tif", "readwrite/multipage_p5.tif", "readwrite/multipage_p6.tif" }; const size_t page_count = sizeof(page_files) / sizeof(page_files[0]); vector<Mat> pages; for (size_t i = 0; i < page_count; i++) { const Mat page = imread(root + page_files[i]); pages.push_back(page); } string tmp_filename = cv::tempfile(".tiff"); bool res = imwrite(tmp_filename, pages); ASSERT_TRUE(res); vector<Mat> read_pages; imreadmulti(tmp_filename, read_pages); for (size_t i = 0; i < page_count; i++) { EXPECT_PRED_FORMAT2(cvtest::MatComparator(0, 0), read_pages[i], pages[i]); } }
TEST(FloatPointTest, LengthTest) { // Sanity check the Pythagorean triples 3-4-5 and 5-12-13 FloatPoint p1 = FloatPoint(3.f, 4.f); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, p1.length(), 5.f); FloatPoint p2 = FloatPoint(5.f, 12.f); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, p2.length(), 13.f); // Test very small numbers. This fails under the old implementation of // FloatPoint::length(): `return sqrtf(lengthSquared());' FloatPoint p3 = FloatPoint(.5e-20f, .5e-20f); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, p3.length(), .707106781186548e-20f); // Test very large numbers. FloatPoint p4 = FloatPoint(.5e20f, .5e20f); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, p4.length(), .707106781186548e20f); }
TEST(FloatBoxTest, CopyTest) { FloatBox box(1, 2, 3, 4, 4, 4); FloatBox box2(box); EXPECT_EQ(box, box2); box.setSize(FloatPoint3D(3, 3, 3)); EXPECT_NE(box, box2); EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, FloatBox(1, 2, 3, 3, 3, 3), box); }
TEST(FloatBoxTest, ExpandTests) { FloatBox box; box.expandTo(FloatPoint3D(10, -3, 2)); EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, FloatBox(0, -3, 0, 10, 3, 2), box); box.expandTo(FloatPoint3D(-15, 6, 8)); EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, FloatBox(-15, -3, 0, 25, 9, 8), box); box = FloatBox(); box.expandTo(FloatPoint3D(-3, 6, 9), FloatPoint3D(-2, 10, 11)); EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, FloatBox(-3, 0, 0, 3, 10, 11), box); box = FloatBox(); box.expandTo(FloatBox(-10, -10, -10, 3, 30, 40)); box.expandTo(FloatBox(-11, 3, 50, 10, 15, 1)); EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, FloatBox(-11, -10, -10, 11, 30, 61), box); }
TEST(ElID, Encode) { std::vector<char> expected; // 1xxxxxxx expected.assign(1, 0x80); EXPECT_PRED_FORMAT2(test_utils::std_vectors_eq, expected, tawara::ids::encode(0x80)); expected[0] = 0x81; EXPECT_PRED_FORMAT2(test_utils::std_vectors_eq, expected, tawara::ids::encode(0x81)); expected[0] = 0x97; EXPECT_PRED_FORMAT2(test_utils::std_vectors_eq, expected, tawara::ids::encode(0x97)); expected[0] = 0xC0; EXPECT_PRED_FORMAT2(test_utils::std_vectors_eq, expected, tawara::ids::encode(0xC0)); expected[0] = 0xFE; EXPECT_PRED_FORMAT2(test_utils::std_vectors_eq, expected, tawara::ids::encode(0xFE)); EXPECT_THROW(tawara::ids::encode(0xFF), tawara::InvalidEBMLID); // 01xxxxxx xxxxxxxx expected.assign(2, 0); expected[0] = 0x40; EXPECT_PRED_FORMAT2(test_utils::std_vectors_eq, expected, tawara::ids::encode(0x4000)); expected[0] = 0x4B; expected[1] = 0x35; EXPECT_PRED_FORMAT2(test_utils::std_vectors_eq, expected, tawara::ids::encode(0x4B35)); expected[0] = 0x7F; expected[1] = 0xFE; EXPECT_PRED_FORMAT2(test_utils::std_vectors_eq, expected, tawara::ids::encode(0x7FFE)); EXPECT_THROW(tawara::ids::encode(0x7FFF), tawara::InvalidEBMLID); /* Uncomment this if EBML IDs expand to 64 bits. // 00000001 xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx expected.assign(7, 0xFF); expected[0] = 0x01; expected[7] = 0xFE; EXPECT_PRED_FORMAT2(test_utils::std_vectors_eq, expected, tawara::ids::encode(0x01FFFFFFFFFFFFFE)); EXPECT_THROW(tawara::ids::encode(0x01FFFFFFFFFFFFFF, buffer), tawara::InvalidEBMLID); */ // EBML tag expected.assign(4, 0x1A); expected[1] = 0x45; expected[2] = 0xDF; expected[3] = 0xA3; EXPECT_PRED_FORMAT2(test_utils::std_vectors_eq, expected, tawara::ids::encode(0x1A45DFA3)); }
TEST(MemoryCluster, Write) { std::ostringstream output; std::stringstream expected; tawara::UIntElement tc(tawara::ids::Timecode, 0); tawara::BlockElement::Ptr b1(new tawara::SimpleBlock(1, 12345, tawara::Block::LACING_NONE)); tawara::BlockElement::Ptr b2(new tawara::SimpleBlock(2, 26262, tawara::Block::LACING_NONE)); tawara::Block::value_type f1(test_utils::make_blob(5)); b1->push_back(f1); tawara::Block::value_type f2(test_utils::make_blob(10)); b2->push_back(f2); tawara::MemoryCluster c; std::streamsize expected_size(tc.size()); tawara::ids::write(tawara::ids::Cluster, expected); tawara::vint::write(expected_size, expected, 8); tc.write(expected); EXPECT_EQ(tawara::ids::size(tawara::ids::Cluster) + 8 + expected_size, c.write(output)); EXPECT_PRED_FORMAT2(test_utils::std_buffers_eq, output.str(), expected.str()); output.str(std::string()); expected.str(std::string()); c.push_back(b1); c.push_back(b2); tawara::ids::write(tawara::ids::Cluster, expected); tawara::vint::write(expected_size, expected, 8); tc.write(expected); EXPECT_EQ(tawara::ids::size(tawara::ids::Cluster) + 8 + expected_size, c.write(output)); EXPECT_PRED_FORMAT2(test_utils::std_buffers_eq, output.str(), expected.str()); expected_size += b1->size() + b2->size(); b1->write(expected); b2->write(expected); EXPECT_EQ(tawara::ids::size(tawara::ids::Cluster) + 8 + expected_size, c.finalise(output)); EXPECT_PRED_FORMAT2(test_utils::std_buffers_eq, output.str(), expected.str()); }
virtual void SetUp() { generate_random_uri(source_root, "copyfile_timeout_source", source, 2048); generate_random_uri(destination_root, "copyfile_timeout", destination, 2048); RecordProperty("Source", source); RecordProperty("Destination", source); GError* error = NULL; int ret = generate_file_if_not_exists(handle, source, "file:///etc/hosts", &error); EXPECT_PRED_FORMAT2(AssertGfalSuccess, ret, error); }
TEST(VoidElement, Write) { std::stringstream output; std::string expected; std::streamsize size(5), f_size(20); bool fill(false); std::string c0; for (std::streamsize ii(0); ii < f_size; ++ii) { // Fill the output with some data to overwrite c0.push_back(0xC0); } tawara::VoidElement v(size); output.str(c0); std::string().swap(expected); test_vel::fill_buffer(expected, size, f_size, fill, true, true); EXPECT_EQ(size, v.write(output)); EXPECT_PRED_FORMAT2(test_utils::std_buffers_eq, output.str(), expected); // With or without filling, the stream write pointer should be after the // body of the void element EXPECT_EQ(v.size(), output.tellp()); fill = true; v.fill(fill); output.str(c0); output.seekp(0, std::ios::beg); std::string().swap(expected); test_vel::fill_buffer(expected, size, f_size, fill, true, true); EXPECT_EQ(size, v.write(output)); EXPECT_PRED_FORMAT2(test_utils::std_buffers_eq, output.str(), expected); EXPECT_EQ(v.size(), output.tellp()); // Offset test output.str("ab" + c0); output.seekp(2); expected = "ab"; test_vel::fill_buffer(expected, size, f_size, fill, true, true); v.write(output); EXPECT_EQ(2, v.offset()); }
TEST(BaseCluster, Write) { std::ostringstream output; std::stringstream expected; tawara::UIntElement tc(tawara::ids::Timecode, 0); tawara::UIntElement st1(tawara::ids::SilentTrackNumber, 1); tawara::UIntElement st2(tawara::ids::SilentTrackNumber, 2); tawara::UIntElement ps(tawara::ids::PrevSize, 0x1234); FakeCluster e; std::streamsize expected_size(tc.size()); tawara::ids::write(tawara::ids::Cluster, expected); tawara::vint::write(expected_size, expected, 8); tc.write(expected); EXPECT_EQ(tawara::ids::size(tawara::ids::Cluster) + 8 + expected_size, e.write(output)); EXPECT_PRED_FORMAT2(test_utils::std_buffers_eq, output.str(), expected.str()); expected_size += tawara::ids::size(tawara::ids::SilentTracks) + tawara::vint::size(st1.size() + st2.size()) + st1.size() + st2.size() + ps.size(); e.silent_tracks().push_back(tawara::SilentTrackNumber(1)); e.silent_tracks().push_back(tawara::SilentTrackNumber(2)); e.previous_size(0x1234); output.str(std::string()); expected.str(std::string()); tawara::ids::write(tawara::ids::Cluster, expected); tawara::vint::write(expected_size, expected, 8); tc.write(expected); tawara::ids::write(tawara::ids::SilentTracks, expected); tawara::vint::write(st1.size() + st2.size(), expected); st1.write(expected); st2.write(expected); ps.write(expected); EXPECT_EQ(tawara::ids::size(tawara::ids::Cluster) + 8 + expected_size, e.write(output)); EXPECT_PRED_FORMAT2(test_utils::std_buffers_eq, output.str(), expected.str()); }
TEST(RelativePositionSummerTest, TwoDirectionsOneDim) { auto positions = std::list<pos> { {1,1} }; List list_ref {positions}; auto command = Command::TestAdvancedTermCollector<1>{}; auto summer = Manipulator::RelPosSummer<1>{&command}; summer.ForAll(list_ref.begin(), list_ref.end()); auto result = command.ExtractData(); auto expected = Command::TestAdvancedTermCollector<1>::container_type{}; expected.insert( { { {{2}} }, 1} ); EXPECT_PRED_FORMAT2(UnitTest::ContainerCompare, expected, result); }
TEST_F(PropertiesTest, GetInt32) { const int32_t DEFAULT_VALUE = INT32_C(0xDEADBEEF); const std::string intMaxString = ToString(INT32_MAX); const std::string intStringOverflow = intMaxString + "0"; const std::string intMinString = ToString(INT32_MIN); const std::string intStringUnderflow = intMinString + "0"; const char* setValues[] = { // base 10 "1", "2", "12345", "-1", "-2", "-12345", // base 16 "0xFF", "0x0FF", "0xC0FFEE", "0Xf00", // base 8 "0", "01234", "07", // corner cases " 2", "2 ", "+0", "-0", " +0 ", intMaxString.c_str(), intMinString.c_str(), // failing cases NULL, "", " ", " ", "hello", " true ", "y", intStringOverflow.c_str(), intStringUnderflow.c_str(), }; int32_t getValues[] = { // base 10 1, 2, 12345, -1, -2, -12345, // base 16 0xFF, 0x0FF, 0xC0FFEE, 0Xf00, // base 8 0, 01234, 07, // corner cases 2, 2, 0, 0, 0, INT32_MAX, INT32_MIN, // failing cases DEFAULT_VALUE, DEFAULT_VALUE, DEFAULT_VALUE, DEFAULT_VALUE, DEFAULT_VALUE, DEFAULT_VALUE, DEFAULT_VALUE, DEFAULT_VALUE, DEFAULT_VALUE, }; ASSERT_EQ(arraysize(setValues), arraysize(getValues)); for (size_t i = 0; i < arraysize(setValues); ++i) { ASSERT_OK(property_set(PROPERTY_TEST_KEY, setValues[i])); int32_t val = property_get_int32(PROPERTY_TEST_KEY, DEFAULT_VALUE); EXPECT_PRED_FORMAT2(AssertEqualHex, getValues[i], val) << "Property was set to '" << setValues[i] << "'"; } }
TYPED_TEST_P(GainTest, Add_capacity) { typedef TypeParam eT; BaseTest<eT>& t = *this; EXPECT_PRED_FORMAT2(equal2<eT>, eT(1)/2, g::add_capacity(t.unif_2, t.id_2, true)); EXPECT_PRED_FORMAT2(equal2<eT>, 1, g::add_capacity(t.unif_2, t.id_2, false)); EXPECT_PRED_FORMAT2(equal2<eT>, 0, g::add_capacity(t.dirac_2, t.id_2, true)); EXPECT_PRED_FORMAT2(equal2<eT>, 0, g::add_capacity(t.dirac_2, t.id_2, false)); EXPECT_PRED_FORMAT2(equal2<eT>, 0, g::add_capacity(t.unif_4, t.noint_4, true)); EXPECT_PRED_FORMAT2(equal2<eT>, 0, g::add_capacity(t.unif_4, t.noint_4, false)); ASSERT_ANY_THROW(g::add_capacity(t.unif_2, t.id_10)); }
TEST(UtilTest, HtpParseUri) { bstr *input = NULL; htp_uri_t *uri = NULL; uri_test *test; input = bstr_dup_c(""); EXPECT_EQ(HTP_OK, htp_parse_uri(input, &uri)); bstr_free(input); free_htp_uri_t(&uri); test = uri_tests; while (test->uri != NULL) { input = bstr_dup_c(test->uri); EXPECT_EQ(HTP_OK, htp_parse_uri(input, &uri)); EXPECT_PRED_FORMAT2(UriIsExpected, test->expected, uri) << "Failed URI = " << test->uri << std::endl; bstr_free(input); free_htp_uri_t(&uri); ++test; } }
TEST_P(Imgcodecs_Tiff_Modes, decode_multipage) { const int mode = GetParam(); const string root = cvtest::TS::ptr()->get_data_path(); const string filename = root + "readwrite/multipage.tif"; const string page_files[] = { "readwrite/multipage_p1.tif", "readwrite/multipage_p2.tif", "readwrite/multipage_p3.tif", "readwrite/multipage_p4.tif", "readwrite/multipage_p5.tif", "readwrite/multipage_p6.tif" }; const size_t page_count = sizeof(page_files)/sizeof(page_files[0]); vector<Mat> pages; bool res = imreadmulti(filename, pages, mode); ASSERT_TRUE(res == true); ASSERT_EQ(page_count, pages.size()); for (size_t i = 0; i < page_count; i++) { const Mat page = imread(root + page_files[i], mode); EXPECT_PRED_FORMAT2(cvtest::MatComparator(0, 0), page, pages[i]); } }
TEST(FloatBoxTest, FlattenTest) { FloatBox box(1, 2, 3, 4, 4, 4); box.flatten(); EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, FloatBox(1, 2, 0, 4, 4, 0), box); }
TYPED_TEST_P(GainTest, Cond_vulnerability) { typedef TypeParam eT; BaseTest<eT>& t = *this; EXPECT_PRED_FORMAT2(equal2<eT>, 1, g::post_vulnerability(t.id_2, t.unif_2, t.id_2)); EXPECT_PRED_FORMAT2(equal2<eT>, 1, g::post_vulnerability(t.id_2, t.dirac_2, t.id_2)); EXPECT_PRED_FORMAT2(equal2<eT>, 1, g::post_vulnerability(t.id_2, t.pi1, t.id_2)); EXPECT_PRED_FORMAT2(equal2<eT>, 1, g::post_vulnerability(t.id_10, t.unif_10, t.id_10)); EXPECT_PRED_FORMAT2(equal2<eT>, 1, g::post_vulnerability(t.id_10, t.dirac_10, t.id_10)); EXPECT_PRED_FORMAT2(equal2<eT>, 1, g::post_vulnerability(t.id_10, t.pi2, t.id_10)); EXPECT_PRED_FORMAT2(equal2<eT>, eT(1)/10, g::post_vulnerability(t.id_10, t.unif_10, t.noint_10)); EXPECT_PRED_FORMAT2(equal2<eT>, 1, g::post_vulnerability(t.id_10, t.dirac_10, t.noint_10)); EXPECT_PRED_FORMAT2(equal2<eT>, g::vulnerability(t.id_10, t.pi2), g::post_vulnerability(t.id_10, t.pi2, t.noint_10)); EXPECT_PRED_FORMAT2(equal2<eT>, g::vulnerability(t.id_2, t.pi3), g::post_vulnerability(t.id_2, t.pi3, t.c1)); // no change in entropy EXPECT_PRED_FORMAT2(equal2<eT>, eT(31)/40, g::post_vulnerability(t.id_2, t.pi4, t.c1)); ASSERT_ANY_THROW(g::post_vulnerability(t.id_10, t.unif_2, t.id_10)); }
TEST(FloatRectTest, SquaredDistanceToTest) { // // O--x // | // y // // FloatRect.x() FloatRect.maxX() // | | // 1 | 2 | 3 // ======+==========+====== --FloatRect.y() // 4 | 5(in) | 6 // ======+==========+====== --FloatRect.maxY() // 7 | 8 | 9 // FloatRect r1(100, 100, 250, 150); // `1` case FloatPoint p1(80, 80); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p1), 800.f); FloatPoint p2(-10, -10); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p2), 24200.f); FloatPoint p3(80, -10); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p3), 12500.f); // `2` case FloatPoint p4(110, 80); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p4), 400.f); FloatPoint p5(150, 0); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p5), 10000.f); FloatPoint p6(180, -10); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p6), 12100.f); // `3` case FloatPoint p7(400, 80); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p7), 2900.f); FloatPoint p8(360, -10); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p8), 12200.f); // `4` case FloatPoint p9(80, 110); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p9), 400.f); FloatPoint p10(-10, 180); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p10), 12100.f); // `5`(& In) case FloatPoint p11(100, 100); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p11), 0.f); FloatPoint p12(150, 100); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p12), 0.f); FloatPoint p13(350, 100); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p13), 0.f); FloatPoint p14(350, 150); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p14), 0.f); FloatPoint p15(350, 250); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p15), 0.f); FloatPoint p16(150, 250); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p16), 0.f); FloatPoint p17(100, 250); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p17), 0.f); FloatPoint p18(100, 150); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p18), 0.f); FloatPoint p19(150, 150); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p19), 0.f); // `6` case FloatPoint p20(380, 150); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p20), 900.f); // `7` case FloatPoint p21(80, 280); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p21), 1300.f); FloatPoint p22(-10, 300); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p22), 14600.f); // `8` case FloatPoint p23(180, 300); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p23), 2500.f); // `9` case FloatPoint p24(450, 450); EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p24), 50000.f); }
void checkInDense(std::vector<int>& amdRowPtr, std::vector<int>& amdColIndices, std::vector<T>& amdVals) { uBLAS::mapped_matrix<T> sparseDense(csrMatrixC.num_rows, csrMatrixC.num_cols, 0); uBLAS::mapped_matrix<T> boostDense(csrMatrixC.num_rows, csrMatrixC.num_cols, 0); // boost sparse_prod cancels out zeros and hence reports more accurately non-zeros // In clSPARSE, spGeMM produces more non-zeros, and considers some zeros as nonzeros. // Therefore converting to dense and verifying the output in dense format // Convert CSR to Dense for (int i = 0; i < amdRowPtr.size() - 1; i++) { // i corresponds to row index for (int j = amdRowPtr[i]; j < amdRowPtr[i + 1]; j++) sparseDense(i, amdColIndices[j]) = amdVals[j]; } for (int i = 0; i < this->C.index1_data().size() - 1; i++) { for (int j = this->C.index1_data()[i]; j < this->C.index1_data()[i + 1]; j++) boostDense(i, this->C.index2_data()[j]) = this->C.value_data()[j]; } bool brelativeErrorFlag = false; bool babsErrorFlag = false; for (int i = 0; i < csrMatrixC.num_rows; i++) { for (int j = 0; j < csrMatrixC.num_cols; j++) { //ASSERT_EQ(boostDense(i, j), sparseDense(i, j)); #ifdef _DEBUG_SpMxSpM_ ASSERT_NEAR(boostDense(i, j), sparseDense(i, j), SPGEMM_PREC_ERROR); #else if (fabs(boostDense(i, j) - sparseDense(i, j)) > SPGEMM_PREC_ERROR) { babsErrorFlag = true; SCOPED_TRACE("Absolute Error Fail"); break; } #endif } } // Relative Error for (int i = 0; i < csrMatrixC.num_rows; i++) { for (int j = 0; j < csrMatrixC.num_cols; j++) { float diff = fabs(boostDense(i, j) - sparseDense(i, j)); float ratio = diff / boostDense(i, j); #ifdef _DEBUG_SpMxSpM_ // ratio is less than or almost equal to SPGEMM_REL_ERROR EXPECT_PRED_FORMAT2(::testing::FloatLE, ratio, SPGEMM_REL_ERROR); #else if (diff / boostDense(i, j) > SPGEMM_REL_ERROR) { brelativeErrorFlag = true; SCOPED_TRACE("Relative Error Fail"); break; } #endif } }// #ifndef _DEBUG_SpMxSpM_ if (brelativeErrorFlag) { ASSERT_FALSE(babsErrorFlag); } if (babsErrorFlag) { ASSERT_FALSE(brelativeErrorFlag); } #endif }// end
TEST(ElIDStream, Write) { std::ostringstream buffer; std::ostringstream expected; // 1xxxxxxx expected.put(0x80); EXPECT_EQ(1, tawara::ids::write(0x80, buffer)); EXPECT_PRED_FORMAT2(test_utils::std_buffers_eq, expected.str(), buffer.str()); expected.put(0x81); EXPECT_EQ(1, tawara::ids::write(0x81, buffer)); EXPECT_PRED_FORMAT2(test_utils::std_buffers_eq, expected.str(), buffer.str()); expected.put(0x97); EXPECT_EQ(1, tawara::ids::write(0x97, buffer)); EXPECT_PRED_FORMAT2(test_utils::std_buffers_eq, expected.str(), buffer.str()); expected.put(0xC0); EXPECT_EQ(1, tawara::ids::write(0xC0, buffer)); EXPECT_PRED_FORMAT2(test_utils::std_buffers_eq, expected.str(), buffer.str()); expected.put(0xFE); EXPECT_EQ(1, tawara::ids::write(0xFE, buffer)); EXPECT_PRED_FORMAT2(test_utils::std_buffers_eq, expected.str(), buffer.str()); EXPECT_THROW(tawara::ids::write(0xFF, buffer), tawara::InvalidEBMLID); // 01xxxxxx xxxxxxxx expected.put(0x40); expected.put(0x00); EXPECT_EQ(2, tawara::ids::write(0x4000, buffer)); EXPECT_PRED_FORMAT2(test_utils::std_buffers_eq, expected.str(), buffer.str()); expected.put(0x4B); expected.put(0x35); EXPECT_EQ(2, tawara::ids::write(0x4B35, buffer)); EXPECT_PRED_FORMAT2(test_utils::std_buffers_eq, expected.str(), buffer.str()); expected.put(0x7F); expected.put(0xFE); EXPECT_EQ(2, tawara::ids::write(0x7FFE, buffer)); EXPECT_PRED_FORMAT2(test_utils::std_buffers_eq, expected.str(), buffer.str()); EXPECT_THROW(tawara::ids::write(0x7FFF, buffer), tawara::InvalidEBMLID); /* Uncomment this if EBML IDs expand to 64 bits. // 00000001 xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx expected.put(0x01); for (int ii(0); ii < 6; ii++) { expected.put(0xFF); } expected.put(0xFE); EXPECT_EQ(8, tawara::ids::write(0x01FFFFFFFFFFFFFE, buffer)); EXPECT_PRED_FORMAT2(test_utils::std_buffers_eq, expected.str(), buffer.str()); EXPECT_THROW(tawara::ids::write(0x01FFFFFFFFFFFFFF, buffer), tawara::InvalidEBMLID); */ // EBML tag expected.put(0x1A); expected.put(0x45); expected.put(0xDF); expected.put(0xA3); EXPECT_EQ(4, tawara::ids::write(0x1A45DFA3, buffer)); EXPECT_PRED_FORMAT2(test_utils::std_buffers_eq, expected.str(), buffer.str()); }
TEST(test_math_random, generate_float) { for (size_t i = 0; i < 10000; ++i) EXPECT_PRED_FORMAT2(testing::FloatLE, 0, sg_random_f()); }
TEST(FloatTest, FloatEqInput) { EXPECT_PRED_FORMAT2(testing::FloatLE, 4, 5); }