📄 hist_02.cc
字号:
long_counts.assign(test_counts); VectorShort short_counts; short_counts.assign(test_counts); VectorUllong ullong_counts; ullong_counts.assign(test_counts); VectorUlong ulong_counts; ulong_counts.assign(test_counts); VectorUshort ushort_counts; ushort_counts.assign(test_counts); if (!hist6.setCounts(byte_counts) || !hist6.counts_d.eq(test_counts)) { test_counts.debug(L"expected counts"); hist6.counts_d.debug(L"actual counts"); return Error::handle(name(), L"setCounts", Error::TEST, __FILE__, __LINE__); } if (!hist6.setCounts(double_counts) || !hist6.counts_d.eq(test_counts)) { test_counts.debug(L"expected counts"); hist6.counts_d.debug(L"actual counts"); return Error::handle(name(), L"setCounts", Error::TEST, __FILE__, __LINE__); } if (!hist6.setCounts(float_counts) || !hist6.counts_d.eq(test_counts)) { test_counts.debug(L"expected counts"); hist6.counts_d.debug(L"actual counts"); return Error::handle(name(), L"setCounts", Error::TEST, __FILE__, __LINE__); } if (!hist6.setCounts(llong_counts) || !hist6.counts_d.eq(test_counts)) { test_counts.debug(L"expected counts"); hist6.counts_d.debug(L"actual counts"); return Error::handle(name(), L"setCounts", Error::TEST, __FILE__, __LINE__); } if (!hist6.setCounts(long_counts) || !hist6.counts_d.eq(test_counts)) { test_counts.debug(L"expected counts"); hist6.counts_d.debug(L"actual counts"); return Error::handle(name(), L"setCounts", Error::TEST, __FILE__, __LINE__); } if (!hist6.setCounts(short_counts) || !hist6.counts_d.eq(test_counts)) { test_counts.debug(L"expected counts"); hist6.counts_d.debug(L"actual counts"); return Error::handle(name(), L"setCounts", Error::TEST, __FILE__, __LINE__); } if (!hist6.setCounts(ullong_counts) || !hist6.counts_d.eq(test_counts)) { test_counts.debug(L"expected counts"); hist6.counts_d.debug(L"actual counts"); return Error::handle(name(), L"setCounts", Error::TEST, __FILE__, __LINE__); } if (!hist6.setCounts(ulong_counts) || !hist6.counts_d.eq(test_counts)) { test_counts.debug(L"expected counts"); hist6.counts_d.debug(L"actual counts"); return Error::handle(name(), L"setCounts", Error::TEST, __FILE__, __LINE__); } if (!hist6.setCounts(ushort_counts) || !hist6.counts_d.eq(test_counts)) { test_counts.debug(L"expected counts"); hist6.counts_d.debug(L"actual counts"); return Error::handle(name(), L"setCounts", Error::TEST, __FILE__, __LINE__); } // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } //--------------------------------------------------------------------------- // // 3. class-specific public methods: // get methods // //--------------------------------------------------------------------------- // set indentation // if (level_a > Integral::NONE) { Console::put(L"testing class-specific public methods: get methods...\n"); Console::increaseIndention(); } // test getMode // if (hist5.getMode() != CENTERS) { return Error::handle(name(), L"getMode", Error::TEST, __FILE__, __LINE__); } // test getBins // VectorDouble tmp; if (!hist6.getBins(tmp) || !tmp.almostEqual(test_edges_bins)) { return Error::handle(name(), L"getBins", Error::TEST, __FILE__, __LINE__); } // test getCounts // hist6.setCounts(test_counts); hist6.getCounts(byte_counts); hist6.getCounts(double_counts); hist6.getCounts(float_counts); hist6.getCounts(llong_counts); hist6.getCounts(long_counts); hist6.getCounts(short_counts); hist6.getCounts(ullong_counts); hist6.getCounts(ulong_counts); hist6.getCounts(ushort_counts); VectorDouble tmp_vec; if (!tmp_vec.assign(byte_counts) || !hist6.counts_d.eq(tmp_vec)) { test_counts.debug(L"expected counts"); byte_counts.debug(L"actual counts"); return Error::handle(name(), L"setCounts", Error::TEST, __FILE__, __LINE__); } if (!tmp_vec.assign(double_counts) || !hist6.counts_d.eq(tmp_vec)) { test_counts.debug(L"expected counts"); double_counts.debug(L"actual counts"); return Error::handle(name(), L"setCounts", Error::TEST, __FILE__, __LINE__); } if (!tmp_vec.assign(float_counts) || !hist6.counts_d.eq(tmp_vec)) { test_counts.debug(L"expected counts"); float_counts.debug(L"actual counts"); return Error::handle(name(), L"setCounts", Error::TEST, __FILE__, __LINE__); } if (!tmp_vec.assign(llong_counts) || !hist6.counts_d.eq(tmp_vec)) { test_counts.debug(L"expected counts"); llong_counts.debug(L"actual counts"); return Error::handle(name(), L"setCounts", Error::TEST, __FILE__, __LINE__); } if (!tmp_vec.assign(long_counts) || !hist6.counts_d.eq(tmp_vec)) { test_counts.debug(L"expected counts"); long_counts.debug(L"actual counts"); return Error::handle(name(), L"setCounts", Error::TEST, __FILE__, __LINE__); } if (!tmp_vec.assign(short_counts) || !hist6.counts_d.eq(tmp_vec)) { test_counts.debug(L"expected counts"); short_counts.debug(L"actual counts"); return Error::handle(name(), L"setCounts", Error::TEST, __FILE__, __LINE__); } if (!tmp_vec.assign(ullong_counts) || !hist6.counts_d.eq(tmp_vec)) { test_counts.debug(L"expected counts"); ullong_counts.debug(L"actual counts"); return Error::handle(name(), L"setCounts", Error::TEST, __FILE__, __LINE__); } if (!tmp_vec.assign(ulong_counts) || !hist6.counts_d.eq(tmp_vec)) { test_counts.debug(L"expected counts"); ulong_counts.debug(L"actual counts"); return Error::handle(name(), L"setCounts", Error::TEST, __FILE__, __LINE__); } if (!tmp_vec.assign(ushort_counts) || !hist6.counts_d.eq(tmp_vec)) { test_counts.debug(L"expected counts"); ushort_counts.debug(L"actual counts"); return Error::handle(name(), L"setCounts", Error::TEST, __FILE__, __LINE__); } // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } //--------------------------------------------------------------------------- // // 4. class-specific public methods: // compute methods // //--------------------------------------------------------------------------- // set indentation // if (level_a > Integral::NONE) { Console::put(L"testing class-specific public methods: get methods...\n"); Console::increaseIndention(); } // create a vector of expected counts for comparison // VectorDouble expected_counts; VectorDouble actual_counts; // test compute methods with centered bins // // test a new histogram in CENTERS mode for each data type // expected_counts.assign(L"2, 1, 1, 1, 1, 1, 1, 1, 1, 1"); hist6.clear(); hist6.setMode(CENTERS); VectorByte byte_data; byte_data.assign(test_data); hist6.compute(byte_data); hist6.getCounts(actual_counts); if (!actual_counts.eq(expected_counts)) { actual_counts.debug(L"actual counts"); expected_counts.debug(L"expected counts"); return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__); } hist6.clear(); hist6.setMode(CENTERS); VectorDouble double_data; double_data.assign(test_data); hist6.compute(double_data); hist6.getCounts(actual_counts); if (!actual_counts.eq(expected_counts)) { actual_counts.debug(L"actual counts"); expected_counts.debug(L"expected counts"); return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__); } hist6.clear(); hist6.setMode(CENTERS); VectorFloat float_data; float_data.assign(test_data); hist6.compute(float_data); hist6.getCounts(actual_counts); if (!actual_counts.eq(expected_counts)) { actual_counts.debug(L"actual counts"); expected_counts.debug(L"expected counts"); return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__); } hist6.clear(); hist6.setMode(CENTERS); VectorLlong llong_data; llong_data.assign(test_data); hist6.compute(llong_data); hist6.getCounts(actual_counts); if (!actual_counts.eq(expected_counts)) { actual_counts.debug(L"actual counts"); expected_counts.debug(L"expected counts"); return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__); } hist6.clear(); hist6.setMode(CENTERS); VectorLong long_data; long_data.assign(test_data); hist6.compute(long_data); hist6.getCounts(actual_counts); if (!actual_counts.eq(expected_counts)) { actual_counts.debug(L"actual counts"); expected_counts.debug(L"expected counts"); return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__); } hist6.clear(); hist6.setMode(CENTERS); VectorShort short_data; short_data.assign(test_data); hist6.compute(short_data); hist6.getCounts(actual_counts); if (!actual_counts.eq(expected_counts)) { actual_counts.debug(L"actual counts"); expected_counts.debug(L"expected counts"); return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__); } hist6.clear(); hist6.setMode(CENTERS); VectorUllong ullong_data; ullong_data.assign(test_data); hist6.compute(ullong_data); hist6.getCounts(actual_counts); if (!actual_counts.eq(expected_counts)) { actual_counts.debug(L"actual counts"); expected_counts.debug(L"expected counts"); return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__); } hist6.clear(); hist6.setMode(CENTERS); VectorUlong ulong_data; ulong_data.assign(test_data); hist6.compute(ulong_data); hist6.getCounts(actual_counts); if (!actual_counts.eq(expected_counts)) { actual_counts.debug(L"actual counts"); expected_counts.debug(L"expected counts"); return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__); } hist6.clear(); hist6.setMode(CENTERS); VectorUshort ushort_data; ushort_data.assign(test_data); hist6.compute(ushort_data); hist6.getCounts(actual_counts); if (!actual_counts.eq(expected_counts)) { actual_counts.debug(L"actual counts"); expected_counts.debug(L"expected counts"); return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__); } // test a histogram with preset bins in CENTERS mode for each data type // expected_counts.assign(L"2, 1, 1, 1, 1, 1, 1, 1, 1, 1"); hist6.clear(); hist6.setMode(CENTERS); hist6.setBins(test_data.min(), test_data.max(), DEF_NUM_BINS); hist6.compute(byte_data); hist6.getCounts(actual_counts); if (!actual_counts.eq(expected_counts)) { actual_counts.debug(L"actual counts"); expected_counts.debug(L"expected counts"); return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__); } hist6.clear(); hist6.setMode(CENTERS); hist6.setBins(test_data.min(), test_data.max(), DEF_NUM_BINS); hist6.compute(double_data); hist6.getCounts(actual_counts); if (!actual_counts.eq(expected_counts)) { actual_counts.debug(L"actual counts"); expected_counts.debug(L"expected counts"); return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__); } hist6.clear(); hist6.setMode(CENTERS); hist6.setBins(test_data.min(), test_data.max(), DEF_NUM_BINS); hist6.compute(float_data); hist6.getCounts(actual_counts); if (!actual_counts.eq(expected_counts)) { actual_counts.debug(L"actual counts"); expected_counts.debug(L"expected counts"); return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__); } hist6.clear(); hist6.setMode(CENTERS); hist6.setBins(test_data.min(), test_data.max(), DEF_NUM_BINS); hist6.compute(llong_data); hist6.getCounts(actual_counts); if (!actual_counts.eq(expected_counts)) { actual_counts.debug(L"actual counts"); expected_counts.debug(L"expected counts"); return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__); } hist6.clear(); hist6.setMode(CENTERS); hist6.setBins(test_data.min(), test_data.max(), DEF_NUM_BINS); hist6.compute(long_data); hist6.getCounts(actual_counts); if (!actual_counts.eq(expected_counts)) { actual_counts.debug(L"actual counts"); expected_counts.debug(L"expected counts"); return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__); } hist6.clear(); hist6.setMode(CENTERS); hist6.setBins(test_data.min(), test_data.max(), DEF_NUM_BINS); hist6.compute(short_data); hist6.getCounts(actual_counts); if (!actual_counts.eq(expected_counts)) { actual_counts.debug(L"actual counts"); expected_counts.debug(L"expected counts"); return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__); } hist6.clear(); hist6.setMode(CENTERS); hist6.setBins(test_data.min(), test_data.max(), DEF_NUM_BINS); hist6.compute(ullong_data); hist6.getCounts(actual_counts); if (!actual_counts.eq(expected_counts)) { actual_counts.debug(L"actual counts"); expected_counts.debug(L"expected counts"); return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__); } hist6.clear(); hist6.setMode(CENTERS); hist6.setBins(test_data.min(), test_data.max(), DEF_NUM_BINS); hist6.compute(ulong_data); hist6.getCounts(actual_counts); if (!actual_counts.eq(expected_counts)) { actual_counts.debug(L"actual counts"); expected_counts.debug(L"expected counts"); return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__); } hist6.clear(); hist6.setMode(CENTERS); hist6.setBins(test_data.min(), test_data.max(), DEF_NUM_BINS); hist6.compute(ushort_data); hist6.getCounts(actual_counts); if (!actual_counts.eq(expected_counts)) { actual_counts.debug(L"actual counts"); expected_counts.debug(L"expected counts"); return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__); } // test a histogram with a specified number of bins in CENTERS mode for // all data types // expected_counts.assign(L"2, 1, 1, 1, 1, 1, 1, 1, 1, 1"); hist6.clear(); hist6.setMode(CENTERS); hist6.compute(byte_data, DEF_NUM_BINS); hist6.getCounts(actual_counts); if (!actual_counts.eq(expected_counts)) { actual_counts.debug(L"actual counts"); expected_counts.debug(L"expected counts"); return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__); } hist6.clear(); hist6.setMode(CENTERS); hist6.compute(double_data, DEF_NUM_BINS); hist6.getCounts(actual_counts); if (!actual_counts.eq(expected_counts)) { actual_counts.debug(L"actual counts"); expected_counts.debug(L"expected counts"); return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__); } hist6.clear(); hist6.setMode(CENTERS); hist6.compute(float_data, DEF_NUM_BINS); hist6.getCounts(actual_counts); if (!actual_counts.eq(expected_counts)) { actual_counts.debug(L"actual counts"); expected_counts.debug(L"expected counts"); return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -