%description: Test registed NED functions. For convenience we use cDynamicExpression, not NED directly. %global: void test(const char *expr) { cDynamicExpression e; e.parse(expr); std::string result; try { cNedValue v = e.evaluate(); result = v.str(); } catch (std::exception& e) { result = e.what(); } EV << expr << " ==> " << result << "\n"; } #define P(expr) test(#expr) %activity: P( W(150mW)); P( min(3, 2)); P( min(3m, 2m)); P( min(3m, 2km)); P( min(2km, 3m)); P( min(1m, 1)); P( min(1m, 1s)); EV << "\n"; P( max(3, 2)); P( max(3m, 2m)); P( max(3m, 2km)); P( max(2km, 3m)); P( max(1m, 1)); P( max(1m, 1s)); EV << "\n"; P( convertUnit(1.5h, "s")); P( convertUnit(1.5h, "")); P( convertUnit(1.5h, "kg")); EV << "\n"; P( replaceUnit(1.5h, "s")); P( replaceUnit(1.5h, "kg")); P( replaceUnit(1.5h, "")); EV << "\n"; P( dropUnit(1.5h)); P( dropUnit(1.5)); EV << "\n"; P( unitOf(1km)); P( unitOf(5 kilometers)); EV << "\n"; P( length("")); P( length("Hello")); EV << "\n"; P( contains("", "")); P( contains("", "bubu")); P( contains("Hello", "")); P( contains("Hello", "ell")); P( contains("Hello", "bubu")); EV << "\n"; P( substring("Hello", 0)); P( substring("Hello", 3)); P( substring("Hello", 5)); P( substring("Hello", -1)); P( substring("Hello", 6)); EV << "\n"; P( substring("Hello", 0, 2)); P( substring("Hello", 1, 3)); P( substring("Hello", 1, 0)); P( substring("Hello", 1, 10)); P( substring("Hello", 1, -1)); P( substring("Hello", -1, 3)); P( substring("Hello", -1, 10)); EV << "\n"; P( substringBefore("this and this and that", "and")); // note: two "and"'s P( substringBefore("this and this and that", "XXX")); P( substringAfter("this and this and that", "and")); P( substringAfter("this and this and that", "XXX")); EV << "\n"; P( substringBeforeLast("this and this and that", "and")); P( substringBeforeLast("this and this and that", "XXX")); P( substringAfterLast("this and this and that", "and")); P( substringAfterLast("this and this and that", "XXX")); EV << "\n"; P( startsWith("", "")); P( startsWith("Hello", "")); P( startsWith("Hello", "He")); P( startsWith("Hello", "ell")); EV << "\n"; P( endsWith("", "")); P( endsWith("Hello", "")); P( endsWith("Hello", "lo")); P( endsWith("Hello", "ell")); EV << "\n"; P( tail("Hello", 0)); P( tail("Hello", 2)); P( tail("Hello", 100)); EV << "\n"; P( replace("Hello", "ell", "******")); P( replace("Hello", "ell", "")); P( replace("Hello", "e", "x")); P( replace("Hello", "l", "x")); P( replace("Hello", "e", "e")); P( replace("Hello", "e", "")); P( replace("Hello", "", "x")); EV << "\n"; P( replaceFirst("Hello", "l", "(_)")); P( replaceFirst("Hello", "X", "(_)")); EV << "\n"; P( indexOf("", "")); P( indexOf("Hello", "")); P( indexOf("Hello", "ell")); P( indexOf("Hello", "bubu")); EV << "\n"; P( toUpper("Hello")); P( toLower("HeLLo")); EV << "\n"; P( trim(" \tfoo \n ")); P( trim("foo")); EV << "\n"; P( choose(0, "Zero One Two Three")); P( choose(2, "Zero One Two Three")); P( choose(3, "Zero One Two Three")); P( choose(-1, "Zero One Two Three")); P( choose(4, "Zero One Two Three")); EV << "\n"; P( int(true)); P( int(3.14)); P( int(-3.14)); P( int("6.28")); P( int("-6.28")); P( double(false)); P( double(7.54)); P( double(-7.54)); P( double("4.53")); P( double("-4.53")); P( string(false)); P( string(13)); P( string(4.72)); P( string(-4.72)); EV << "\n"; P( s(0.5)); P( ms(0.5s)); P( W(0.15)); P( W(150mW)); P( W(0dBm)); P( dBm(10W)); P( ratio(-10dB)); P( ratio(0dB)); EV << ".\n"; %contains: stdout min(3, 2) ==> 2 min(3m, 2m) ==> 2m min(3m, 2km) ==> 3m min(2km, 3m) ==> 3m min(1m, 1) ==> Cannot convert unit none to 'm' (meter) min(1m, 1s) ==> Cannot convert unit 's' (second) to 'm' (meter) max(3, 2) ==> 3 max(3m, 2m) ==> 3m max(3m, 2km) ==> 2km max(2km, 3m) ==> 2km max(1m, 1) ==> Cannot convert unit none to 'm' (meter) max(1m, 1s) ==> Cannot convert unit 's' (second) to 'm' (meter) convertUnit(1.5h, "s") ==> 5400s convertUnit(1.5h, "") ==> Cannot convert unit 'h' (hour) to none convertUnit(1.5h, "kg") ==> Cannot convert unit 'h' (hour) to 'kg' (kilogram) replaceUnit(1.5h, "s") ==> 1.5s replaceUnit(1.5h, "kg") ==> 1.5kg replaceUnit(1.5h, "") ==> 1.5 dropUnit(1.5h) ==> 1.5 dropUnit(1.5) ==> 1.5 unitOf(1km) ==> "km" unitOf(5 kilometers) ==> "kilometers" length("") ==> 0 length("Hello") ==> 5 contains("", "") ==> true contains("", "bubu") ==> false contains("Hello", "") ==> true contains("Hello", "ell") ==> true contains("Hello", "bubu") ==> false substring("Hello", 0) ==> "Hello" substring("Hello", 3) ==> "lo" substring("Hello", 5) ==> "" substring("Hello", -1) ==> substring(): Index out of bounds substring("Hello", 6) ==> substring(): Index out of bounds substring("Hello", 0, 2) ==> "He" substring("Hello", 1, 3) ==> "ell" substring("Hello", 1, 0) ==> "" substring("Hello", 1, 10) ==> "ello" substring("Hello", 1, -1) ==> substring(): Length is negative substring("Hello", -1, 3) ==> substring(): Index out of bounds substring("Hello", -1, 10) ==> substring(): Index out of bounds substringBefore("this and this and that", "and") ==> "this " substringBefore("this and this and that", "XXX") ==> "" substringAfter("this and this and that", "and") ==> " this and that" substringAfter("this and this and that", "XXX") ==> "" substringBeforeLast("this and this and that", "and") ==> "this and this " substringBeforeLast("this and this and that", "XXX") ==> "" substringAfterLast("this and this and that", "and") ==> " that" substringAfterLast("this and this and that", "XXX") ==> "" startsWith("", "") ==> true startsWith("Hello", "") ==> true startsWith("Hello", "He") ==> true startsWith("Hello", "ell") ==> false endsWith("", "") ==> true endsWith("Hello", "") ==> true endsWith("Hello", "lo") ==> true endsWith("Hello", "ell") ==> false tail("Hello", 0) ==> "" tail("Hello", 2) ==> "lo" tail("Hello", 100) ==> "Hello" replace("Hello", "ell", "******") ==> "H******o" replace("Hello", "ell", "") ==> "Ho" replace("Hello", "e", "x") ==> "Hxllo" replace("Hello", "l", "x") ==> "Hexxo" replace("Hello", "e", "e") ==> "Hello" replace("Hello", "e", "") ==> "Hllo" replace("Hello", "", "x") ==> "xHxexlxlxox" replaceFirst("Hello", "l", "(_)") ==> "He(_)lo" replaceFirst("Hello", "X", "(_)") ==> "Hello" indexOf("", "") ==> 0 indexOf("Hello", "") ==> 0 indexOf("Hello", "ell") ==> 1 indexOf("Hello", "bubu") ==> -1 toUpper("Hello") ==> "HELLO" toLower("HeLLo") ==> "hello" trim(" \tfoo \n ") ==> "foo" trim("foo") ==> "foo" choose(0, "Zero One Two Three") ==> "Zero" choose(2, "Zero One Two Three") ==> "Two" choose(3, "Zero One Two Three") ==> "Three" choose(-1, "Zero One Two Three") ==> choose(): Negative index choose(4, "Zero One Two Three") ==> choose(): Index out of bounds: 4 int(true) ==> 1 int(3.14) ==> 3 int(-3.14) ==> -4 int("6.28") ==> 6 int("-6.28") ==> -7 double(false) ==> 0 double(7.54) ==> 7.54 double(-7.54) ==> -7.54 double("4.53") ==> 4.53 double("-4.53") ==> -4.53 string(false) ==> "false" string(13) ==> "13" string(4.72) ==> "4.72" string(-4.72) ==> "-4.72" s(0.5) ==> 0.5s ms(0.5s) ==> 500ms W(0.15) ==> 0.15W W(150mW) ==> 0.15W W(0dBm) ==> 0.001W dBm(10W) ==> 40dBm ratio(-10dB) ==> 0.316228ratio ratio(0dB) ==> 1ratio .