#include <boost/test/auto_unit_test.hpp>
#include "physical/exception.hpp"
#include "physical/fixedphysical.hpp"
#include "physical/dynamicunit.hpp"
#include "physical/quantity.hpp"
#include "physical/unit.hpp"
#include "physical/unitsymbol.hpp"
#include "physical/format.hpp"
#include "physical/parser.hpp"
#include "physical/dimension.hpp"
#include "physical/autoformat.hpp"
#include <iostream>
Include dependency graph for manual_test.cpp:
Go to the source code of this file.
Functions | |
void | try_to_parse (std::string formula) |
BOOST_AUTO_UNIT_TEST (manual_test) |
BOOST_AUTO_UNIT_TEST | ( | manual_test | ) |
Definition at line 50 of file manual_test.cpp.
References physical::unit_si_float::celsius(), physical::unit_si_float::fahrenheit(), physical::format::format(), physical::format::Dimension::get(), physical::unit_si_float::gram, physical::unit_si_float::hour, physical::unit_si_float::kelvin, physical::unit_si_float::kilometer, physical::unitsymbol_si_float::m, physical::unit_si_float::meter, physical::FixedPhysical< T, Exponents >::numerical_value, physical::unitsymbol_si_float::quantity, physical::unit_si_float::reaumur(), physical::unit_si_float::second, try_to_parse(), and physical::unitsymbol_si_float::unit.
00050 { 00051 00052 namespace quantity=physical::quantity_si_double; 00053 namespace unit=physical::unit_si_float; 00054 using physical::DynamicPhysical; 00055 using physical::DynamicUnit; 00056 using physical::format::format; 00057 using physical::format::FormatSpec; 00058 00059 std::cout << "Hello World!\n"; 00060 00061 std::cout << "numerical value of meter: " << unit::meter.numerical_value << "\n"; 00062 std::cout << "numerical value of kilometer: " << unit::kilometer.numerical_value << "\n"; 00063 00064 std::cout << "numerical value of hour: " << unit::hour.numerical_value << "\n"; 00065 00066 DynamicUnit<SI> d_hour(unit::hour); 00067 DynamicPhysical<SI> day= 24*unit::hour; 00068 00069 std::cout << "numerical value of day: " << day.numerical_value << "\n"; 00070 00071 double spd = (day / DynamicPhysical<SI>(unit::second) ).numerical_value; // FIXME automatic conversion should work again!!! 00072 std::cout << "number of seconds per day: " << spd << "\n"; 00073 00074 std::cout << "day = " << day << "\n"; 00075 00076 quantity::mass m = unit::gram; 00077 00078 // FormatSpecs can be stored and handles e.g. by standard containers: 00079 std::vector<FormatSpec<SI>> hourspecs; 00080 hourspecs.push_back(FormatSpec<SI>("h",unit::hour,2)); 00081 hourspecs.push_back(FormatSpec<SI>("hour(s)",unit::hour,2)); 00082 hourspecs.push_back(FormatSpec<SI>("Stunde(n)",unit::hour,2)); 00083 hourspecs.push_back(FormatSpec<SI>("heure(s)",unit::hour,2)); 00084 00085 00086 std::cout << "day = " << format(day, hourspecs[0]) << "\n"; 00087 std::cout << "day = " << format(day, hourspecs[1]) << "\n"; 00088 std::cout << "day = " << format(day, hourspecs[2]) << "\n"; 00089 std::cout << "day = " << format(day, hourspecs[3]) << "\n"; 00090 00091 // pre-created formatter object 00092 physical::format::formatter<SI> f(hourspecs[3]); 00093 std::cout << "day = " << f(day) << "\n"; 00094 00095 00096 physical::format::Dimension("units of time usually used by machines", unit::second); 00097 physical::format::Dimension human_clock 00098 = physical::format::DimensionDef<quantity::time>("units of time usually used by humans") 00099 .add(FormatSpec<SI>("hours", unit::hour, 2)) 00100 .add(FormatSpec<SI>("minutes", 60*unit::second, 0)) 00101 .add(FormatSpec<SI>("seconds", unit::second, 0)); 00102 00103 00104 std::cout << "day/dimension = " << format(day, human_clock.get(0)) << "\n"; 00105 std::cout << "day/dimension = " << format(human_clock.get(0))(day) << "\n"; 00106 00107 quantity::velocity velocity = 50*unit::kilometer/unit::hour; 00108 DynamicPhysical<SI> dvelocity = 50*unit::kilometer/unit::hour; 00109 00110 std::cout << "50kmh = " << DynamicPhysical<SI>(velocity) << "\n"; // FIXME automatic conversion should work again!!! 00111 std::cout << "50kmh = " << dvelocity << "\n"; 00112 00113 quantity::length side = 20*unit::meter; 00114 quantity::area square = side*side; 00115 std::cout << "area = " << DynamicPhysical<SI>(square) << "\n"; // FIXME automatic conversion should work again!!! 00116 00117 FormatSpec<SI> areaspec("m*m", unit::meter*unit::meter, 3); 00118 std::cout << "area = " << format(DynamicPhysical<SI>(square), areaspec) << "\n";// FIXME automatic conversion should work again!!! 00119 00120 00121 quantity::temperature temp= 18*unit::celsius; // implicit conversion DynamicPhysical->FixedPhysical 00122 DynamicPhysical<SI> temp2= 20*unit::celsius; 00123 00124 try { 00125 // this is an invalid conversion and should throw an exception: 00126 DynamicPhysical<SI> length = 200*unit::meter; 00127 quantity::temperature temp = length; 00128 } catch(const std::exception& e) { 00129 std::cout << "Could not convert length to temperature: " << e.what() << "\n"; 00130 } 00131 00132 std::cout << "celsius.factor " << unit::celsius.scale.factor << "\n"; 00133 std::cout << "celsius.origin " << unit::celsius.scale.origin << "\n"; 00134 00135 std::cout << "temp.numerical_value " << temp.numerical_value << "\n"; 00136 00137 std::cout << "temp.numerical_value " << temp.numerical_value << "\n"; 00138 00139 std::cout << "room temperature = " << format<SI>(temp, FormatSpec<SI>("K", unit::kelvin, 4)) << "\n"; 00140 std::cout << "room temperature = " << format<SI>(temp, FormatSpec<SI>("°C", unit::celsius, 4)) << "\n"; 00141 00142 quantity::temperature freezing_point = 0*unit::celsius; 00143 00144 std::cout << "freezing_point = " << format<SI>(freezing_point, FormatSpec<SI>("K", unit::kelvin, 4)) << "\n"; 00145 std::cout << "freezing_point = " << format<SI>(freezing_point, FormatSpec<SI>("°C", unit::celsius, 4)) << "\n"; 00146 std::cout << "freezing_point = " << format<SI>(freezing_point, FormatSpec<SI>("°F", unit::fahrenheit, 4)) << "\n"; 00147 std::cout << "freezing_point = " << format<SI>(freezing_point, FormatSpec<SI>("°R", unit::reaumur, 4)) << "\n"; 00148 00149 quantity::temperature boiling_point = 100*unit::celsius; 00150 00151 std::cout << "boiling_point = " << format<SI>(boiling_point, FormatSpec<SI>("K", unit::kelvin, 4)) << "\n"; 00152 std::cout << "boiling_point = " << format<SI>(boiling_point, FormatSpec<SI>("°C", unit::celsius, 4)) << "\n"; 00153 std::cout << "boiling_point = " << format<SI>(boiling_point, FormatSpec<SI>("°F", unit::fahrenheit, 4)) << "\n"; 00154 std::cout << "boiling_point = " << format<SI>(boiling_point, FormatSpec<SI>("°R", unit::reaumur, 4)) << "\n"; 00155 00156 // try the parser: 00157 try_to_parse("0.5"); 00158 try_to_parse("1.5[]"); 00159 try_to_parse("2.5[1]"); 00160 try_to_parse("3.5[123]"); 00161 try_to_parse("4.5[m]"); 00162 try_to_parse("5.5[kg]"); 00163 try_to_parse("6.5[kg^5]"); 00164 try_to_parse("7.5[m*A*s^-1*kg^5]"); 00165 try_to_parse("8.5[m]"); 00166 try_to_parse("9.5[m*A]"); 00167 try_to_parse("10.5[m*A*s^-1]"); 00168 try_to_parse("11.5[m*A*s^-1*kg^5]"); 00169 try_to_parse("12.5[m*s*grad]"); 00170 try_to_parse("13.5[m*s*Grad]"); 00171 try_to_parse("14.5[rad]"); 00172 try_to_parse("15.5[m/s]"); 00173 00174 };
void try_to_parse | ( | std::string | formula | ) |
Definition at line 36 of file manual_test.cpp.
References physical::parser::Parser::parse(), physical::parser::parser_exception::string_to_parse, and physical::parser::parser_exception::sucessfully_parsed_up_to.
Referenced by BOOST_AUTO_UNIT_TEST().
00036 { 00037 physical::parser::Parser p; 00038 00039 try { 00040 physical::DynamicPhysical<SI> q = p.parse(formula); 00041 std::cout << "parsing of " << formula << " succeeded: " << q <<"\n"; 00042 00043 } catch(const physical::parser::parser_exception& e) { 00044 std::cout << "parsing of " << formula << " failed after " << e.string_to_parse.substr(0, e.sucessfully_parsed_up_to) << "\n"; 00045 }; 00046 00047 };
Generated on Mon Apr 2 22:25:06 2007 for physical_svn by 1.5.1-p1 | hosted on |