/* Copyright (c) 2013 Daniel Stahlke Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ // Include this several times to test delayed loading of armadillo/blitz support. #include "gnuplot-iostream.h" #include #include #if GNUPLOT_ENABLE_CXX11 #include #include #endif #include #if USE_ARMA #include #endif #include "gnuplot-iostream.h" #if USE_BLITZ #include #endif #include "gnuplot-iostream.h" #include "gnuplot-iostream.h" using namespace gnuplotio; Gnuplot gp; const std::string basedir = "unittest-output"; template void test_given_mode( std::ostream &log_fh, std::string header, const T &arg, ArrayMode, boost::mpl::true_ ) { std::string modename = ArrayMode::class_name(); std::string fn_prefix = basedir+"/"+header+"-"+modename; log_fh << "* " << modename << " -> " << gp.binaryFile(arg, fn_prefix+".bin", "record", ArrayMode()) << std::endl; gp.file(arg, fn_prefix+".txt", ArrayMode()); } template void test_given_mode( std::ostream &log_fh, std::string header, const T &arg, ArrayMode, boost::mpl::false_ ) { std::string modename = ArrayMode::class_name(); std::string fn_prefix = basedir+"/"+header+"-"+modename; log_fh << "* " << modename << " (skipped binary) " << std::endl; gp.file(arg, fn_prefix+".txt", ArrayMode()); } template typename boost::enable_if_c<(ArrayTraits::depth == 1)>::type runtest_inner(std::ostream &log_fh, std::string header, const T &arg) { test_given_mode(log_fh, header, arg, Mode1D(), DoBinary()); } template typename boost::enable_if_c<(ArrayTraits::depth == 2)>::type runtest_inner(std::ostream &log_fh, std::string header, const T &arg) { test_given_mode(log_fh, header, arg, Mode2D(), DoBinary()); test_given_mode(log_fh, header, arg, Mode1DUnwrap(), DoBinary()); } template typename boost::enable_if_c<(ArrayTraits::depth >= 3)>::type runtest_inner(std::ostream &log_fh, std::string header, const T &arg) { test_given_mode(log_fh, header, arg, Mode2D(), DoBinary()); test_given_mode(log_fh, header, arg, Mode2DUnwrap(), DoBinary()); } template void runtest_maybe_dobin(std::string header, const T &arg) { std::ofstream log_fh((basedir+"/"+header+"-log.txt").c_str()); log_fh << "--- " << header << " -------------------------------------" << std::endl; log_fh << "depth=" << ArrayTraits::depth << std::endl; log_fh << "ModeAutoDecoder=" << ModeAutoDecoder::mode::class_name() << std::endl; runtest_inner(log_fh, header, arg); } template void runtest(std::string header, const T &arg) { runtest_maybe_dobin(header, arg); } template void runtest_nobin(std::string header, const T &arg) { runtest_maybe_dobin(header, arg); } template void basic_datatype_test_integral(std::string name) { std::vector v; for(int i=0; i<4; i++) { v.push_back(i); } runtest_maybe_dobin, DoBinary>(name, v); } template void basic_datatype_test_float(std::string name) { std::vector v; for(int i=0; i<4; i++) { v.push_back(i + T(0.1234)); } v.push_back(std::numeric_limits::quiet_NaN()); runtest_maybe_dobin, DoBinary>(name, v); } int main() { const int NX=3, NY=4, NZ=2; std::vector vd; std::vector vi; std::vector vf; std::vector > vvd(NX); std::vector > vvi(NX); std::vector > > vvvi(NX); std::vector > > > vvvp(NX); int ai[NX]; boost::array bi; std::vector > v_bt; #if GNUPLOT_ENABLE_CXX11 std::array si; std::vector< std::tuple > v_st; #endif for(int x=0; x tup; tup.push_back(300+x*10+y); tup.push_back(400+x*10+y); vvvi[x].push_back(tup); std::vector > stuff; for(int z=0; z("vi8"); basic_datatype_test_integral("vu8"); basic_datatype_test_integral("vi16"); basic_datatype_test_integral("vu16"); basic_datatype_test_integral("vi32"); basic_datatype_test_integral("vu32"); // these should all print as integers basic_datatype_test_integral("vpc"); basic_datatype_test_integral("vsc"); basic_datatype_test_integral("vuc"); basic_datatype_test_float("vf"); basic_datatype_test_float("vd"); basic_datatype_test_float("vld"); runtest("vd,vi,bi", std::make_pair(vd, std::make_pair(vi, bi))); runtest("vvd", vvd); runtest("vvd,vvi", std::make_pair(vvd, vvi)); runtest("ai", ai); runtest("bi", bi); #if GNUPLOT_ENABLE_CXX11 runtest("si", si); runtest("tie{si,bi}", boost::tie(si, bi)); runtest("pair{&si,&bi}", std::pair&, boost::array&>(si, bi)); #endif // Doesn't work because array gets cast to pointer //runtest("pair{ai,bi}", std::make_pair(ai, bi)); // However, these work: runtest("boost_tie{ai,bi}", boost::tie(ai, bi)); #if GNUPLOT_ENABLE_CXX11 runtest("std_tie{ai,bi}", std::tie(ai, bi)); runtest("std_fwd{ai,bi}", std::forward_as_tuple(ai, bi)); #endif runtest("pair{ai,bi}", std::pair >(ai, bi)); runtest("vvd,vvi,vvvi", std::make_pair(vvd, std::make_pair(vvi, vvvi))); runtest("vvvp", vvvp); #if USE_ARMA arma::vec armacol(NX); arma::mat armamat(NX, NY); for(int x=0; x blitz1d(NX); blitz::Array blitz2d(NX, NY); { blitz::firstIndex i; blitz::secondIndex j; blitz1d = i + 0.777; blitz2d = 100 + i*10 + j; } blitz::Array, 2> blitz2d_tup(NX, NY); for(int x=0; x