From 12520715afc431497ad0262a2ad0cfe82003aea8 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Thu, 2 Jan 2014 01:21:40 -0500 Subject: [PATCH] Unit Tests - Merged libexpr Variant tests. - Updated .gitignore. --- test/.gitignore | 20 +++ test/CMakeLists.txt | 9 +- test/variant_add.t.cpp | 242 +++++++++++++++++++++++++++++ test/variant_and.t.cpp | 204 ++++++++++++++++++++++++ test/variant_cast.t.cpp | 257 +++++++++++++++++++++++++++++++ test/variant_divide.t.cpp | 204 ++++++++++++++++++++++++ test/variant_equal.t.cpp | 196 +++++++++++++++++++++++ test/variant_exp.t.cpp | 198 ++++++++++++++++++++++++ test/variant_gt.t.cpp | 194 +++++++++++++++++++++++ test/variant_gte.t.cpp | 194 +++++++++++++++++++++++ test/variant_inequal.t.cpp | 196 +++++++++++++++++++++++ test/variant_lt.t.cpp | 196 +++++++++++++++++++++++ test/variant_lte.t.cpp | 196 +++++++++++++++++++++++ test/variant_match.t.cpp | 299 ++++++++++++++++++++++++++++++++++++ test/variant_math.t.cpp | 49 ++++++ test/variant_modulo.t.cpp | 200 ++++++++++++++++++++++++ test/variant_multiply.t.cpp | 215 ++++++++++++++++++++++++++ test/variant_nomatch.t.cpp | 299 ++++++++++++++++++++++++++++++++++++ test/variant_not.t.cpp | 82 ++++++++++ test/variant_or.t.cpp | 204 ++++++++++++++++++++++++ test/variant_subtract.t.cpp | 177 +++++++++++++++++++++ test/variant_xor.t.cpp | 204 ++++++++++++++++++++++++ 22 files changed, 4034 insertions(+), 1 deletion(-) create mode 100644 test/variant_add.t.cpp create mode 100644 test/variant_and.t.cpp create mode 100644 test/variant_cast.t.cpp create mode 100644 test/variant_divide.t.cpp create mode 100644 test/variant_equal.t.cpp create mode 100644 test/variant_exp.t.cpp create mode 100644 test/variant_gt.t.cpp create mode 100644 test/variant_gte.t.cpp create mode 100644 test/variant_inequal.t.cpp create mode 100644 test/variant_lt.t.cpp create mode 100644 test/variant_lte.t.cpp create mode 100644 test/variant_match.t.cpp create mode 100644 test/variant_math.t.cpp create mode 100644 test/variant_modulo.t.cpp create mode 100644 test/variant_multiply.t.cpp create mode 100644 test/variant_nomatch.t.cpp create mode 100644 test/variant_not.t.cpp create mode 100644 test/variant_or.t.cpp create mode 100644 test/variant_subtract.t.cpp create mode 100644 test/variant_xor.t.cpp diff --git a/test/.gitignore b/test/.gitignore index 7fb32d3f1..09f9d612a 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -30,6 +30,26 @@ tree.t uri.t utf8.t util.t +variant_add.t +variant_and.t +variant_cast.t +variant_divide.t +variant_equal.t +variant_exp.t +variant_gt.t +variant_gte.t +variant_inequal.t +variant_lt.t +variant_lte.t +variant_match.t +variant_math.t +variant_modulo.t +variant_multiply.t +variant_nomatch.t +variant_not.t +variant_or.t +variant_subtract.t +variant_xor.t view.t width.t diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4ffe966b3..cb83294ef 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -9,7 +9,14 @@ include_directories (${CMAKE_SOURCE_DIR} set (test_SRCS autocomplete.t color.t config.t date.t directory.t dom.t old_duration.t file.t i18n.t json.t list.t msg.t nibbler.t path.t rx.t t.t t2.t taskmod.t tdb2.t text.t tree.t uri.t utf8.t util.t - view.t width.t json_test iso8601d.t iso8601p.t duration.t lexer.t) + view.t width.t json_test iso8601d.t iso8601p.t duration.t lexer.t + variant_add.t variant_and.t variant_cast.t variant_divide.t + variant_equal.t variant_exp.t variant_gt.t variant_gte.t + variant_inequal.t variant_lt.t variant_lte.t variant_match.t + variant_math.t variant_modulo.t variant_multiply.t + variant_nomatch.t variant_not.t variant_or.t variant_subtract.t + variant_xor.t) + message ("-- Configuring run_all") if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) diff --git a/test/variant_add.t.cpp b/test/variant_add.t.cpp new file mode 100644 index 000000000..5821dc384 --- /dev/null +++ b/test/variant_add.t.cpp @@ -0,0 +1,242 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2013 - 2014, Göteborg Bit Factory. +// +// 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. +// +// http://www.opensource.org/licenses/mit-license.php +// +//////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include +#include + +Context context; + +#define EPSILON 0.001 + +//////////////////////////////////////////////////////////////////////////////// +int main (int argc, char** argv) +{ + UnitTest t (80); + + Variant v0 (true); + Variant v1 (42); + Variant v2 (3.14); + Variant v3 ("foo"); + Variant v4 (1234567890, Variant::type_date); + Variant v5 (1200, Variant::type_duration); + + // boolean + boolean -> ERROR + try {Variant v00 = v0 + v0; t.fail ("true + true --> error");} + catch (...) {t.pass ("true + true --> error");} + + // boolean + integer -> integer + Variant v01 = v0 + v1; + t.is (v01.type (), Variant::type_integer, "true + 42 --> integer"); + t.is (v01.get_integer (), 43, "true + 42 --> 43"); + + // boolean + real -> real + Variant v02 = v0 + v2; + t.is (v02.type (), Variant::type_real, "true + 3.14 --> real"); + t.is (v02.get_real (), 4.14, EPSILON, "true + 3.14 --> 4.14"); + + // boolean + string -> string + Variant v03 = v0 + v3; + t.is (v03.type (), Variant::type_string, "true + foo --> string"); + t.is (v03.get_string (), "truefoo", "true + foo --> truefoo"); + + // boolean + date -> date + Variant v04 = v0 + v4; + t.is (v04.type (), Variant::type_date, "true + 1234567890 --> date"); + t.is (v04.get_date (), "1234567891", "true + 1234567890 --> 1234567891"); + + // boolean + duration -> duration + Variant v05 = v0 + v5; + t.is (v05.type (), Variant::type_duration, "true + 1200 --> duration"); + t.is (v05.get_duration (), "1201", "true + 1200 --> 1201"); + + // integer + boolean -> integer + Variant v10 = v1 + v0; + t.is (v10.type (), Variant::type_integer, "42 + true --> integer"); + t.is (v10.get_integer (), 43, "42 + true --> 43"); + + // integer + integer -> integer + Variant v11 = v1 + v1; + t.is (v11.type (), Variant::type_integer, "42 + 42 --> integer"); + t.is (v11.get_integer (), 84, "42 + 42 --> 84"); + + // integer + real -> real + Variant v12 = v1 + v2; + t.is (v12.type (), Variant::type_real, "42 + 3.14 --> real"); + t.is (v12.get_real (), 45.14, EPSILON, "42 + 3.14 --> 45.14"); + + // integer + string -> string + Variant v13 = v1 + v3; + t.is (v13.type (), Variant::type_string, "42 + foo --> string"); + t.is (v13.get_string (), "42foo", "42 + foo --> 42foo"); + + // integer + date -> date + Variant v14 = v1 + v4; + t.is (v14.type (), Variant::type_date, "42 + 1234567890 --> date"); + t.is (v14.get_date (), 1234567932, "42 + 1234567890 --> 1234567932"); + + // integer + duration -> duration + Variant v15 = v1 + v5; + t.is (v15.type (), Variant::type_duration, "42 + 1200 --> duration"); + t.is (v15.get_duration (), 1242, "42 + 1200 --> 1242"); + + // real + boolean -> real + Variant v20 = v2 + v0; + t.is (v20.type (), Variant::type_real, "3.14 + true --> real"); + t.is (v20.get_real (), 4.14, EPSILON, "3.14 + true --> 4.14"); + + // real + integer -> real + Variant v21 = v2 + v1; + t.is (v21.type (), Variant::type_real, "3.14 + 42 --> real"); + t.is (v21.get_real (), 45.14, EPSILON, "3.14 + 42 --> 45.14"); + + // real + real -> real + Variant v22 = v2 + v2; + t.is (v22.type (), Variant::type_real, "3.14 + 3.14 --> real"); + t.is (v22.get_real (), 6.28, EPSILON, "3.14 + 3.14 --> 6.28"); + + // real + string -> string + Variant v23 = v2 + v3; + t.is (v23.type (), Variant::type_string, "3.14 + foo --> string"); + t.is (v23.get_string (), "3.14foo", "3.14 + foo --> 3.14foo"); + + // real + date -> date + Variant v24 = v2 + v4; + t.is (v24.type (), Variant::type_date, "3.14 + 1234567890 --> date"); + t.is (v24.get_date (), 1234567893, "3.14 + 1234567890 --> 1234567893"); + + // real + duration -> duration + Variant v25 = v2 + v5; + t.is (v25.type (), Variant::type_duration, "3.14 + 1200 --> duration"); + t.is (v25.get_duration (), 1203, "3.14 + 1200 --> 1203"); + + // string + boolean -> string + Variant v30 = v3 + v0; + t.is (v30.type (), Variant::type_string, "foo + true --> string"); + t.is (v30.get_string (), "footrue", "foo + true --> footrue"); + + // string + integer -> string + Variant v31 = v3 + v1; + t.is (v31.type (), Variant::type_string, "foo + 42 --> string"); + t.is (v31.get_string (), "foo42", "foo + 42 --> foo42"); + + // string + real -> string + Variant v32 = v3 + v2; + t.is (v32.type (), Variant::type_string, "foo + 3.14 --> string"); + t.is (v32.get_string (), "foo3.14", "foo + 3.14 --> foo3.14"); + + // string + string -> string + Variant v33 = v3 + v3; + t.is (v33.type (), Variant::type_string, "foo + foo --> string"); + t.is (v33.get_string (), "foofoo", "foo + foo --> foofoo"); + + // string + date -> string + Variant v34 = v3 + v4; + t.is (v34.type (), Variant::type_string, "foo + 1234567890 --> string"); + std::string s = v34.get_string (); + t.is ((int)s[7], (int)'-', "foo + 1234567890 --> fooYYYY-MM-DDThh:mm:ss"); + t.is ((int)s[10], (int)'-', "foo + 1234567890 --> fooYYYY-MM-DDThh:mm:ss"); + t.is ((int)s[13], (int)'T', "foo + 1234567890 --> fooYYYY-MM-DDThh:mm:ss"); + t.is ((int)s[16], (int)':', "foo + 1234567890 --> fooYYYY-MM-DDThh:mm:ss"); + t.is ((int)s[19], (int)':', "foo + 1234567890 --> fooYYYY-MM-DDThh:mm:ss"); + t.is ((int)s.length (), 22, "foo + 1234567890 --> fooYYYY-MM-DDThh:mm:ss"); + + // string + duration -> string + Variant v35 = v3 + v5; + t.is (v35.type (), Variant::type_string, "foo + 1200 --> string"); + t.is (v35.get_string (), "fooPT20M", "foo + 1200 --> fooPT20M"); + + // date + boolean -> date + Variant v40 = v4 + v0; + t.is (v40.type (), Variant::type_date, "1234567890 + true --> date"); + t.is (v40.get_date (), 1234567891, "1234567890 + true --> 1234567891"); + + // date + integer -> date + Variant v41 = v4 + v1; + t.is (v41.type (), Variant::type_date, "1234567890 + 42 --> date"); + t.is (v41.get_date (), 1234567932, "1234567890 + 42 --> 1234567932"); + + // date + real -> date + Variant v42 = v4 + v2; + t.is (v42.type (), Variant::type_date, "1234567890 + 3.14 --> date"); + t.is (v42.get_date (), 1234567893, "1234567890 + 3.14 --> 1234567893"); + + // date + string -> string + Variant v43 = v4 + v3; + t.is (v43.type (), Variant::type_string, "1234567890 + foo --> string"); + s = v43.get_string (); + t.is ((int)s[4], (int)'-', "1234567890 + foo --> YYYY-MM-DDThh:mm:ssfoo"); + t.is ((int)s[7], (int)'-', "1234567890 + foo --> YYYY-MM-DDThh:mm:ssfoo"); + t.is ((int)s[10], (int)'T', "1234567890 + foo --> YYYY-MM-DDThh:mm:ssfoo"); + t.is ((int)s[13], (int)':', "1234567890 + foo --> YYYY-MM-DDThh:mm:ssfoo"); + t.is ((int)s[16], (int)':', "1234567890 + foo --> YYYY-MM-DDThh:mm:ssfoo"); + t.is ((int)s.length (), 22, "1234567890 + foo --> YYYY-MM-DDThh:mm:ssfoo"); + + // date + date -> ERROR + try {Variant v44 = v4 + v4; t.fail ("1234567890 + 1234567890 --> error");} + catch (...) {t.pass ("1234567890 + 1234567890 --> error");} + + // date + duration -> date + Variant v45 = v4 + v5; + t.is (v45.type (), Variant::type_date, "1234567890 + 1200 --> date"); + t.is (v45.get_date (), 1234569090, "1234567890 + 1200 --> 1234569090"); + + // duration + boolean -> duration + Variant v50 = v5 + v0; + t.is (v50.type (), Variant::type_duration, "1200 + true --> duration"); + t.is (v50.get_duration (), 1201, "1200 + true --> 1201"); + + // duration + integer -> duration + Variant v51 = v5 + v1; + t.is (v51.type (), Variant::type_duration, "1200 + 42 --> duration"); + t.is (v51.get_duration (), 1242, "1200 + 42 --> 1242"); + + // duration + real -> duration + Variant v52 = v5 + v2; + t.is (v52.type (), Variant::type_duration, "1200 + 3.14 --> duration"); + t.is (v52.get_duration (), 1203, "1200 + 3.14 --> 1203"); + + // duration + string -> string + Variant v53 = v5 + v3; + t.is (v53.type (), Variant::type_string, "1200 + foo --> string"); + t.is (v53.get_string (), "PT20Mfoo", "1200 + foo --> PT20Mfoo"); + + // duration + date -> date + Variant v54 = v5 + v4; + t.is (v54.type (), Variant::type_date, "1200 + 1234567890 --> date"); + t.is (v54.get_date (), 1234569090, "1200 + 1234567890 --> 1234569090"); + + // duration + duration -> duration + Variant v55 = v5 + v5; + t.is (v55.type (), Variant::type_duration, "1200 + 1200 --> duration"); + t.is (v55.get_duration (), 2400, "1200 + 1200 --> 2400"); + + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/test/variant_and.t.cpp b/test/variant_and.t.cpp new file mode 100644 index 000000000..444eab760 --- /dev/null +++ b/test/variant_and.t.cpp @@ -0,0 +1,204 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2013 - 2014, Göteborg Bit Factory. +// +// 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. +// +// http://www.opensource.org/licenses/mit-license.php +// +//////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include +#include + +Context context; + +#define EPSILON 0.001 + +//////////////////////////////////////////////////////////////////////////////// +int main (int argc, char** argv) +{ + UnitTest t (76); + + Variant v0 (true); + Variant v1 (42); + Variant v2 (3.14); + Variant v3 ("foo"); + Variant v4 (1234567890, Variant::type_date); + Variant v5 (1200, Variant::type_duration); + + // Truth table. + Variant vFalse (false); + Variant vTrue (true); + t.is (vFalse && vFalse, false, "false && false --> false"); + t.is (vFalse && vTrue, false, "false && true --> false"); + t.is (vTrue && vFalse, false, "true && false --> false"); + t.is (vTrue && vTrue, true, "true && true --> true"); + + Variant v00 = v0 && v0; + t.is (v00.type (), Variant::type_boolean, "true && true --> boolean"); + t.is (v00.get_bool (), true, "true && true --> true"); + + Variant v01 = v0 && v1; + t.is (v01.type (), Variant::type_boolean, "true && 42 --> boolean"); + t.is (v01.get_bool (), true, "true && 42 --> true"); + + Variant v02 = v0 && v2; + t.is (v02.type (), Variant::type_boolean, "true && 3.14 --> boolean"); + t.is (v02.get_bool (), true, "true && 3.14 --> true"); + + Variant v03 = v0 && v3; + t.is (v03.type (), Variant::type_boolean, "true && 'foo' --> boolean"); + t.is (v03.get_bool (), true, "true && 'foo' --> true"); + + Variant v04 = v0 && v4; + t.is (v04.type (), Variant::type_boolean, "true && 1234567890 --> boolean"); + t.is (v04.get_bool (), true, "true && 1234567890 --> true"); + + Variant v05 = v0 && v5; + t.is (v05.type (), Variant::type_boolean, "true && 1200 --> boolean"); + t.is (v05.get_bool (), true, "true && 1200 --> true"); + + Variant v10 = v1 && v0; + t.is (v10.type (), Variant::type_boolean, "42 && true --> boolean"); + t.is (v10.get_bool (), true, "42 && true --> true"); + + Variant v11 = v1 && v1; + t.is (v11.type (), Variant::type_boolean, "42 && 42 --> boolean"); + t.is (v11.get_bool (), true, "42 && 42 --> true"); + + Variant v12 = v1 && v2; + t.is (v12.type (), Variant::type_boolean, "42 && 3.14 --> boolean"); + t.is (v12.get_bool (), true, "42 && 3.14 --> true"); + + Variant v13 = v1 && v3; + t.is (v13.type (), Variant::type_boolean, "42 && 'foo' --> boolean"); + t.is (v13.get_bool (), true, "42 && 'foo' --> true"); + + Variant v14 = v1 && v4; + t.is (v04.type (), Variant::type_boolean, "42 && 1234567890 --> boolean"); + t.is (v04.get_bool (), true, "42 && 1234567890 --> true"); + + Variant v15 = v1 && v5; + t.is (v15.type (), Variant::type_boolean, "42 && 1200 --> boolean"); + t.is (v15.get_bool (), true, "42 && 1200 --> true"); + + Variant v20 = v2 && v0; + t.is (v20.type (), Variant::type_boolean, "3.14 && true --> boolean"); + t.is (v20.get_bool (), true, "3.14 && true --> true"); + + Variant v21 = v2 && v1; + t.is (v21.type (), Variant::type_boolean, "3.14 && 42 --> boolean"); + t.is (v21.get_bool (), true, "3.14 && 42 --> true"); + + Variant v22 = v2 && v2; + t.is (v22.type (), Variant::type_boolean, "3.14 && 3.14 --> boolean"); + t.is (v22.get_bool (), true, "3.14 && 3.14 --> true"); + + Variant v23 = v2 && v3; + t.is (v23.type (), Variant::type_boolean, "3.14 && 'foo' --> boolean"); + t.is (v23.get_bool (), true, "3.14 && 'foo' --> true"); + + Variant v24 = v2 && v4; + t.is (v24.type (), Variant::type_boolean, "3.14 && 1234567890 --> boolean"); + t.is (v24.get_bool (), true, "3.14 && 1234567890 --> true"); + + Variant v25 = v2 && v5; + t.is (v25.type (), Variant::type_boolean, "3.14 && 1200 --> boolean"); + t.is (v25.get_bool (), true, "3.14 && 1200 --> true"); + + Variant v30 = v3 && v0; + t.is (v30.type (), Variant::type_boolean, "'foo' && true --> boolean"); + t.is (v30.get_bool (), true, "'foo' && true --> true"); + + Variant v31 = v3 && v1; + t.is (v31.type (), Variant::type_boolean, "'foo' && 42 --> boolean"); + t.is (v31.get_bool (), true, "'foo' && 42 --> true"); + + Variant v32 = v3 && v2; + t.is (v32.type (), Variant::type_boolean, "'foo' && 3.14 --> boolean"); + t.is (v32.get_bool (), true, "'foo' && 3.14 --> true"); + + Variant v33 = v3 && v3; + t.is (v33.type (), Variant::type_boolean, "'foo' && 'foo' --> boolean"); + t.is (v33.get_bool (), true, "'foo' && 'foo' --> true"); + + Variant v34 = v3 && v4; + t.is (v34.type (), Variant::type_boolean, "'foo' && 1234567890 --> boolean"); + t.is (v34.get_bool (), true, "'foo' && 1234567890 --> true"); + + Variant v35 = v3 && v5; + t.is (v35.type (), Variant::type_boolean, "'foo' && 1200 --> boolean"); + t.is (v35.get_bool (), true, "'foo' && 1200 --> true"); + + Variant v40 = v4 && v0; + t.is (v40.type (), Variant::type_boolean, "1234567890 && true --> boolean"); + t.is (v40.get_bool (), true, "1234567890 && true --> true"); + + Variant v41 = v4 && v1; + t.is (v41.type (), Variant::type_boolean, "1234567890 && 42 --> boolean"); + t.is (v41.get_bool (), true, "1234567890 && 42 --> true"); + + Variant v42 = v4 && v2; + t.is (v42.type (), Variant::type_boolean, "1234567890 && 3.14 --> boolean"); + t.is (v42.get_bool (), true, "1234567890 && 3.14 --> true"); + + Variant v43 = v4 && v3; + t.is (v43.type (), Variant::type_boolean, "1234567890 && 'foo' --> boolean"); + t.is (v43.get_bool (), true, "1234567890 && 'foo' --> true"); + + Variant v44 = v4 && v4; + t.is (v44.type (), Variant::type_boolean, "1234567890 && 1234567890 --> boolean"); + t.is (v44.get_bool (), true, "1234567890 && 1234567890 --> true"); + + Variant v45 = v4 && v5; + t.is (v45.type (), Variant::type_boolean, "1234567890 && 1200 --> boolean"); + t.is (v45.get_bool (), true, "1234567890 && 1200 --> true"); + + Variant v50 = v5 && v0; + t.is (v50.type (), Variant::type_boolean, "1200 && true --> boolean"); + t.is (v50.get_bool (), true, "1200 && true --> true"); + + Variant v51 = v5 && v1; + t.is (v51.type (), Variant::type_boolean, "1200 && 42 --> boolean"); + t.is (v51.get_bool (), true, "1200 && 42 --> true"); + + Variant v52 = v5 && v2; + t.is (v52.type (), Variant::type_boolean, "1200 && 3.14 --> boolean"); + t.is (v52.get_bool (), true, "1200 && 3.14 --> true"); + + Variant v53 = v5 && v3; + t.is (v53.type (), Variant::type_boolean, "1200 && 'foo' --> boolean"); + t.is (v53.get_bool (), true, "1200 && 'foo' --> true"); + + Variant v54 = v5 && v4; + t.is (v04.type (), Variant::type_boolean, "1200 && 1234567890 --> boolean"); + t.is (v04.get_bool (), true, "1200 && 1234567890 --> true"); + + Variant v55 = v5 && v5; + t.is (v55.type (), Variant::type_boolean, "1200 && 1200 --> boolean"); + t.is (v55.get_bool (), true, "1200 && 1200 --> true"); + + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/test/variant_cast.t.cpp b/test/variant_cast.t.cpp new file mode 100644 index 000000000..0a1860941 --- /dev/null +++ b/test/variant_cast.t.cpp @@ -0,0 +1,257 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2013 - 2014, Göteborg Bit Factory. +// +// 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. +// +// http://www.opensource.org/licenses/mit-license.php +// +//////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include +#include + +Context context; + +#define EPSILON 0.001 + +//////////////////////////////////////////////////////////////////////////////// +int main (int argc, char** argv) +{ + UnitTest t (81); + + try + { + // Variant::type_boolean --> * + Variant v00 (true); + v00.cast (Variant::type_boolean); + t.ok (v00.type () == Variant::type_boolean, "cast boolean --> boolean"); + t.ok (v00.get_bool () == true, "cast boolean --> boolean"); + + Variant v01 (true); + v01.cast (Variant::type_integer); + t.ok (v01.type () == Variant::type_integer, "cast boolean --> integer"); + t.ok (v01.get_integer () == 1, "cast boolean --> integer"); + + Variant v02 (true); + v02.cast (Variant::type_real); + t.ok (v02.type () == Variant::type_real, "cast boolean --> real"); + t.is (v02.get_real (), 1.0, EPSILON, "cast boolean --> real"); + + Variant v03 (true); + v03.cast (Variant::type_string); + t.ok (v03.type () == Variant::type_string, "cast boolean --> string"); + t.ok (v03.get_string () == "true", "cast boolean --> string"); + + Variant v04 (true); + v04.cast (Variant::type_date); + t.ok (v04.type () == Variant::type_date, "cast boolean --> date"); + t.is (v04.get_date (), 1, "cast boolean --> date"); + + Variant v05 (true); + v05.cast (Variant::type_duration); + t.ok (v05.type () == Variant::type_duration, "cast boolean --> duration"); + t.is (v05.get_duration (), 1, "cast boolean --> duration"); + + // Variant::type_integer --> * + Variant v10 (42); + v10.cast (Variant::type_boolean); + t.ok (v10.type () == Variant::type_boolean, "cast integer --> boolean"); + t.ok (v10.get_bool () == true, "cast integer --> boolean"); + + Variant v11 (42); + v11.cast (Variant::type_integer); + t.ok (v11.type () == Variant::type_integer, "cast integer --> integer"); + t.ok (v11.get_integer () == 42, "cast integer --> integer"); + + Variant v12 (42); + v12.cast (Variant::type_real); + t.ok (v12.type () == Variant::type_real, "cast integer --> real"); + t.is (v12.get_real (), 42.0, EPSILON, "cast integer --> real"); + + Variant v13 (42); + v13.cast (Variant::type_string); + t.is (v13.type (), Variant::type_string, "cast integer --> string"); + t.is (v13.get_string (), "42", "cast integer --> string"); + + Variant v14 (42); + v14.cast (Variant::type_date); + t.ok (v14.type () == Variant::type_date, "cast integer --> date"); + t.ok (v14.get_date () == 42, "cast integer --> date"); + + Variant v15 (42); + v15.cast (Variant::type_duration); + t.is (v15.type (), Variant::type_duration, "cast integer --> duration"); + t.is (v15.get_duration (), 42, "cast integer --> duration"); + + // Variant::type_real --> * + Variant v20 (3.14); + v20.cast (Variant::type_boolean); + t.ok (v20.type () == Variant::type_boolean, "cast real --> boolean"); + t.ok (v20.get_bool () == true, "cast real --> boolean"); + + Variant v21 (3.14); + v21.cast (Variant::type_integer); + t.ok (v21.type () == Variant::type_integer, "cast real --> integer"); + t.ok (v21.get_integer () == 3, "cast real --> integer"); + + Variant v22 (3.14); + v22.cast (Variant::type_real); + t.ok (v22.type () == Variant::type_real, "cast real --> real"); + t.is (v22.get_real (), 3.14, EPSILON, "cast real --> real"); + + Variant v23 (3.14); + v23.cast (Variant::type_string); + t.ok (v23.type () == Variant::type_string, "cast real --> string"); + t.ok (v23.get_string () == "3.14", "cast real --> string"); + + Variant v24 (3.14); + v24.cast (Variant::type_date); + t.ok (v24.type () == Variant::type_date, "cast real --> date"); + t.ok (v24.get_date () == 3, "cast real --> date"); + + Variant v25 (3.14); + v25.cast (Variant::type_duration); + t.ok (v25.type () == Variant::type_duration, "cast real --> duration"); + t.ok (v25.get_duration () == 3, "cast real --> duration"); + + // Variant::type_string --> * + Variant v30 ("foo"); + v30.cast (Variant::type_boolean); + t.ok (v30.type () == Variant::type_boolean, "cast string --> boolean"); + t.ok (v30.get_bool () == true, "cast string --> boolean"); + + Variant v31 ("42"); + v31.cast (Variant::type_integer); + t.ok (v31.type () == Variant::type_integer, "cast string --> integer"); + t.ok (v31.get_integer () == 42, "cast string --> integer"); + + Variant v31h ("0x20"); + v31h.cast (Variant::type_integer); + t.ok (v31h.type () == Variant::type_integer, "cast string(hex) --> integer"); + t.ok (v31h.get_integer () == 32, "cast string(hex) --> integer"); + + Variant v32 ("3.14"); + v32.cast (Variant::type_real); + t.ok (v32.type () == Variant::type_real, "cast string --> real"); + t.is (v32.get_real (), 3.14, EPSILON, "cast string --> real"); + + Variant v33 ("foo"); + v33.cast (Variant::type_string); + t.ok (v33.type () == Variant::type_string, "cast string --> string"); + t.ok (v33.get_string () == "foo", "cast string --> string"); + + Variant v34 ("2013-12-07T16:33:00-05:00"); + v34.cast (Variant::type_date); + t.ok (v34.type () == Variant::type_date, "cast string --> date"); + t.ok (v34.get_date () == 1386451980, "cast string --> date"); + + Variant v35 ("42 days"); + v35.cast (Variant::type_duration); + t.ok (v35.type () == Variant::type_duration, "cast string --> duration"); + t.is (v35.get_duration (), 3628800, "cast string --> duration"); + + Variant v35b ("P42D"); + v35b.cast (Variant::type_duration); + t.ok (v35b.type () == Variant::type_duration, "cast string --> duration"); + t.is (v35b.get_duration (), 3628800, "cast string --> duration"); + + // Variant::type_date --> * + Variant v40 ((time_t) 1234567890); + v40.cast (Variant::type_boolean); + t.ok (v40.type () == Variant::type_boolean, "cast date --> boolean"); + t.ok (v40.get_bool () == true, "cast date --> boolean"); + + Variant v41 ((time_t) 1234567890); + v41.cast (Variant::type_integer); + t.ok (v41.type () == Variant::type_integer, "cast date --> integer"); + t.ok (v41.get_integer () == 1234567890, "cast date --> integer"); + + Variant v42 ((time_t) 1234567890); + v42.cast (Variant::type_real); + t.ok (v42.type () == Variant::type_real, "cast date --> real"); + t.is (v42.get_real (), 1234567890.0, EPSILON, "cast date --> real"); + + // YYYY-MM-DDThh:mm:ss + // ^ ^ ^ ^ ^ + Variant v43 ((time_t) 1234567890); + v43.cast (Variant::type_string); + t.ok (v43.type () == Variant::type_string, "cast date --> string"); + std::string s = v43.get_string (); + t.is ((int)s[4], (int)'-', "cast date --> string"); + t.is ((int)s[7], (int)'-', "cast date --> string"); + t.is ((int)s[10], (int)'T', "cast date --> string"); + t.is ((int)s[13], (int)':', "cast date --> string"); + t.is ((int)s[16], (int)':', "cast date --> string"); + t.is ((int)s.length (), 19, "cast date --> string"); + + Variant v44 ((time_t) 1234567890); + v44.cast (Variant::type_date); + t.ok (v44.type () == Variant::type_date, "cast date --> date"); + t.ok (v44.get_date () == 1234567890, "cast date --> date"); + + Variant v45 ((time_t) 1234567890); + v45.cast (Variant::type_duration); + t.ok (v45.type () == Variant::type_duration, "cast date --> duration"); + t.ok (v45.get_duration () == 1234567890, "cast date --> duration"); + + // Variant::type_duration --> * + Variant v50 ((time_t) 12345, Variant::type_duration); + v50.cast (Variant::type_boolean); + t.ok (v50.type () == Variant::type_boolean, "cast duration --> boolean"); + t.ok (v50.get_bool () == true, "cast duration --> boolean"); + + Variant v51 ((time_t) 12345, Variant::type_duration); + v51.cast (Variant::type_integer); + t.ok (v51.type () == Variant::type_integer, "cast duration --> integer"); + t.ok (v51.get_integer () == 12345, "cast duration --> integer"); + + Variant v52 ((time_t) 12345, Variant::type_duration); + v52.cast (Variant::type_real); + t.ok (v52.type () == Variant::type_real, "cast duration --> real"); + t.is (v52.get_real (), 12345.0, EPSILON, "cast duration --> real"); + + Variant v53 ((time_t) 12345, Variant::type_duration); + v53.cast (Variant::type_string); + t.ok (v53.type () == Variant::type_string, "cast duration --> string"); + t.is (v53.get_string (), "PT3H25M45S", "cast duration --> string"); + + Variant v54 ((time_t) 12345, Variant::type_duration); + v54.cast (Variant::type_date); + t.ok (v54.type () == Variant::type_date, "cast duration --> date"); + t.is (v54.get_date (), 12345, "cast duration --> date"); + + Variant v55 ((time_t) 12345, Variant::type_duration); + v55.cast (Variant::type_duration); + t.ok (v55.type () == Variant::type_duration, "cast duration --> duration"); + t.ok (v55.get_duration () == 12345, "cast duration --> duration"); + } + + catch (const std::string& e) + { + t.diag (e); + } + + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/test/variant_divide.t.cpp b/test/variant_divide.t.cpp new file mode 100644 index 000000000..e0484fdbb --- /dev/null +++ b/test/variant_divide.t.cpp @@ -0,0 +1,204 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2013 - 2014, Göteborg Bit Factory. +// +// 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. +// +// http://www.opensource.org/licenses/mit-license.php +// +//////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include +#include + +Context context; + +#define EPSILON 0.0001 + +//////////////////////////////////////////////////////////////////////////////// +int main (int argc, char** argv) +{ + UnitTest t (44); + + Variant v0 (true); + Variant v1 (42); + Variant v2 (3.14); + Variant v3 ("foo"); + Variant v4 (1234567890, Variant::type_date); + Variant v5 (1200, Variant::type_duration); + + // boolean / boolean -> ERROR + try {Variant v00 = v0 / v0; t.fail ("true / true --> error");} + catch (...) {t.pass ("true / true --> error");} + + // boolean / integer -> ERROR + try {Variant v01 = v0 / v1; t.fail ("true / 42 --> error");} + catch (...) {t.pass ("true / 42 --> error");} + + // boolean / real -> ERROR + try {Variant v02 = v0 / v2; t.fail ("true / 3.14 --> error");} + catch (...) {t.pass ("true / 3.14 --> error");} + + // boolean / string -> ERROR + try {Variant v03 = v0 / v3; t.fail ("true / foo --> error");} + catch (...) {t.pass ("true / foo --> error");} + + // boolean / date -> ERROR + try {Variant v04 = v0 / v4; t.fail ("true / 1234567890 --> error");} + catch (...) {t.pass ("true / 1234567890 --> error");} + + // boolean / duration -> ERROR + try {Variant v05 = v0 / v5; t.fail ("true / 1200 --> error");} + catch (...) {t.pass ("true / 1200 --> error");} + + // integer / boolean -> ERROR + try {Variant v10 = v1 / v0; t.fail ("42 / true --> error");} + catch (...) {t.pass ("42 / true --> error");} + + // integer / integer -> integer + Variant v11 = v1 / v1; + t.is (v11.type (), Variant::type_integer, "42 / 42 --> integer"); + t.is (v11.get_integer (), 1, "42 / 42 --> 1"); + + // integer / real -> real + Variant v12 = v1 / v2; + t.is (v12.type (), Variant::type_real, "42 / 3.14 --> real"); + t.is (v12.get_real (), 13.3757, EPSILON, "42 / 3.14 --> 13.3757"); + + // integer / string -> ERROR + try {Variant v13 = v1 / v3; t.fail ("42 / foo --> error");} + catch (...) {t.pass ("42 / foo --> error");} + + // integer / date -> ERROR + try {Variant v14 = v1 / v4; t.fail ("42 / 1234567890 --> error");} + catch (...) {t.pass ("42 / 1234567890 --> error");} + + // integer / duration -> duration + Variant v15 = v1 / v5; + t.is (v15.type (), Variant::type_duration, "42 / 1200 --> duration"); + t.is (v15.get_duration (), 0, "42 / 1200 --> 0"); + + // real / boolean -> ERROR + try {Variant v20 = v2 / v0; t.fail ("3.14 / true --> error");} + catch (...) {t.pass ("3.14 / true --> error");} + + // real / integer -> real + Variant v21 = v2 / v1; + t.is (v21.type (), Variant::type_real, "3.14 / 42 --> real"); + t.is (v21.get_real (), 0.0747, EPSILON, "3.14 / 42 --> 0.0747"); + + // real / real -> real + Variant v22 = v2 / v2; + t.is (v22.type (), Variant::type_real, "3.14 / 3.14 --> real"); + t.is (v22.get_real (), 1.0, EPSILON, "3.14 / 3.14 --> 1.0"); + + // real / string -> error + try {Variant v23 = v2 / v3; t.fail ("3.14 / foo --> error");} + catch (...) {t.pass ("3.14 / foo --> error");} + + // real / date -> error + try {Variant v24 = v2 / v4; t.fail ("3.14 / 1234567890 --> error");} + catch (...) {t.pass ("3.14 / 1234567890 --> error");} + + // real / duration -> duration + Variant v25 = v2 / v5; + t.is (v25.type (), Variant::type_duration, "3.14 / 1200 --> duration"); + t.is (v25.get_duration (), 0, "3.14 / 1200 --> 0"); + + // string / boolean -> ERROR + try {Variant v30 = v3 / v0; t.fail ("foo / true --> error");} + catch (...) {t.pass ("foo / true --> error");} + + // string / integer -> ERROR + try {Variant v31 = v3 / v1; t.fail ("foo / 42 --> error");} + catch (...) {t.pass ("foo / 42 --> error");} + + // string / real -> ERROR + try {Variant v32 = v3 / v2; t.fail ("foo / 3.14 --> error");} + catch (...) {t.pass ("foo / 3.14 --> error");} + + // string / string -> ERROR + try {Variant v33 = v3 / v3; t.fail ("foo / foo --> error");} + catch (...) {t.pass ("foo / foo --> error");} + + // string / date -> ERROR + try {Variant v34 = v3 / v4; t.fail ("foo / 1234567890 --> error");} + catch (...) {t.pass ("foo / 1234567890 --> error");} + + // string / duration -> ERROR + try {Variant v35 = v3 / v5; t.fail ("foo / 1200 --> error");} + catch (...) {t.pass ("foo / 1200 --> error");} + + // date / boolean -> ERROR + try {Variant v40 = v4 / v0; t.fail ("1234567890 / true --> error");} + catch (...) {t.pass ("1234567890 / true --> error");} + + // date / integer -> ERROR + try {Variant v41 = v4 / v1; t.fail ("1234567890 / 42 --> error");} + catch (...) {t.pass ("1234567890 / 42 --> error");} + + // date / real -> ERROR + try {Variant v42 = v4 / v2; t.fail ("1234567890 / 3.14 --> error");} + catch (...) {t.pass ("1234567890 / 3.14 --> error");} + + // date / string -> ERROR + try {Variant v43 = v4 / v3; t.fail ("1234567890 / foo --> error");} + catch (...) {t.pass ("1234567890 / foo --> error");} + + // date / date -> ERROR + try {Variant v44 = v4 / v4; t.fail ("1234567890 / 1234567890 --> error");} + catch (...) {t.pass ("1234567890 / 1234567890 --> error");} + + // date / duration -> ERROR + try {Variant v45 = v4 / v5; t.fail ("1234567890 / 1200 --> error");} + catch (...) {t.pass ("1234567890 / 1200 --> error");} + + // duration / boolean -> ERROR + try {Variant v50 = v5 / v0; t.fail ("1200 / true --> error");} + catch (...) {t.pass ("1200 / true --> error");} + + // duration / integer -> duration + Variant v51 = v5 / v1; + t.is (v51.type (), Variant::type_duration, "1200 / 42 --> duration"); + t.is (v51.get_duration (), 28, "1200 / 42 --> 28"); + + // duration / real -> duration + Variant v52 = v5 / v2; + t.is (v52.type (), Variant::type_duration, "1200 / 3.14 --> duration"); + t.is (v52.get_duration (), 382, "1200 / 3.14 --> 382"); + + // duration / string -> string + try {Variant v53 = v5 / v3; t.fail ("1200 / foo --> error");} + catch (...) {t.pass ("1200 / foo --> error");} + + // duration / date -> date + try {Variant v54 = v5 / v4; t.fail ("1200 / 1234567890 --> error");} + catch (...) {t.pass ("1200 / 1234567890 --> error");} + + // duration / duration -> duration + try {Variant v55 = v5 / v5; t.fail ("1200 / 1200 --> error");} + catch (...) {t.pass ("1200 / 1200 --> error");} + + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/test/variant_equal.t.cpp b/test/variant_equal.t.cpp new file mode 100644 index 000000000..b038fbd2f --- /dev/null +++ b/test/variant_equal.t.cpp @@ -0,0 +1,196 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2013 - 2014, Göteborg Bit Factory. +// +// 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. +// +// http://www.opensource.org/licenses/mit-license.php +// +//////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include +#include + +Context context; + +#define EPSILON 0.001 + +//////////////////////////////////////////////////////////////////////////////// +int main (int argc, char** argv) +{ + UnitTest t (72); + + Variant v0 (true); + Variant v1 (42); + Variant v2 (3.14); + Variant v3 ("foo"); + Variant v4 (1234567890, Variant::type_date); + Variant v5 (1200, Variant::type_duration); + + Variant v00 = v0 == v0; + t.is (v00.type (), Variant::type_boolean, "true == true --> boolean"); + t.is (v00.get_bool (), true, "true == true --> true"); + + Variant v01 = v0 == v1; + t.is (v01.type (), Variant::type_boolean, "true == 42 --> boolean"); + t.is (v01.get_bool (), false, "true == 42 --> false"); + + Variant v02 = v0 == v2; + t.is (v02.type (), Variant::type_boolean, "true == 3.14 --> boolean"); + t.is (v02.get_bool (), false, "true == 3.14 --> false"); + + Variant v03 = v0 == v3; + t.is (v03.type (), Variant::type_boolean, "true == 'foo' --> boolean"); + t.is (v03.get_bool (), false, "true == 'foo' --> false"); + + Variant v04 = v0 == v4; + t.is (v04.type (), Variant::type_boolean, "true == 1234567890 --> boolean"); + t.is (v04.get_bool (), false, "true == 1234567890 --> false"); + + Variant v05 = v0 == v5; + t.is (v05.type (), Variant::type_boolean, "true == 1200 --> boolean"); + t.is (v05.get_bool (), false, "true == 1200 --> false"); + + Variant v10 = v1 == v0; + t.is (v10.type (), Variant::type_boolean, "42 == true --> boolean"); + t.is (v10.get_bool (), false, "42 == true --> false"); + + Variant v11 = v1 == v1; + t.is (v11.type (), Variant::type_boolean, "42 == 42 --> boolean"); + t.is (v11.get_bool (), true, "42 == 42 --> true"); + + Variant v12 = v1 == v2; + t.is (v12.type (), Variant::type_boolean, "42 == 3.14 --> boolean"); + t.is (v12.get_bool (), false, "42 == 3.14 --> false"); + + Variant v13 = v1 == v3; + t.is (v13.type (), Variant::type_boolean, "42 == 'foo' --> boolean"); + t.is (v13.get_bool (), false, "42 == 'foo' --> false"); + + Variant v14 = v1 == v4; + t.is (v04.type (), Variant::type_boolean, "42 == 1234567890 --> boolean"); + t.is (v04.get_bool (), false, "42 == 1234567890 --> false"); + + Variant v15 = v1 == v5; + t.is (v15.type (), Variant::type_boolean, "42 == 1200 --> boolean"); + t.is (v15.get_bool (), false, "42 == 1200 --> false"); + + Variant v20 = v2 == v0; + t.is (v20.type (), Variant::type_boolean, "3.14 == true --> boolean"); + t.is (v20.get_bool (), false, "3.14 == true --> false"); + + Variant v21 = v2 == v1; + t.is (v21.type (), Variant::type_boolean, "3.14 == 42 --> boolean"); + t.is (v21.get_bool (), false, "3.14 == 42 --> false"); + + Variant v22 = v2 == v2; + t.is (v22.type (), Variant::type_boolean, "3.14 == 3.14 --> boolean"); + t.is (v22.get_bool (), true, "3.14 == 3.14 --> true"); + + Variant v23 = v2 == v3; + t.is (v23.type (), Variant::type_boolean, "3.14 == 'foo' --> boolean"); + t.is (v23.get_bool (), false, "3.14 == 'foo' --> false"); + + Variant v24 = v2 == v4; + t.is (v24.type (), Variant::type_boolean, "3.14 == 1234567890 --> boolean"); + t.is (v24.get_bool (), false, "3.14 == 1234567890 --> false"); + + Variant v25 = v2 == v5; + t.is (v25.type (), Variant::type_boolean, "3.14 == 1200 --> boolean"); + t.is (v25.get_bool (), false, "3.14 == 1200 --> false"); + + Variant v30 = v3 == v0; + t.is (v30.type (), Variant::type_boolean, "'foo' == true --> boolean"); + t.is (v30.get_bool (), false, "'foo' == true --> false"); + + Variant v31 = v3 == v1; + t.is (v31.type (), Variant::type_boolean, "'foo' == 42 --> boolean"); + t.is (v31.get_bool (), false, "'foo' == 42 --> false"); + + Variant v32 = v3 == v2; + t.is (v32.type (), Variant::type_boolean, "'foo' == 3.14 --> boolean"); + t.is (v32.get_bool (), false, "'foo' == 3.14 --> false"); + + Variant v33 = v3 == v3; + t.is (v33.type (), Variant::type_boolean, "'foo' == 'foo' --> boolean"); + t.is (v33.get_bool (), true, "'foo' == 'foo' --> true"); + + Variant v34 = v3 == v4; + t.is (v34.type (), Variant::type_boolean, "'foo' == 1234567890 --> boolean"); + t.is (v34.get_bool (), false, "'foo' == 1234567890 --> false"); + + Variant v35 = v3 == v5; + t.is (v35.type (), Variant::type_boolean, "'foo' == 1200 --> boolean"); + t.is (v35.get_bool (), false, "'foo' == 1200 --> false"); + + Variant v40 = v4 == v0; + t.is (v40.type (), Variant::type_boolean, "1234567890 == true --> boolean"); + t.is (v40.get_bool (), false, "1234567890 == true --> false"); + + Variant v41 = v4 == v1; + t.is (v41.type (), Variant::type_boolean, "1234567890 == 42 --> boolean"); + t.is (v41.get_bool (), false, "1234567890 == 42 --> false"); + + Variant v42 = v4 == v2; + t.is (v42.type (), Variant::type_boolean, "1234567890 == 3.14 --> boolean"); + t.is (v42.get_bool (), false, "1234567890 == 3.14 --> false"); + + Variant v43 = v4 == v3; + t.is (v43.type (), Variant::type_boolean, "1234567890 == 'foo' --> boolean"); + t.is (v43.get_bool (), false, "1234567890 == 'foo' --> false"); + + Variant v44 = v4 == v4; + t.is (v44.type (), Variant::type_boolean, "1234567890 == 1234567890 --> boolean"); + t.is (v44.get_bool (), true, "1234567890 == 1234567890 --> true"); + + Variant v45 = v4 == v5; + t.is (v45.type (), Variant::type_boolean, "1234567890 == 1200 --> boolean"); + t.is (v45.get_bool (), false, "1234567890 == 1200 --> false"); + + Variant v50 = v5 == v0; + t.is (v50.type (), Variant::type_boolean, "1200 == true --> boolean"); + t.is (v50.get_bool (), false, "1200 == true --> false"); + + Variant v51 = v5 == v1; + t.is (v51.type (), Variant::type_boolean, "1200 == 42 --> boolean"); + t.is (v51.get_bool (), false, "1200 == 42 --> false"); + + Variant v52 = v5 == v2; + t.is (v52.type (), Variant::type_boolean, "1200 == 3.14 --> boolean"); + t.is (v52.get_bool (), false, "1200 == 3.14 --> false"); + + Variant v53 = v5 == v3; + t.is (v53.type (), Variant::type_boolean, "1200 == 'foo' --> boolean"); + t.is (v53.get_bool (), false, "1200 == 'foo' --> false"); + + Variant v54 = v5 == v4; + t.is (v04.type (), Variant::type_boolean, "1200 == 1234567890 --> boolean"); + t.is (v04.get_bool (), false, "1200 == 1234567890 --> false"); + + Variant v55 = v5 == v5; + t.is (v55.type (), Variant::type_boolean, "1200 == 1200 --> boolean"); + t.is (v55.get_bool (), true, "1200 == 1200 --> true"); + + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/test/variant_exp.t.cpp b/test/variant_exp.t.cpp new file mode 100644 index 000000000..33d60ec5d --- /dev/null +++ b/test/variant_exp.t.cpp @@ -0,0 +1,198 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2013 - 2014, Göteborg Bit Factory. +// +// 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. +// +// http://www.opensource.org/licenses/mit-license.php +// +//////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include +#include + +Context context; + +#define EPSILON 0.001 + +//////////////////////////////////////////////////////////////////////////////// +int main (int argc, char** argv) +{ + UnitTest t (38); + + Variant v0 (true); + Variant v1 (42); + Variant v2 (3.14); + Variant v3 ("foo"); + Variant v4 (1234567890, Variant::type_date); + Variant v5 (1200, Variant::type_duration); + + // boolean ^ boolean -> ERROR + try {Variant v00 = v0 ^ v0; t.fail ("true ^ true --> error");} + catch (...) {t.pass ("true ^ true --> error");} + + // boolean ^ integer -> ERROR + try {Variant v01 = v0 ^ v1; t.fail ("true ^ 42 --> error");} + catch (...) {t.pass ("true ^ 42 --> error");} + + // boolean ^ real -> ERROR + try {Variant v02 = v0 ^ v2; t.fail ("true ^ 3.14 --> error");} + catch (...) {t.pass ("true ^ 3.14 --> error");} + + // boolean ^ string -> ERROR + try {Variant v03 = v0 ^ v3; t.fail ("true ^ foo --> error");} + catch (...) {t.pass ("true ^ foo --> error");} + + // boolean ^ date -> ERROR + try {Variant v04 = v0 ^ v4; t.fail ("true ^ 1234567890 --> error");} + catch (...) {t.pass ("true ^ 1234567890 --> error");} + + // boolean ^ duration -> ERROR + try {Variant v05 = v0 ^ v5; t.fail ("true ^ 1200 --> error");} + catch (...) {t.pass ("true ^ 1200 --> error");} + + // integer ^ boolean -> ERROR + try {Variant v10 = v1 ^ v0; t.fail ("42 ^ true --> error");} + catch (...) {t.pass ("42 ^ true --> error");} + + // integer ^ integer -> integer + Variant v11 = v1 ^ Variant (2); + t.is (v11.type (), Variant::type_integer, "42 ^ 2 --> integer"); + t.is (v11.get_integer (), 1764, "42 ^ 2 --> 1764"); + + // integer ^ real -> real + try {Variant v12 = v1 ^ v2; t.fail ("42 ^ 3.14 --> error");} + catch (...) {t.pass ("42 ^ 3.14 --> error");} + + // integer ^ string -> ERROR + try {Variant v13 = v1 ^ v3; t.fail ("42 ^ foo --> error");} + catch (...) {t.pass ("42 ^ foo --> error");} + + // integer ^ date -> ERROR + try {Variant v14 = v1 ^ v4; t.fail ("42 ^ 1234567890 --> error");} + catch (...) {t.pass ("42 ^ 1234567890 --> error");} + + // integer ^ duration -> ERROR + try {Variant v15 = v1 ^ v5; t.fail ("42 ^ 1200 --> error");} + catch (...) {t.pass ("42 ^ 1200 --> error");} + + // real ^ boolean -> ERROR + try {Variant v20 = v2 ^ v0; t.fail ("3.14 ^ true --> error");} + catch (...) {t.pass ("3.14 ^ true --> error");} + + // real ^ integer -> real + Variant v21 = v2 ^ Variant (2); + t.is (v21.type (), Variant::type_real, "3.14 ^ 2 --> real"); + t.is (v21.get_real (), 9.8596, 0.001, "3.14 ^ 2 --> 9.8596"); + + // real ^ real -> ERROR + try {Variant v22 = v2 ^ v2; t.fail ("3.14 ^ 3.14 --> error");} + catch (...) {t.pass ("3.14 ^ 3.14 --> error");} + + // real ^ string -> ERROR + try {Variant v23 = v2 ^ v3; t.fail ("3.14 ^ foo --> error");} + catch (...) {t.pass ("3.14 ^ foo --> error");} + + // real ^ date -> ERROR + try {Variant v24 = v2 ^ v4; t.fail ("3.14 ^ 1234567890 --> error");} + catch (...) {t.pass ("3.14 ^ 1234567890 --> error");} + + // real ^ duration -> ERROR + try {Variant v25 = v2 ^ v5; t.fail ("3.14 ^ 1200 --> error");} + catch (...) {t.pass ("3.14 ^ 1200 --> error");} + + // string ^ boolean -> ERROR + try {Variant v30 = v3 ^ v0; t.fail ("foo ^ true --> error");} + catch (...) {t.pass ("foo ^ true --> error");} + + // string ^ integer -> ERROR + try {Variant v31 = v3 ^ v1; t.fail ("foo ^ 42 --> error");} + catch (...) {t.pass ("foo ^ 42 --> error");} + + // string ^ real -> ERROR + try {Variant v32 = v3 ^ v2; t.fail ("foo ^ 3.14 --> error");} + catch (...) {t.pass ("foo ^ 3.14 --> error");} + + // string ^ string -> ERROR + try {Variant v33 = v3 ^ v3; t.fail ("foo ^ foo --> error");} + catch (...) {t.pass ("foo ^ foo --> error");} + + // string ^ date -> ERROR + try {Variant v34 = v3 ^ v4; t.fail ("foo ^ 1234567890 --> error");} + catch (...) {t.pass ("foo ^ 1234567890 --> error");} + + // string ^ duration -> ERROR + try {Variant v35 = v3 ^ v5; t.fail ("foo ^ 1200 --> error");} + catch (...) {t.pass ("foo ^ 1200 --> error");} + + // date ^ boolean -> ERROR + try {Variant v40 = v4 ^ v0; t.fail ("1234567890 ^ true --> error");} + catch (...) {t.pass ("1234567890 ^ true --> error");} + + // date ^ integer -> ERROR + try {Variant v41 = v4 ^ v1; t.fail ("1234567890 ^ 42 --> error");} + catch (...) {t.pass ("1234567890 ^ 42 --> error");} + + // date ^ real -> ERROR + try {Variant v42 = v4 ^ v2; t.fail ("1234567890 ^ 3.14 --> error");} + catch (...) {t.pass ("1234567890 ^ 3.14 --> error");} + + // date ^ string -> ERROR + try {Variant v43 = v4 ^ v3; t.fail ("1234567890 ^ foo --> error");} + catch (...) {t.pass ("1234567890 ^ foo --> error");} + + // date ^ date -> ERROR + try {Variant v44 = v4 ^ v4; t.fail ("1234567890 ^ 1234567890 --> error");} + catch (...) {t.pass ("1234567890 ^ 1234567890 --> error");} + + // date ^ duration -> ERROR + try {Variant v45 = v4 ^ v5; t.fail ("1234567890 ^ 1200 --> error");} + catch (...) {t.pass ("1234567890 ^ 1200 --> error");} + + // duration ^ boolean -> ERROR + try {Variant v50 = v5 ^ v0; t.fail ("1200 ^ true --> error");} + catch (...) {t.pass ("1200 ^ true --> error");} + + // duration ^ integer -> ERROR + try {Variant v51 = v5 ^ v1; t.fail ("1200 ^ 42 --> error");} + catch (...) {t.pass ("1200 ^ 42 --> error");} + + // duration ^ real -> ERROR + try {Variant v52 = v5 ^ v2; t.fail ("1200 ^ 3.14 --> error");} + catch (...) {t.pass ("1200 ^ 3.14 --> error");} + + // duration ^ string -> ERROR + try {Variant v53 = v5 ^ v3; t.fail ("1200 ^ foo --> error");} + catch (...) {t.pass ("1200 ^ foo --> error");} + + // duration ^ date -> ERROR + try {Variant v54 = v5 ^ v4; t.fail ("1200 ^ 1234567890 --> error");} + catch (...) {t.pass ("1200 ^ 1234567890 --> error");} + + // duration ^ duration -> ERROR + try {Variant v55 = v5 ^ v5; t.fail ("1200 ^ 1200 --> error");} + catch (...) {t.pass ("1200 ^ 1200 --> error");} + + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/test/variant_gt.t.cpp b/test/variant_gt.t.cpp new file mode 100644 index 000000000..254710104 --- /dev/null +++ b/test/variant_gt.t.cpp @@ -0,0 +1,194 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2013 - 2014, Göteborg Bit Factory. +// +// 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. +// +// http://www.opensource.org/licenses/mit-license.php +// +//////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include +#include + +Context context; + +//////////////////////////////////////////////////////////////////////////////// +int main (int argc, char** argv) +{ + UnitTest t (72); + + Variant v0 (true); + Variant v1 (42); + Variant v2 (3.14); + Variant v3 ("foo"); + Variant v4 (1234567890, Variant::type_date); + Variant v5 (1200, Variant::type_duration); + + Variant v00 = v0 > v0; + t.is (v00.type (), Variant::type_boolean, "true > true --> boolean"); + t.is (v00.get_bool (), false, "true > true --> false"); + + Variant v01 = v0 > v1; + t.is (v01.type (), Variant::type_boolean, "true > 42 --> boolean"); + t.is (v01.get_bool (), false, "true > 42 --> false"); + + Variant v02 = v0 > v2; + t.is (v02.type (), Variant::type_boolean, "true > 3.14 --> boolean"); + t.is (v02.get_bool (), false, "true > 3.14 --> false"); + + Variant v03 = v0 > v3; + t.is (v03.type (), Variant::type_boolean, "true > 'foo' --> boolean"); + t.is (v03.get_bool (), true, "true > 'foo' --> true"); + + Variant v04 = v0 > v4; + t.is (v04.type (), Variant::type_boolean, "true > 1234567890 --> boolean"); + t.is (v04.get_bool (), false, "true > 1234567890 --> false"); + + Variant v05 = v0 > v5; + t.is (v05.type (), Variant::type_boolean, "true > 1200 --> boolean"); + t.is (v05.get_bool (), false, "true > 1200 --> false"); + + Variant v10 = v1 > v0; + t.is (v10.type (), Variant::type_boolean, "42 > true --> boolean"); + t.is (v10.get_bool (), true, "42 > true --> true"); + + Variant v11 = v1 > v1; + t.is (v11.type (), Variant::type_boolean, "42 > 42 --> boolean"); + t.is (v11.get_bool (), false, "42 > 42 --> false"); + + Variant v12 = v1 > v2; + t.is (v12.type (), Variant::type_boolean, "42 > 3.14 --> boolean"); + t.is (v12.get_bool (), true, "42 > 3.14 --> true"); + + Variant v13 = v1 > v3; + t.is (v13.type (), Variant::type_boolean, "42 > 'foo' --> boolean"); + t.is (v13.get_bool (), false, "42 > 'foo' --> false"); + + Variant v14 = v1 > v4; + t.is (v04.type (), Variant::type_boolean, "42 > 1234567890 --> boolean"); + t.is (v04.get_bool (), false, "42 > 1234567890 --> false"); + + Variant v15 = v1 > v5; + t.is (v15.type (), Variant::type_boolean, "42 > 1200 --> boolean"); + t.is (v15.get_bool (), false, "42 > 1200 --> false"); + + Variant v20 = v2 > v0; + t.is (v20.type (), Variant::type_boolean, "3.14 > true --> boolean"); + t.is (v20.get_bool (), true, "3.14 > true --> true"); + + Variant v21 = v2 > v1; + t.is (v21.type (), Variant::type_boolean, "3.14 > 42 --> boolean"); + t.is (v21.get_bool (), false, "3.14 > 42 --> false"); + + Variant v22 = v2 > v2; + t.is (v22.type (), Variant::type_boolean, "3.14 > 3.14 --> boolean"); + t.is (v22.get_bool (), false, "3.14 > 3.14 --> false"); + + Variant v23 = v2 > v3; + t.is (v23.type (), Variant::type_boolean, "3.14 > 'foo' --> boolean"); + t.is (v23.get_bool (), false, "3.14 > 'foo' --> false"); + + Variant v24 = v2 > v4; + t.is (v24.type (), Variant::type_boolean, "3.14 > 1234567890 --> boolean"); + t.is (v24.get_bool (), false, "3.14 > 1234567890 --> false"); + + Variant v25 = v2 > v5; + t.is (v25.type (), Variant::type_boolean, "3.14 > 1200 --> boolean"); + t.is (v25.get_bool (), false, "3.14 > 1200 --> false"); + + Variant v30 = v3 > v0; + t.is (v30.type (), Variant::type_boolean, "'foo' > true --> boolean"); + t.is (v30.get_bool (), false, "'foo' > true --> false"); + + Variant v31 = v3 > v1; + t.is (v31.type (), Variant::type_boolean, "'foo' > 42 --> boolean"); + t.is (v31.get_bool (), true, "'foo' > 42 --> true"); + + Variant v32 = v3 > v2; + t.is (v32.type (), Variant::type_boolean, "'foo' > 3.14 --> boolean"); + t.is (v32.get_bool (), true, "'foo' > 3.14 --> true"); + + Variant v33 = v3 > v3; + t.is (v33.type (), Variant::type_boolean, "'foo' > 'foo' --> boolean"); + t.is (v33.get_bool (), false, "'foo' > 'foo' --> false"); + + Variant v34 = v3 > v4; + t.is (v34.type (), Variant::type_boolean, "'foo' > 1234567890 --> boolean"); + t.is (v34.get_bool (), false, "'foo' > 1234567890 --> false"); + + Variant v35 = v3 > v5; + t.is (v35.type (), Variant::type_boolean, "'foo' > 1200 --> boolean"); + t.is (v35.get_bool (), false, "'foo' > 1200 --> false"); + + Variant v40 = v4 > v0; + t.is (v40.type (), Variant::type_boolean, "1234567890 > true --> boolean"); + t.is (v40.get_bool (), true, "1234567890 > true --> true"); + + Variant v41 = v4 > v1; + t.is (v41.type (), Variant::type_boolean, "1234567890 > 42 --> boolean"); + t.is (v41.get_bool (), true, "1234567890 > 42 --> true"); + + Variant v42 = v4 > v2; + t.is (v42.type (), Variant::type_boolean, "1234567890 > 3.14 --> boolean"); + t.is (v42.get_bool (), true, "1234567890 > 3.14 --> true"); + + Variant v43 = v4 > v3; + t.is (v43.type (), Variant::type_boolean, "1234567890 > 'foo' --> boolean"); + t.is (v43.get_bool (), true, "1234567890 > 'foo' --> true"); + + Variant v44 = v4 > v4; + t.is (v44.type (), Variant::type_boolean, "1234567890 > 1234567890 --> boolean"); + t.is (v44.get_bool (), false, "1234567890 > 1234567890 --> false"); + + Variant v45 = v4 > v5; + t.is (v45.type (), Variant::type_boolean, "1234567890 > 1200 --> boolean"); + t.is (v45.get_bool (), true, "1234567890 > 1200 --> true"); + + Variant v50 = v5 > v0; + t.is (v50.type (), Variant::type_boolean, "1200 > true --> boolean"); + t.is (v50.get_bool (), true, "1200 > true --> true"); + + Variant v51 = v5 > v1; + t.is (v51.type (), Variant::type_boolean, "1200 > 42 --> boolean"); + t.is (v51.get_bool (), true, "1200 > 42 --> true"); + + Variant v52 = v5 > v2; + t.is (v52.type (), Variant::type_boolean, "1200 > 3.14 --> boolean"); + t.is (v52.get_bool (), true, "1200 > 3.14 --> true"); + + Variant v53 = v5 > v3; + t.is (v53.type (), Variant::type_boolean, "1200 > 'foo' --> boolean"); + t.is (v53.get_bool (), true, "1200 > 'foo' --> true"); + + Variant v54 = v5 > v4; + t.is (v54.type (), Variant::type_boolean, "1200 > 1234567890 --> boolean"); + t.is (v54.get_bool (), false, "1200 > 1234567890 --> false"); + + Variant v55 = v5 > v5; + t.is (v55.type (), Variant::type_boolean, "1200 > 1200 --> boolean"); + t.is (v55.get_bool (), false, "1200 > 1200 --> false"); + + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/test/variant_gte.t.cpp b/test/variant_gte.t.cpp new file mode 100644 index 000000000..926f61e28 --- /dev/null +++ b/test/variant_gte.t.cpp @@ -0,0 +1,194 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2013 - 2014, Göteborg Bit Factory. +// +// 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. +// +// http://www.opensource.org/licenses/mit-license.php +// +//////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include +#include + +Context context; + +//////////////////////////////////////////////////////////////////////////////// +int main (int argc, char** argv) +{ + UnitTest t (72); + + Variant v0 (true); + Variant v1 (42); + Variant v2 (3.14); + Variant v3 ("foo"); + Variant v4 (1234567890, Variant::type_date); + Variant v5 (1200, Variant::type_duration); + + Variant v00 = v0 >= v0; + t.is (v00.type (), Variant::type_boolean, "true >= true --> boolean"); + t.is (v00.get_bool (), true, "true >= true --> true"); + + Variant v01 = v0 >= v1; + t.is (v01.type (), Variant::type_boolean, "true >= 42 --> boolean"); + t.is (v01.get_bool (), false, "true >= 42 --> false"); + + Variant v02 = v0 >= v2; + t.is (v02.type (), Variant::type_boolean, "true >= 3.14 --> boolean"); + t.is (v02.get_bool (), false, "true >= 3.14 --> false"); + + Variant v03 = v0 >= v3; + t.is (v03.type (), Variant::type_boolean, "true >= 'foo' --> boolean"); + t.is (v03.get_bool (), true, "true >= 'foo' --> true"); + + Variant v04 = v0 >= v4; + t.is (v04.type (), Variant::type_boolean, "true >= 1234567890 --> boolean"); + t.is (v04.get_bool (), false, "true >= 1234567890 --> false"); + + Variant v05 = v0 >= v5; + t.is (v05.type (), Variant::type_boolean, "true >= 1200 --> boolean"); + t.is (v05.get_bool (), false, "true >= 1200 --> false"); + + Variant v10 = v1 >= v0; + t.is (v10.type (), Variant::type_boolean, "42 >= true --> boolean"); + t.is (v10.get_bool (), true, "42 >= true --> true"); + + Variant v11 = v1 >= v1; + t.is (v11.type (), Variant::type_boolean, "42 >= 42 --> boolean"); + t.is (v11.get_bool (), true, "42 >= 42 --> true"); + + Variant v12 = v1 >= v2; + t.is (v12.type (), Variant::type_boolean, "42 >= 3.14 --> boolean"); + t.is (v12.get_bool (), true, "42 >= 3.14 --> true"); + + Variant v13 = v1 >= v3; + t.is (v13.type (), Variant::type_boolean, "42 >= 'foo' --> boolean"); + t.is (v13.get_bool (), false, "42 >= 'foo' --> false"); + + Variant v14 = v1 >= v4; + t.is (v04.type (), Variant::type_boolean, "42 >= 1234567890 --> boolean"); + t.is (v04.get_bool (), false, "42 >= 1234567890 --> false"); + + Variant v15 = v1 >= v5; + t.is (v15.type (), Variant::type_boolean, "42 >= 1200 --> boolean"); + t.is (v15.get_bool (), false, "42 >= 1200 --> false"); + + Variant v20 = v2 >= v0; + t.is (v20.type (), Variant::type_boolean, "3.14 >= true --> boolean"); + t.is (v20.get_bool (), true, "3.14 >= true --> true"); + + Variant v21 = v2 >= v1; + t.is (v21.type (), Variant::type_boolean, "3.14 >= 42 --> boolean"); + t.is (v21.get_bool (), false, "3.14 >= 42 --> false"); + + Variant v22 = v2 >= v2; + t.is (v22.type (), Variant::type_boolean, "3.14 >= 3.14 --> boolean"); + t.is (v22.get_bool (), true, "3.14 >= 3.14 --> true"); + + Variant v23 = v2 >= v3; + t.is (v23.type (), Variant::type_boolean, "3.14 >= 'foo' --> boolean"); + t.is (v23.get_bool (), false, "3.14 >= 'foo' --> false"); + + Variant v24 = v2 >= v4; + t.is (v24.type (), Variant::type_boolean, "3.14 >= 1234567890 --> boolean"); + t.is (v24.get_bool (), false, "3.14 >= 1234567890 --> false"); + + Variant v25 = v2 >= v5; + t.is (v25.type (), Variant::type_boolean, "3.14 >= 1200 --> boolean"); + t.is (v25.get_bool (), false, "3.14 >= 1200 --> false"); + + Variant v30 = v3 >= v0; + t.is (v30.type (), Variant::type_boolean, "'foo' >= true --> boolean"); + t.is (v30.get_bool (), false, "'foo' >= true --> false"); + + Variant v31 = v3 >= v1; + t.is (v31.type (), Variant::type_boolean, "'foo' >= 42 --> boolean"); + t.is (v31.get_bool (), true, "'foo' >= 42 --> true"); + + Variant v32 = v3 >= v2; + t.is (v32.type (), Variant::type_boolean, "'foo' >= 3.14 --> boolean"); + t.is (v32.get_bool (), true, "'foo' >= 3.14 --> true"); + + Variant v33 = v3 >= v3; + t.is (v33.type (), Variant::type_boolean, "'foo' >= 'foo' --> boolean"); + t.is (v33.get_bool (), true, "'foo' >= 'foo' --> true"); + + Variant v34 = v3 >= v4; + t.is (v34.type (), Variant::type_boolean, "'foo' >= 1234567890 --> boolean"); + t.is (v34.get_bool (), false, "'foo' >= 1234567890 --> false"); + + Variant v35 = v3 >= v5; + t.is (v35.type (), Variant::type_boolean, "'foo' >= 1200 --> boolean"); + t.is (v35.get_bool (), false, "'foo' >= 1200 --> false"); + + Variant v40 = v4 >= v0; + t.is (v40.type (), Variant::type_boolean, "1234567890 >= true --> boolean"); + t.is (v40.get_bool (), true, "1234567890 >= true --> true"); + + Variant v41 = v4 >= v1; + t.is (v41.type (), Variant::type_boolean, "1234567890 >= 42 --> boolean"); + t.is (v41.get_bool (), true, "1234567890 >= 42 --> true"); + + Variant v42 = v4 >= v2; + t.is (v42.type (), Variant::type_boolean, "1234567890 >= 3.14 --> boolean"); + t.is (v42.get_bool (), true, "1234567890 >= 3.14 --> true"); + + Variant v43 = v4 >= v3; + t.is (v43.type (), Variant::type_boolean, "1234567890 >= 'foo' --> boolean"); + t.is (v43.get_bool (), true, "1234567890 >= 'foo' --> true"); + + Variant v44 = v4 >= v4; + t.is (v44.type (), Variant::type_boolean, "1234567890 >= 1234567890 --> boolean"); + t.is (v44.get_bool (), true, "1234567890 >= 1234567890 --> true"); + + Variant v45 = v4 >= v5; + t.is (v45.type (), Variant::type_boolean, "1234567890 >= 1200 --> boolean"); + t.is (v45.get_bool (), true, "1234567890 >= 1200 --> true"); + + Variant v50 = v5 >= v0; + t.is (v50.type (), Variant::type_boolean, "1200 >= true --> boolean"); + t.is (v50.get_bool (), true, "1200 >= true --> true"); + + Variant v51 = v5 >= v1; + t.is (v51.type (), Variant::type_boolean, "1200 >= 42 --> boolean"); + t.is (v51.get_bool (), true, "1200 >= 42 --> true"); + + Variant v52 = v5 >= v2; + t.is (v52.type (), Variant::type_boolean, "1200 >= 3.14 --> boolean"); + t.is (v52.get_bool (), true, "1200 >= 3.14 --> true"); + + Variant v53 = v5 >= v3; + t.is (v53.type (), Variant::type_boolean, "1200 >= 'foo' --> boolean"); + t.is (v53.get_bool (), true, "1200 >= 'foo' --> true"); + + Variant v54 = v5 >= v4; + t.is (v54.type (), Variant::type_boolean, "1200 >= 1234567890 --> boolean"); + t.is (v54.get_bool (), false, "1200 >= 1234567890 --> false"); + + Variant v55 = v5 >= v5; + t.is (v55.type (), Variant::type_boolean, "1200 >= 1200 --> boolean"); + t.is (v55.get_bool (), true, "1200 >= 1200 --> true"); + + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/test/variant_inequal.t.cpp b/test/variant_inequal.t.cpp new file mode 100644 index 000000000..2f0174093 --- /dev/null +++ b/test/variant_inequal.t.cpp @@ -0,0 +1,196 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2013 - 2014, Göteborg Bit Factory. +// +// 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. +// +// http://www.opensource.org/licenses/mit-license.php +// +//////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include +#include + +Context context; + +#define EPSILON 0.001 + +//////////////////////////////////////////////////////////////////////////////// +int main (int argc, char** argv) +{ + UnitTest t (72); + + Variant v0 (true); + Variant v1 (42); + Variant v2 (3.14); + Variant v3 ("foo"); + Variant v4 (1234567890, Variant::type_date); + Variant v5 (1200, Variant::type_duration); + + Variant v00 = v0 != v0; + t.is (v00.type (), Variant::type_boolean, "true != true --> boolean"); + t.is (v00.get_bool (), false, "true != true --> false"); + + Variant v01 = v0 != v1; + t.is (v01.type (), Variant::type_boolean, "true != 42 --> boolean"); + t.is (v01.get_bool (), true, "true != 42 --> true"); + + Variant v02 = v0 != v2; + t.is (v02.type (), Variant::type_boolean, "true != 3.14 --> boolean"); + t.is (v02.get_bool (), true, "true != 3.14 --> true"); + + Variant v03 = v0 != v3; + t.is (v03.type (), Variant::type_boolean, "true != 'foo' --> boolean"); + t.is (v03.get_bool (), true, "true != 'foo' --> true"); + + Variant v04 = v0 != v4; + t.is (v04.type (), Variant::type_boolean, "true != 1234567890 --> boolean"); + t.is (v04.get_bool (), true, "true != 1234567890 --> true"); + + Variant v05 = v0 != v5; + t.is (v05.type (), Variant::type_boolean, "true != 1200 --> boolean"); + t.is (v05.get_bool (), true, "true != 1200 --> true"); + + Variant v10 = v1 != v0; + t.is (v10.type (), Variant::type_boolean, "42 != true --> boolean"); + t.is (v10.get_bool (), true, "42 != true --> true"); + + Variant v11 = v1 != v1; + t.is (v11.type (), Variant::type_boolean, "42 != 42 --> boolean"); + t.is (v11.get_bool (), false, "42 != 42 --> false"); + + Variant v12 = v1 != v2; + t.is (v12.type (), Variant::type_boolean, "42 != 3.14 --> boolean"); + t.is (v12.get_bool (), true, "42 != 3.14 --> true"); + + Variant v13 = v1 != v3; + t.is (v13.type (), Variant::type_boolean, "42 != 'foo' --> boolean"); + t.is (v13.get_bool (), true, "42 != 'foo' --> true"); + + Variant v14 = v1 != v4; + t.is (v04.type (), Variant::type_boolean, "42 != 1234567890 --> boolean"); + t.is (v04.get_bool (), true, "42 != 1234567890 --> true"); + + Variant v15 = v1 != v5; + t.is (v15.type (), Variant::type_boolean, "42 != 1200 --> boolean"); + t.is (v15.get_bool (), true, "42 != 1200 --> true"); + + Variant v20 = v2 != v0; + t.is (v20.type (), Variant::type_boolean, "3.14 != true --> boolean"); + t.is (v20.get_bool (), true, "3.14 != true --> true"); + + Variant v21 = v2 != v1; + t.is (v21.type (), Variant::type_boolean, "3.14 != 42 --> boolean"); + t.is (v21.get_bool (), true, "3.14 != 42 --> true"); + + Variant v22 = v2 != v2; + t.is (v22.type (), Variant::type_boolean, "3.14 != 3.14 --> boolean"); + t.is (v22.get_bool (), false, "3.14 != 3.14 --> false"); + + Variant v23 = v2 != v3; + t.is (v23.type (), Variant::type_boolean, "3.14 != 'foo' --> boolean"); + t.is (v23.get_bool (), true, "3.14 != 'foo' --> true"); + + Variant v24 = v2 != v4; + t.is (v24.type (), Variant::type_boolean, "3.14 != 1234567890 --> boolean"); + t.is (v24.get_bool (), true, "3.14 != 1234567890 --> true"); + + Variant v25 = v2 != v5; + t.is (v25.type (), Variant::type_boolean, "3.14 != 1200 --> boolean"); + t.is (v25.get_bool (), true, "3.14 != 1200 --> true"); + + Variant v30 = v3 != v0; + t.is (v30.type (), Variant::type_boolean, "'foo' != true --> boolean"); + t.is (v30.get_bool (), true, "'foo' != true --> true"); + + Variant v31 = v3 != v1; + t.is (v31.type (), Variant::type_boolean, "'foo' != 42 --> boolean"); + t.is (v31.get_bool (), true, "'foo' != 42 --> true"); + + Variant v32 = v3 != v2; + t.is (v32.type (), Variant::type_boolean, "'foo' != 3.14 --> boolean"); + t.is (v32.get_bool (), true, "'foo' != 3.14 --> true"); + + Variant v33 = v3 != v3; + t.is (v33.type (), Variant::type_boolean, "'foo' != 'foo' --> boolean"); + t.is (v33.get_bool (), false, "'foo' != 'foo' --> false"); + + Variant v34 = v3 != v4; + t.is (v34.type (), Variant::type_boolean, "'foo' != 1234567890 --> boolean"); + t.is (v34.get_bool (), true, "'foo' != 1234567890 --> true"); + + Variant v35 = v3 != v5; + t.is (v35.type (), Variant::type_boolean, "'foo' != 1200 --> boolean"); + t.is (v35.get_bool (), true, "'foo' != 1200 --> true"); + + Variant v40 = v4 != v0; + t.is (v40.type (), Variant::type_boolean, "1234567890 != true --> boolean"); + t.is (v40.get_bool (), true, "1234567890 != true --> true"); + + Variant v41 = v4 != v1; + t.is (v41.type (), Variant::type_boolean, "1234567890 != 42 --> boolean"); + t.is (v41.get_bool (), true, "1234567890 != 42 --> true"); + + Variant v42 = v4 != v2; + t.is (v42.type (), Variant::type_boolean, "1234567890 != 3.14 --> boolean"); + t.is (v42.get_bool (), true, "1234567890 != 3.14 --> true"); + + Variant v43 = v4 != v3; + t.is (v43.type (), Variant::type_boolean, "1234567890 != 'foo' --> boolean"); + t.is (v43.get_bool (), true, "1234567890 != 'foo' --> true"); + + Variant v44 = v4 != v4; + t.is (v44.type (), Variant::type_boolean, "1234567890 != 1234567890 --> boolean"); + t.is (v44.get_bool (), false, "1234567890 != 1234567890 --> false"); + + Variant v45 = v4 != v5; + t.is (v45.type (), Variant::type_boolean, "1234567890 != 1200 --> boolean"); + t.is (v45.get_bool (), true, "1234567890 != 1200 --> true"); + + Variant v50 = v5 != v0; + t.is (v50.type (), Variant::type_boolean, "1200 != true --> boolean"); + t.is (v50.get_bool (), true, "1200 != true --> true"); + + Variant v51 = v5 != v1; + t.is (v51.type (), Variant::type_boolean, "1200 != 42 --> boolean"); + t.is (v51.get_bool (), true, "1200 != 42 --> true"); + + Variant v52 = v5 != v2; + t.is (v52.type (), Variant::type_boolean, "1200 != 3.14 --> boolean"); + t.is (v52.get_bool (), true, "1200 != 3.14 --> true"); + + Variant v53 = v5 != v3; + t.is (v53.type (), Variant::type_boolean, "1200 != 'foo' --> boolean"); + t.is (v53.get_bool (), true, "1200 != 'foo' --> true"); + + Variant v54 = v5 != v4; + t.is (v04.type (), Variant::type_boolean, "1200 != 1234567890 --> boolean"); + t.is (v04.get_bool (), true, "1200 != 1234567890 --> true"); + + Variant v55 = v5 != v5; + t.is (v55.type (), Variant::type_boolean, "1200 != 1200 --> boolean"); + t.is (v55.get_bool (), false, "1200 != 1200 --> false"); + + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/test/variant_lt.t.cpp b/test/variant_lt.t.cpp new file mode 100644 index 000000000..00102de33 --- /dev/null +++ b/test/variant_lt.t.cpp @@ -0,0 +1,196 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2013 - 2014, Göteborg Bit Factory. +// +// 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. +// +// http://www.opensource.org/licenses/mit-license.php +// +//////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include +#include + +Context context; + +#define EPSILON 0.001 + +//////////////////////////////////////////////////////////////////////////////// +int main (int argc, char** argv) +{ + UnitTest t (72); + + Variant v0 (true); + Variant v1 (42); + Variant v2 (3.14); + Variant v3 ("foo"); + Variant v4 (1234567890, Variant::type_date); + Variant v5 (1200, Variant::type_duration); + + Variant v00 = v0 < v0; + t.is (v00.type (), Variant::type_boolean, "true < true --> boolean"); + t.is (v00.get_bool (), false, "true < true --> false"); + + Variant v01 = v0 < v1; + t.is (v01.type (), Variant::type_boolean, "true < 42 --> boolean"); + t.is (v01.get_bool (), true, "true < 42 --> true"); + + Variant v02 = v0 < v2; + t.is (v02.type (), Variant::type_boolean, "true < 3.14 --> boolean"); + t.is (v02.get_bool (), true, "true < 3.14 --> true"); + + Variant v03 = v0 < v3; + t.is (v03.type (), Variant::type_boolean, "true < 'foo' --> boolean"); + t.is (v03.get_bool (), false, "true < 'foo' --> false"); + + Variant v04 = v0 < v4; + t.is (v04.type (), Variant::type_boolean, "true < 1234567890 --> boolean"); + t.is (v04.get_bool (), true, "true < 1234567890 --> true"); + + Variant v05 = v0 < v5; + t.is (v05.type (), Variant::type_boolean, "true < 1200 --> boolean"); + t.is (v05.get_bool (), true, "true < 1200 --> true"); + + Variant v10 = v1 < v0; + t.is (v10.type (), Variant::type_boolean, "42 < true --> boolean"); + t.is (v10.get_bool (), false, "42 < true --> false"); + + Variant v11 = v1 < v1; + t.is (v11.type (), Variant::type_boolean, "42 < 42 --> boolean"); + t.is (v11.get_bool (), false, "42 < 42 --> false"); + + Variant v12 = v1 < v2; + t.is (v12.type (), Variant::type_boolean, "42 < 3.14 --> boolean"); + t.is (v12.get_bool (), false, "42 < 3.14 --> false"); + + Variant v13 = v1 < v3; + t.is (v13.type (), Variant::type_boolean, "42 < 'foo' --> boolean"); + t.is (v13.get_bool (), true, "42 < 'foo' --> true"); + + Variant v14 = v1 < v4; + t.is (v04.type (), Variant::type_boolean, "42 < 1234567890 --> boolean"); + t.is (v04.get_bool (), true, "42 < 1234567890 --> true"); + + Variant v15 = v1 < v5; + t.is (v15.type (), Variant::type_boolean, "42 < 1200 --> boolean"); + t.is (v15.get_bool (), true, "42 < 1200 --> true"); + + Variant v20 = v2 < v0; + t.is (v20.type (), Variant::type_boolean, "3.14 < true --> boolean"); + t.is (v20.get_bool (), false, "3.14 < true --> false"); + + Variant v21 = v2 < v1; + t.is (v21.type (), Variant::type_boolean, "3.14 < 42 --> boolean"); + t.is (v21.get_bool (), true, "3.14 < 42 --> true"); + + Variant v22 = v2 < v2; + t.is (v22.type (), Variant::type_boolean, "3.14 < 3.14 --> boolean"); + t.is (v22.get_bool (), false, "3.14 < 3.14 --> false"); + + Variant v23 = v2 < v3; + t.is (v23.type (), Variant::type_boolean, "3.14 < 'foo' --> boolean"); + t.is (v23.get_bool (), true, "3.14 < 'foo' --> true"); + + Variant v24 = v2 < v4; + t.is (v24.type (), Variant::type_boolean, "3.14 < 1234567890 --> boolean"); + t.is (v24.get_bool (), true, "3.14 < 1234567890 --> true"); + + Variant v25 = v2 < v5; + t.is (v25.type (), Variant::type_boolean, "3.14 < 1200 --> boolean"); + t.is (v25.get_bool (), true, "3.14 < 1200 --> true"); + + Variant v30 = v3 < v0; + t.is (v30.type (), Variant::type_boolean, "'foo' < true --> boolean"); + t.is (v30.get_bool (), true, "'foo' < true --> true"); + + Variant v31 = v3 < v1; + t.is (v31.type (), Variant::type_boolean, "'foo' < 42 --> boolean"); + t.is (v31.get_bool (), false, "'foo' < 42 --> false"); + + Variant v32 = v3 < v2; + t.is (v32.type (), Variant::type_boolean, "'foo' < 3.14 --> boolean"); + t.is (v32.get_bool (), false, "'foo' < 3.14 --> false"); + + Variant v33 = v3 < v3; + t.is (v33.type (), Variant::type_boolean, "'foo' < 'foo' --> boolean"); + t.is (v33.get_bool (), false, "'foo' < 'foo' --> false"); + + Variant v34 = v3 < v4; + t.is (v34.type (), Variant::type_boolean, "'foo' < 1234567890 --> boolean"); + t.is (v34.get_bool (), true, "'foo' < 1234567890 --> true"); + + Variant v35 = v3 < v5; + t.is (v35.type (), Variant::type_boolean, "'foo' < 1200 --> boolean"); + t.is (v35.get_bool (), true, "'foo' < 1200 --> true"); + + Variant v40 = v4 < v0; + t.is (v40.type (), Variant::type_boolean, "1234567890 < true --> boolean"); + t.is (v40.get_bool (), false, "1234567890 < true --> false"); + + Variant v41 = v4 < v1; + t.is (v41.type (), Variant::type_boolean, "1234567890 < 42 --> boolean"); + t.is (v41.get_bool (), false, "1234567890 < 42 --> false"); + + Variant v42 = v4 < v2; + t.is (v42.type (), Variant::type_boolean, "1234567890 < 3.14 --> boolean"); + t.is (v42.get_bool (), false, "1234567890 < 3.14 --> false"); + + Variant v43 = v4 < v3; + t.is (v43.type (), Variant::type_boolean, "1234567890 < 'foo' --> boolean"); + t.is (v43.get_bool (), false, "1234567890 < 'foo' --> false"); + + Variant v44 = v4 < v4; + t.is (v44.type (), Variant::type_boolean, "1234567890 < 1234567890 --> boolean"); + t.is (v44.get_bool (), false, "1234567890 < 1234567890 --> false"); + + Variant v45 = v4 < v5; + t.is (v45.type (), Variant::type_boolean, "1234567890 < 1200 --> boolean"); + t.is (v45.get_bool (), false, "1234567890 < 1200 --> false"); + + Variant v50 = v5 < v0; + t.is (v50.type (), Variant::type_boolean, "1200 < true --> boolean"); + t.is (v50.get_bool (), false, "1200 < true --> false"); + + Variant v51 = v5 < v1; + t.is (v51.type (), Variant::type_boolean, "1200 < 42 --> boolean"); + t.is (v51.get_bool (), false, "1200 < 42 --> false"); + + Variant v52 = v5 < v2; + t.is (v52.type (), Variant::type_boolean, "1200 < 3.14 --> boolean"); + t.is (v52.get_bool (), false, "1200 < 3.14 --> false"); + + Variant v53 = v5 < v3; + t.is (v53.type (), Variant::type_boolean, "1200 < 'foo' --> boolean"); + t.is (v53.get_bool (), false, "1200 < 'foo' --> false"); + + Variant v54 = v5 < v4; + t.is (v54.type (), Variant::type_boolean, "1200 < 1234567890 --> boolean"); + t.is (v54.get_bool (), true, "1200 < 1234567890 --> true"); + + Variant v55 = v5 < v5; + t.is (v55.type (), Variant::type_boolean, "1200 < 1200 --> boolean"); + t.is (v55.get_bool (), false, "1200 < 1200 --> false"); + + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/test/variant_lte.t.cpp b/test/variant_lte.t.cpp new file mode 100644 index 000000000..92515d05e --- /dev/null +++ b/test/variant_lte.t.cpp @@ -0,0 +1,196 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2013 - 2014, Göteborg Bit Factory. +// +// 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. +// +// http://www.opensource.org/licenses/mit-license.php +// +//////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include +#include + +Context context; + +#define EPSILON 0.001 + +//////////////////////////////////////////////////////////////////////////////// +int main (int argc, char** argv) +{ + UnitTest t (72); + + Variant v0 (true); + Variant v1 (42); + Variant v2 (3.14); + Variant v3 ("foo"); + Variant v4 (1234567890, Variant::type_duration); + Variant v5 (1200, Variant::type_duration); + + Variant v00 = v0 <= v0; + t.is (v00.type (), Variant::type_boolean, "true <= true --> boolean"); + t.is (v00.get_bool (), true, "true <= true --> true"); + + Variant v01 = v0 <= v1; + t.is (v01.type (), Variant::type_boolean, "true <= 42 --> boolean"); + t.is (v01.get_bool (), true, "true <= 42 --> true"); + + Variant v02 = v0 <= v2; + t.is (v02.type (), Variant::type_boolean, "true <= 3.14 --> boolean"); + t.is (v02.get_bool (), true, "true <= 3.14 --> true"); + + Variant v03 = v0 <= v3; + t.is (v03.type (), Variant::type_boolean, "true <= 'foo' --> boolean"); + t.is (v03.get_bool (), false, "true <= 'foo' --> false"); + + Variant v04 = v0 <= v4; + t.is (v04.type (), Variant::type_boolean, "true <= 1234567890 --> boolean"); + t.is (v04.get_bool (), true, "true <= 1234567890 --> true"); + + Variant v05 = v0 <= v5; + t.is (v05.type (), Variant::type_boolean, "true <= 1200 --> boolean"); + t.is (v05.get_bool (), true, "true <= 1200 --> true"); + + Variant v10 = v1 <= v0; + t.is (v10.type (), Variant::type_boolean, "42 <= true --> boolean"); + t.is (v10.get_bool (), false, "42 <= true --> false"); + + Variant v11 = v1 <= v1; + t.is (v11.type (), Variant::type_boolean, "42 <= 42 --> boolean"); + t.is (v11.get_bool (), true, "42 <= 42 --> true"); + + Variant v12 = v1 <= v2; + t.is (v12.type (), Variant::type_boolean, "42 <= 3.14 --> boolean"); + t.is (v12.get_bool (), false, "42 <= 3.14 --> false"); + + Variant v13 = v1 <= v3; + t.is (v13.type (), Variant::type_boolean, "42 <= 'foo' --> boolean"); + t.is (v13.get_bool (), true, "42 <= 'foo' --> true"); + + Variant v14 = v1 <= v4; + t.is (v04.type (), Variant::type_boolean, "42 <= 1234567890 --> boolean"); + t.is (v04.get_bool (), true, "42 <= 1234567890 --> true"); + + Variant v15 = v1 <= v5; + t.is (v15.type (), Variant::type_boolean, "42 <= 1200 --> boolean"); + t.is (v15.get_bool (), true, "42 <= 1200 --> true"); + + Variant v20 = v2 <= v0; + t.is (v20.type (), Variant::type_boolean, "3.14 <= true --> boolean"); + t.is (v20.get_bool (), false, "3.14 <= true --> false"); + + Variant v21 = v2 <= v1; + t.is (v21.type (), Variant::type_boolean, "3.14 <= 42 --> boolean"); + t.is (v21.get_bool (), true, "3.14 <= 42 --> true"); + + Variant v22 = v2 <= v2; + t.is (v22.type (), Variant::type_boolean, "3.14 <= 3.14 --> boolean"); + t.is (v22.get_bool (), true, "3.14 <= 3.14 --> true"); + + Variant v23 = v2 <= v3; + t.is (v23.type (), Variant::type_boolean, "3.14 <= 'foo' --> boolean"); + t.is (v23.get_bool (), true, "3.14 <= 'foo' --> true"); + + Variant v24 = v2 <= v4; + t.is (v24.type (), Variant::type_boolean, "3.14 <= 1234567890 --> boolean"); + t.is (v24.get_bool (), true, "3.14 <= 1234567890 --> true"); + + Variant v25 = v2 <= v5; + t.is (v25.type (), Variant::type_boolean, "3.14 <= 1200 --> boolean"); + t.is (v25.get_bool (), true, "3.14 <= 1200 --> true"); + + Variant v30 = v3 <= v0; + t.is (v30.type (), Variant::type_boolean, "'foo' <= true --> boolean"); + t.is (v30.get_bool (), true, "'foo' <= true --> true"); + + Variant v31 = v3 <= v1; + t.is (v31.type (), Variant::type_boolean, "'foo' <= 42 --> boolean"); + t.is (v31.get_bool (), false, "'foo' <= 42 --> false"); + + Variant v32 = v3 <= v2; + t.is (v32.type (), Variant::type_boolean, "'foo' <= 3.14 --> boolean"); + t.is (v32.get_bool (), false, "'foo' <= 3.14 --> false"); + + Variant v33 = v3 <= v3; + t.is (v33.type (), Variant::type_boolean, "'foo' <= 'foo' --> boolean"); + t.is (v33.get_bool (), true, "'foo' <= 'foo' --> true"); + + Variant v34 = v3 <= v4; + t.is (v34.type (), Variant::type_boolean, "'foo' <= 1234567890 --> boolean"); + t.is (v34.get_bool (), true, "'foo' <= 1234567890 --> true"); + + Variant v35 = v3 <= v5; + t.is (v35.type (), Variant::type_boolean, "'foo' <= 1200 --> boolean"); + t.is (v35.get_bool (), true, "'foo' <= 1200 --> true"); + + Variant v40 = v4 <= v0; + t.is (v40.type (), Variant::type_boolean, "1234567890 <= true --> boolean"); + t.is (v40.get_bool (), false, "1234567890 <= true --> false"); + + Variant v41 = v4 <= v1; + t.is (v41.type (), Variant::type_boolean, "1234567890 <= 42 --> boolean"); + t.is (v41.get_bool (), false, "1234567890 <= 42 --> false"); + + Variant v42 = v4 <= v2; + t.is (v42.type (), Variant::type_boolean, "1234567890 <= 3.14 --> boolean"); + t.is (v42.get_bool (), false, "1234567890 <= 3.14 --> false"); + + Variant v43 = v4 <= v3; + t.is (v43.type (), Variant::type_boolean, "1234567890 <= 'foo' --> boolean"); + t.is (v43.get_bool (), false, "1234567890 <= 'foo' --> false"); + + Variant v44 = v4 <= v4; + t.is (v44.type (), Variant::type_boolean, "1234567890 <= 1234567890 --> boolean"); + t.is (v44.get_bool (), true, "1234567890 <= 1234567890 --> true"); + + Variant v45 = v4 <= v5; + t.is (v45.type (), Variant::type_boolean, "1234567890 <= 1200 --> boolean"); + t.is (v45.get_bool (), false, "1234567890 <= 1200 --> false"); + + Variant v50 = v5 <= v0; + t.is (v50.type (), Variant::type_boolean, "1200 <= true --> boolean"); + t.is (v50.get_bool (), false, "1200 <= true --> false"); + + Variant v51 = v5 <= v1; + t.is (v51.type (), Variant::type_boolean, "1200 <= 42 --> boolean"); + t.is (v51.get_bool (), false, "1200 <= 42 --> false"); + + Variant v52 = v5 <= v2; + t.is (v52.type (), Variant::type_boolean, "1200 <= 3.14 --> boolean"); + t.is (v52.get_bool (), false, "1200 <= 3.14 --> false"); + + Variant v53 = v5 <= v3; + t.is (v53.type (), Variant::type_boolean, "1200 <= 'foo' --> boolean"); + t.is (v53.get_bool (), false, "1200 <= 'foo' --> false"); + + Variant v54 = v5 <= v4; + t.is (v54.type (), Variant::type_boolean, "1200 <= 1234567890 --> boolean"); + t.is (v54.get_bool (), true, "1200 <= 1234567890 --> true"); + + Variant v55 = v5 <= v5; + t.is (v55.type (), Variant::type_boolean, "1200 <= 1200 --> boolean"); + t.is (v55.get_bool (), true, "1200 <= 1200 --> true"); + + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/test/variant_match.t.cpp b/test/variant_match.t.cpp new file mode 100644 index 000000000..c6028142b --- /dev/null +++ b/test/variant_match.t.cpp @@ -0,0 +1,299 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2013 - 2014, Göteborg Bit Factory. +// +// 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. +// +// http://www.opensource.org/licenses/mit-license.php +// +//////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include +#include + +Context context; + +#define EPSILON 0.001 + +//////////////////////////////////////////////////////////////////////////////// +int main (int argc, char** argv) +{ + UnitTest t (120); + + Variant vs0 ("untrue"); // ~ true + Variant vs1 (8421); // ~ 42 + Variant vs2 (3.14159); // ~ 3.14 + Variant vs3 ("foolish"); // ~ foo + + Variant v0 (true); + Variant v1 (42); + Variant v2 (3.14); + Variant v3 ("foo"); + Variant v4 (1234567890, Variant::type_date); + Variant v5 (1200, Variant::type_duration); + + // Interesting cases. + Variant vs00 = vs0.operator_match (v0); + t.is (vs00.type (), Variant::type_boolean, "untrue ~ true --> boolean"); + t.is (vs00.get_bool (), true, "untrue ~ true --> true"); + + Variant vs01 = vs0.operator_match (v1); + t.is (vs01.type (), Variant::type_boolean, "untrue ~ 42 --> boolean"); + t.is (vs01.get_bool (), false, "untrue ~ 42 --> false"); + + Variant vs02 = vs0.operator_match (v2); + t.is (vs02.type (), Variant::type_boolean, "untrue ~ 3.14 --> boolean"); + t.is (vs02.get_bool (), false, "untrue ~ 3.14 --> false"); + + Variant vs03 = vs0.operator_match (v3); + t.is (vs03.type (), Variant::type_boolean, "untrue ~ 'foo' --> boolean"); + t.is (vs03.get_bool (), false, "untrue ~ 'foo' --> false"); + + Variant vs04 = vs0.operator_match (v4); + t.is (vs04.type (), Variant::type_boolean, "untrue ~ 1234567890 --> boolean"); + t.is (vs04.get_bool (), false, "untrue ~ 1234567890 --> false"); + + Variant vs05 = vs0.operator_match (v5); + t.is (vs05.type (), Variant::type_boolean, "untrue ~ 1200 --> boolean"); + t.is (vs05.get_bool (), false, "untrue ~ 1200 --> false"); + + Variant vs10 = vs1.operator_match (v0); + t.is (vs10.type (), Variant::type_boolean, "8421 ~ true --> boolean"); + t.is (vs10.get_bool (), false, "8421 ~ true --> false"); + + Variant vs11 = vs1.operator_match (v1); + t.is (vs11.type (), Variant::type_boolean, "8421 ~ 42 --> boolean"); + t.is (vs11.get_bool (), true, "8421 ~ 42 --> true"); + + Variant vs12 = vs1.operator_match (v2); + t.is (vs12.type (), Variant::type_boolean, "8421 ~ 3.14 --> boolean"); + t.is (vs12.get_bool (), false, "8421 ~ 3.14 --> false"); + + Variant vs13 = vs1.operator_match (v3); + t.is (vs13.type (), Variant::type_boolean, "8421 ~ 'foo' --> boolean"); + t.is (vs13.get_bool (), false, "8421 ~ 'foo' --> false"); + + Variant vs14 = vs1.operator_match (v4); + t.is (vs14.type (), Variant::type_boolean, "8421 ~ 1234567890 --> boolean"); + t.is (vs14.get_bool (), false, "8421 ~ 1234567890 --> false"); + + Variant vs15 = vs1.operator_match (v5); + t.is (vs15.type (), Variant::type_boolean, "8421 ~ 1200 --> boolean"); + t.is (vs15.get_bool (), false, "8421 ~ 1200 --> false"); + + Variant vs20 = vs2.operator_match (v0); + t.is (vs20.type (), Variant::type_boolean, "3.14159 ~ true --> boolean"); + t.is (vs20.get_bool (), false, "3.14159 ~ true --> false"); + + Variant vs21 = vs2.operator_match (v1); + t.is (vs21.type (), Variant::type_boolean, "3.14159 ~ 42 --> boolean"); + t.is (vs21.get_bool (), false, "3.14159 ~ 42 --> false"); + + Variant vs22 = vs2.operator_match (v2); + t.is (vs22.type (), Variant::type_boolean, "3.14159 ~ 3.14 --> boolean"); + t.is (vs22.get_bool (), true, "3.14159 ~ 3.14 --> true"); + + Variant vs23 = vs2.operator_match (v3); + t.is (vs23.type (), Variant::type_boolean, "3.14159 ~ 'foo' --> boolean"); + t.is (vs23.get_bool (), false, "3.14159 ~ 'foo' --> false"); + + Variant vs24 = vs2.operator_match (v4); + t.is (vs24.type (), Variant::type_boolean, "3.14159 ~ 1234567890 --> boolean"); + t.is (vs24.get_bool (), false, "3.14159 ~ 1234567890 --> false"); + + Variant vs25 = vs2.operator_match (v5); + t.is (vs25.type (), Variant::type_boolean, "3.14159 ~ 1200 --> boolean"); + t.is (vs25.get_bool (), false, "3.14159 ~ 1200 --> false"); + + Variant vs30 = vs3.operator_match (v0); + t.is (vs30.type (), Variant::type_boolean, "foolish ~ true --> boolean"); + t.is (vs30.get_bool (), false, "foolish ~ true --> false"); + + Variant vs31 = vs3.operator_match (v1); + t.is (vs31.type (), Variant::type_boolean, "foolish ~ 42 --> boolean"); + t.is (vs31.get_bool (), false, "foolish ~ 42 --> false"); + + Variant vs32 = vs3.operator_match (v2); + t.is (vs32.type (), Variant::type_boolean, "foolish ~ 3.14 --> boolean"); + t.is (vs32.get_bool (), false, "foolish ~ 3.14 --> false"); + + Variant vs33 = vs3.operator_match (v3); + t.is (vs33.type (), Variant::type_boolean, "foolish ~ 'foo' --> boolean"); + t.is (vs33.get_bool (), true, "foolish ~ 'foo' --> true"); + + Variant vs34 = vs3.operator_match (v4); + t.is (vs34.type (), Variant::type_boolean, "foolish ~ 1234567890 --> boolean"); + t.is (vs34.get_bool (), false, "foolish ~ 1234567890 --> false"); + + Variant vs35 = vs3.operator_match (v5); + t.is (vs35.type (), Variant::type_boolean, "foolish ~ 1200 --> boolean"); + t.is (vs35.get_bool (), false, "foolish ~ 1200 --> false"); + + // Exhaustive comparisons. + Variant v00 = v0.operator_match (v0); + t.is (v00.type (), Variant::type_boolean, "true ~ true --> boolean"); + t.is (v00.get_bool (), true, "true ~ true --> true"); + + Variant v01 = v0.operator_match (v1); + t.is (v01.type (), Variant::type_boolean, "true ~ 42 --> boolean"); + t.is (v01.get_bool (), false, "true ~ 42 --> false"); + + Variant v02 = v0.operator_match (v2); + t.is (v02.type (), Variant::type_boolean, "true ~ 3.14 --> boolean"); + t.is (v02.get_bool (), false, "true ~ 3.14 --> false"); + + Variant v03 = v0.operator_match (v3); + t.is (v03.type (), Variant::type_boolean, "true ~ 'foo' --> boolean"); + t.is (v03.get_bool (), false, "true ~ 'foo' --> false"); + + Variant v04 = v0.operator_match (v4); + t.is (v04.type (), Variant::type_boolean, "true ~ 1234567890 --> boolean"); + t.is (v04.get_bool (), false, "true ~ 1234567890 --> false"); + + Variant v05 = v0.operator_match (v5); + t.is (v05.type (), Variant::type_boolean, "true ~ 1200 --> boolean"); + t.is (v05.get_bool (), false, "true ~ 1200 --> false"); + + Variant v10 = v1.operator_match (v0); + t.is (v10.type (), Variant::type_boolean, "42 ~ true --> boolean"); + t.is (v10.get_bool (), false, "42 ~ true --> false"); + + Variant v11 = v1.operator_match (v1); + t.is (v11.type (), Variant::type_boolean, "42 ~ 42 --> boolean"); + t.is (v11.get_bool (), true, "42 ~ 42 --> true"); + + Variant v12 = v1.operator_match (v2); + t.is (v12.type (), Variant::type_boolean, "42 ~ 3.14 --> boolean"); + t.is (v12.get_bool (), false, "42 ~ 3.14 --> false"); + + Variant v13 = v1.operator_match (v3); + t.is (v13.type (), Variant::type_boolean, "42 ~ 'foo' --> boolean"); + t.is (v13.get_bool (), false, "42 ~ 'foo' --> false"); + + Variant v14 = v1.operator_match (v4); + t.is (v04.type (), Variant::type_boolean, "42 ~ 1234567890 --> boolean"); + t.is (v04.get_bool (), false, "42 ~ 1234567890 --> false"); + + Variant v15 = v1.operator_match (v5); + t.is (v15.type (), Variant::type_boolean, "42 ~ 1200 --> boolean"); + t.is (v15.get_bool (), false, "42 ~ 1200 --> false"); + + Variant v20 = v2.operator_match (v0); + t.is (v20.type (), Variant::type_boolean, "3.14 ~ true --> boolean"); + t.is (v20.get_bool (), false, "3.14 ~ true --> false"); + + Variant v21 = v2.operator_match (v1); + t.is (v21.type (), Variant::type_boolean, "3.14 ~ 42 --> boolean"); + t.is (v21.get_bool (), false, "3.14 ~ 42 --> false"); + + Variant v22 = v2.operator_match (v2); + t.is (v22.type (), Variant::type_boolean, "3.14 ~ 3.14 --> boolean"); + t.is (v22.get_bool (), true, "3.14 ~ 3.14 --> true"); + + Variant v23 = v2.operator_match (v3); + t.is (v23.type (), Variant::type_boolean, "3.14 ~ 'foo' --> boolean"); + t.is (v23.get_bool (), false, "3.14 ~ 'foo' --> false"); + + Variant v24 = v2.operator_match (v4); + t.is (v24.type (), Variant::type_boolean, "3.14 ~ 1234567890 --> boolean"); + t.is (v24.get_bool (), false, "3.14 ~ 1234567890 --> false"); + + Variant v25 = v2.operator_match (v5); + t.is (v25.type (), Variant::type_boolean, "3.14 ~ 1200 --> boolean"); + t.is (v25.get_bool (), false, "3.14 ~ 1200 --> false"); + + Variant v30 = v3.operator_match (v0); + t.is (v30.type (), Variant::type_boolean, "'foo' ~ true --> boolean"); + t.is (v30.get_bool (), false, "'foo' ~ true --> false"); + + Variant v31 = v3.operator_match (v1); + t.is (v31.type (), Variant::type_boolean, "'foo' ~ 42 --> boolean"); + t.is (v31.get_bool (), false, "'foo' ~ 42 --> false"); + + Variant v32 = v3.operator_match (v2); + t.is (v32.type (), Variant::type_boolean, "'foo' ~ 3.14 --> boolean"); + t.is (v32.get_bool (), false, "'foo' ~ 3.14 --> false"); + + Variant v33 = v3.operator_match (v3); + t.is (v33.type (), Variant::type_boolean, "'foo' ~ 'foo' --> boolean"); + t.is (v33.get_bool (), true, "'foo' ~ 'foo' --> true"); + + Variant v34 = v3.operator_match (v4); + t.is (v34.type (), Variant::type_boolean, "'foo' ~ 1234567890 --> boolean"); + t.is (v34.get_bool (), false, "'foo' ~ 1234567890 --> false"); + + Variant v35 = v3.operator_match (v5); + t.is (v35.type (), Variant::type_boolean, "'foo' ~ 1200 --> boolean"); + t.is (v35.get_bool (), false, "'foo' ~ 1200 --> false"); + + Variant v40 = v4.operator_match (v0); + t.is (v40.type (), Variant::type_boolean, "1234567890 ~ true --> boolean"); + t.is (v40.get_bool (), false, "1234567890 ~ true --> false"); + + Variant v41 = v4.operator_match (v1); + t.is (v41.type (), Variant::type_boolean, "1234567890 ~ 42 --> boolean"); + t.is (v41.get_bool (), false, "1234567890 ~ 42 --> false"); + + Variant v42 = v4.operator_match (v2); + t.is (v42.type (), Variant::type_boolean, "1234567890 ~ 3.14 --> boolean"); + t.is (v42.get_bool (), false, "1234567890 ~ 3.14 --> false"); + + Variant v43 = v4.operator_match (v3); + t.is (v43.type (), Variant::type_boolean, "1234567890 ~ 'foo' --> boolean"); + t.is (v43.get_bool (), false, "1234567890 ~ 'foo' --> false"); + + Variant v44 = v4.operator_match (v4); + t.is (v44.type (), Variant::type_boolean, "1234567890 ~ 1234567890 --> boolean"); + t.is (v44.get_bool (), true, "1234567890 ~ 1234567890 --> true"); + + Variant v45 = v4.operator_match (v5); + t.is (v45.type (), Variant::type_boolean, "1234567890 ~ 1200 --> boolean"); + t.is (v45.get_bool (), false, "1234567890 ~ 1200 --> false"); + + Variant v50 = v5.operator_match (v0); + t.is (v50.type (), Variant::type_boolean, "1200 ~ true --> boolean"); + t.is (v50.get_bool (), false, "1200 ~ true --> false"); + + Variant v51 = v5.operator_match (v1); + t.is (v51.type (), Variant::type_boolean, "1200 ~ 42 --> boolean"); + t.is (v51.get_bool (), false, "1200 ~ 42 --> false"); + + Variant v52 = v5.operator_match (v2); + t.is (v52.type (), Variant::type_boolean, "1200 ~ 3.14 --> boolean"); + t.is (v52.get_bool (), false, "1200 ~ 3.14 --> false"); + + Variant v53 = v5.operator_match (v3); + t.is (v53.type (), Variant::type_boolean, "1200 ~ 'foo' --> boolean"); + t.is (v53.get_bool (), false, "1200 ~ 'foo' --> false"); + + Variant v54 = v5.operator_match (v4); + t.is (v04.type (), Variant::type_boolean, "1200 ~ 1234567890 --> boolean"); + t.is (v04.get_bool (), false, "1200 ~ 1234567890 --> false"); + + Variant v55 = v5.operator_match (v5); + t.is (v55.type (), Variant::type_boolean, "1200 ~ 1200 --> boolean"); + t.is (v55.get_bool (), true, "1200 ~ 1200 --> true"); + + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/test/variant_math.t.cpp b/test/variant_math.t.cpp new file mode 100644 index 000000000..764686b06 --- /dev/null +++ b/test/variant_math.t.cpp @@ -0,0 +1,49 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2013 - 2014, Göteborg Bit Factory. +// +// 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. +// +// http://www.opensource.org/licenses/mit-license.php +// +//////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include +#include + +Context context; + +#define EPSILON 0.001 + +//////////////////////////////////////////////////////////////////////////////// +int main (int argc, char** argv) +{ + UnitTest t (1); + + Variant v0 (10.0); + v0.sqrt (); + t.is (v0.get_real (), 3.1622, EPSILON, "math sqrt 10 -> 3.1622"); + + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/test/variant_modulo.t.cpp b/test/variant_modulo.t.cpp new file mode 100644 index 000000000..c5d973f0d --- /dev/null +++ b/test/variant_modulo.t.cpp @@ -0,0 +1,200 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2013 - 2014, Göteborg Bit Factory. +// +// 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. +// +// http://www.opensource.org/licenses/mit-license.php +// +//////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include +#include + +Context context; + +#define EPSILON 0.0001 + +//////////////////////////////////////////////////////////////////////////////// +int main (int argc, char** argv) +{ + UnitTest t (40); + + Variant v0 (true); + Variant v1 (42); + Variant v2 (3.14); + Variant v3 ("foo"); + Variant v4 (1234567890, Variant::type_date); + Variant v5 (1200, Variant::type_duration); + + // boolean / boolean -> ERROR + try {Variant v00 = v0 % v0; t.fail ("true % true --> error");} + catch (...) {t.pass ("true % true --> error");} + + // boolean / integer -> ERROR + try {Variant v01 = v0 % v1; t.fail ("true % 42 --> error");} + catch (...) {t.pass ("true % 42 --> error");} + + // boolean / real -> ERROR + try {Variant v02 = v0 % v2; t.fail ("true % 3.14 --> error");} + catch (...) {t.pass ("true % 3.14 --> error");} + + // boolean / string -> ERROR + try {Variant v03 = v0 % v3; t.fail ("true % foo --> error");} + catch (...) {t.pass ("true % foo --> error");} + + // boolean / date -> ERROR + try {Variant v04 = v0 % v4; t.fail ("true % 1234567890 --> error");} + catch (...) {t.pass ("true % 1234567890 --> error");} + + // boolean / duration -> ERROR + try {Variant v05 = v0 % v5; t.fail ("true % 1200 --> error");} + catch (...) {t.pass ("true % 1200 --> error");} + + // integer / boolean -> ERROR + try {Variant v10 = v1 % v0; t.fail ("42 % true --> error");} + catch (...) {t.pass ("42 % true --> error");} + + // integer / integer -> integer + Variant v11 = v1 % v1; + t.is (v11.type (), Variant::type_integer, "42 % 42 --> integer"); + t.is (v11.get_integer (), 0, "42 % 42 --> 0"); + + // integer / real -> real + Variant v12 = v1 % v2; + t.is (v12.type (), Variant::type_real, "42 % 3.14 --> real"); + t.is (v12.get_real (), 1.18, EPSILON, "42 % 3.14 --> 1.18"); + + // integer / string -> ERROR + try {Variant v13 = v1 % v3; t.fail ("42 % foo --> error");} + catch (...) {t.pass ("42 % foo --> error");} + + // integer / date -> ERROR + try {Variant v14 = v1 % v4; t.fail ("42 % 1234567890 --> error");} + catch (...) {t.pass ("42 % 1234567890 --> error");} + + // integer / duration -> duration + try {Variant v15 = v1 % v5; t.fail ("42 % 1200 --> error");} + catch (...) {t.pass ("42 % 1200 --> error");} + + // real / boolean -> ERROR + try {Variant v20 = v2 % v0; t.fail ("3.14 % true --> error");} + catch (...) {t.pass ("3.14 % true --> error");} + + // real / integer -> real + Variant v21 = v2 % v1; + t.is (v21.type (), Variant::type_real, "3.14 % 42 --> real"); + t.is (v21.get_real (), 3.14, EPSILON, "3.14 % 42 --> 3.14"); + + // real / real -> real + Variant v22 = v2 % v2; + t.is (v22.type (), Variant::type_real, "3.14 % 3.14 --> real"); + t.is (v22.get_real (), 0.0, EPSILON, "3.14 % 3.14 --> 0.0"); + + // real / string -> error + try {Variant v23 = v2 % v3; t.fail ("3.14 % foo --> error");} + catch (...) {t.pass ("3.14 % foo --> error");} + + // real / date -> error + try {Variant v24 = v2 % v4; t.fail ("3.14 % 1234567890 --> error");} + catch (...) {t.pass ("3.14 % 1234567890 --> error");} + + // real / duration -> duration + try {Variant v25 = v2 % v5; t.fail ("3.14 % 1200 --> error");} + catch (...) {t.pass ("3.14 % 1200 --> error");} + + // string / boolean -> ERROR + try {Variant v30 = v3 % v0; t.fail ("foo % true --> error");} + catch (...) {t.pass ("foo % true --> error");} + + // string / integer -> ERROR + try {Variant v31 = v3 % v1; t.fail ("foo % 42 --> error");} + catch (...) {t.pass ("foo % 42 --> error");} + + // string / real -> ERROR + try {Variant v32 = v3 % v2; t.fail ("foo % 3.14 --> error");} + catch (...) {t.pass ("foo % 3.14 --> error");} + + // string / string -> ERROR + try {Variant v33 = v3 % v3; t.fail ("foo % foo --> error");} + catch (...) {t.pass ("foo % foo --> error");} + + // string / date -> ERROR + try {Variant v34 = v3 % v4; t.fail ("foo % 1234567890 --> error");} + catch (...) {t.pass ("foo % 1234567890 --> error");} + + // string / duration -> ERROR + try {Variant v35 = v3 % v5; t.fail ("foo % 1200 --> error");} + catch (...) {t.pass ("foo % 1200 --> error");} + + // date / boolean -> ERROR + try {Variant v40 = v4 % v0; t.fail ("1234567890 % true --> error");} + catch (...) {t.pass ("1234567890 % true --> error");} + + // date / integer -> ERROR + try {Variant v41 = v4 % v1; t.fail ("1234567890 % 42 --> error");} + catch (...) {t.pass ("1234567890 % 42 --> error");} + + // date / real -> ERROR + try {Variant v42 = v4 % v2; t.fail ("1234567890 % 3.14 --> error");} + catch (...) {t.pass ("1234567890 % 3.14 --> error");} + + // date / string -> ERROR + try {Variant v43 = v4 % v3; t.fail ("1234567890 % foo --> error");} + catch (...) {t.pass ("1234567890 % foo --> error");} + + // date / date -> ERROR + try {Variant v44 = v4 % v4; t.fail ("1234567890 % 1234567890 --> error");} + catch (...) {t.pass ("1234567890 % 1234567890 --> error");} + + // date / duration -> ERROR + try {Variant v45 = v4 % v5; t.fail ("1234567890 % 1200 --> error");} + catch (...) {t.pass ("1234567890 % 1200 --> error");} + + // duration / boolean -> ERROR + try {Variant v50 = v5 % v0; t.fail ("1200 % true --> error");} + catch (...) {t.pass ("1200 % true --> error");} + + // duration / integer -> ERROR + try {Variant v51 = v5 % v1; t.fail ("1200 % 42 --> error");} + catch (...) {t.pass ("1200 % 42 --> error");} + + // duration / real -> ERROR + try {Variant v52 = v5 % v2; t.fail ("1200 % 3.14 --> error");} + catch (...) {t.pass ("1200 % 3.14 --> error");} + + // duration / string -> ERROR + try {Variant v53 = v5 % v3; t.fail ("1200 % foo --> error");} + catch (...) {t.pass ("1200 % foo --> error");} + + // duration / date -> ERROR + try {Variant v54 = v5 % v4; t.fail ("1200 % 1234567890 --> error");} + catch (...) {t.pass ("1200 % 1234567890 --> error");} + + // duration / duration -> ERROR + try {Variant v55 = v5 % v5; t.fail ("1200 % 1200 --> error");} + catch (...) {t.pass ("1200 % 1200 --> error");} + + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/test/variant_multiply.t.cpp b/test/variant_multiply.t.cpp new file mode 100644 index 000000000..1e54041de --- /dev/null +++ b/test/variant_multiply.t.cpp @@ -0,0 +1,215 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2013 - 2014, Göteborg Bit Factory. +// +// 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. +// +// http://www.opensource.org/licenses/mit-license.php +// +//////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include +#include + +Context context; + +#define EPSILON 0.0001 + +//////////////////////////////////////////////////////////////////////////////// +int main (int argc, char** argv) +{ + UnitTest t (54); + + Variant v0 (true); + Variant v1 (42); + Variant v2 (3.14); + Variant v3 ("foo"); + Variant v4 (1234567890, Variant::type_date); + Variant v5 (1200, Variant::type_duration); + + // boolean * boolean -> ERROR + try {Variant v00 = v0 * v0; t.fail ("true * true --> error");} + catch (...) {t.pass ("true * true --> error");} + + // boolean * integer -> integer + Variant v01 = v0 * v1; + t.is (v01.type (), Variant::type_integer, "true * 42 --> integer"); + t.is (v01.get_integer (), 42, "true * 42 --> 42"); + + // boolean * real -> real + Variant v02 = v0 * v2; + t.is (v02.type (), Variant::type_real, "true * 3.14 --> real"); + t.is (v02.get_real (), 3.14, EPSILON, "true * 3.14 --> 3.14"); + + // boolean * string -> string + Variant v03 = v0 * v3; + t.is (v03.type (), Variant::type_string, "true * foo --> real"); + t.is (v03.get_string (), "foo", "true * foo --> foo"); + + // boolean * date -> ERROR + try {Variant v04 = v0 * v4; t.fail ("true * 1234567890 --> error");} + catch (...) {t.pass ("true * 1234567890 --> error");} + + // boolean * duration -> duration + Variant v05 = v0 * v5; + t.is (v05.type (), Variant::type_duration, "true * 1200 --> duration"); + t.is (v05.get_duration (), 1200, "true * 1200 --> 1200"); + + // integer * boolean -> integer + Variant v10 = v1 * v0; + t.is (v10.type (), Variant::type_integer, "42 * true --> integer"); + t.is (v10.get_integer (), 42, "42 * true --> 42"); + + // integer * integer -> integer + Variant v11 = v1 * v1; + t.is (v11.type (), Variant::type_integer, "42 * 42 --> integer"); + t.is (v11.get_integer (), 1764, "42 * 42 --> 1764"); + + // integer * real -> real + Variant v12 = v1 * v2; + t.is (v12.type (), Variant::type_real, "42 * 3.14 --> real"); + t.is (v12.get_real (), 131.88, EPSILON, "42 * 3.14 --> 131.88"); + + // integer * string -> string + Variant v13 = v1 * v3; + t.is (v13.type (), Variant::type_string, "42 * foo --> string"); + t.is (v13.get_string ().substr (0, 10), "foofoofoof", + "42 * foo --> foofoofoofoo..."); + // integer * date -> error + try {Variant v14 = v1 * v4; t.fail ("42 * 1234567890 --> error");} + catch (...) {t.pass ("42 * 1234567890 --> error");} + + // integer * duration -> duration + Variant v15 = v1 * v5; + t.is (v15.type (), Variant::type_duration, "42 * 1200 --> duration"); + t.is (v15.get_duration (), 50400, "42 * 1200 --> 50400"); + + // real * boolean -> real + Variant v20 = v2 * v0; + t.is (v20.type (), Variant::type_real, "3.14 * true --> real"); + t.is (v20.get_real (), 3.14, EPSILON, "3.14 * true --> 3.14"); + + // real * integer -> real + Variant v21 = v2 * v1; + t.is (v21.type (), Variant::type_real, "3.14 * 42 --> real"); + t.is (v21.get_real (), 131.88, EPSILON, "3.14 * 42 --> 131.88"); + + // real * real -> real + Variant v22 = v2 * v2; + t.is (v22.type (), Variant::type_real, "3.14 * 3.14 --> real"); + t.is (v22.get_real (), 9.8596, EPSILON, "3.14 * 3.14 --> 9.8596"); + + // real * string -> error + try {Variant v23 = v2 * v3; t.fail ("3.14 * foo --> error");} + catch (...) {t.pass ("3.14 * foo --> error");} + + // real * date -> error + try {Variant v24 = v2 * v4; t.fail ("3.14 * 1234567890 --> error");} + catch (...) {t.pass ("3.14 * 1234567890 --> error");} + + // real * duration -> duration + Variant v25 = v2 * v5; + t.is (v25.type (), Variant::type_duration, "3.14 * 1200 --> duration"); + t.is (v25.get_duration (), 3768, "3.14 * 1200 --> 3768"); + + // string * boolean -> string + Variant v30 = v3 * v0; + t.is (v30.type (), Variant::type_string, "foo * true --> real"); + t.is (v30.get_string (), "foo", "foo * true --> foo"); + + // string * integer -> string + Variant v31 = v3 * v1; + t.is (v31.type (), Variant::type_string, "foo * 42 --> string"); + t.is (v31.get_string ().substr (0, 10), "foofoofoof", + "foo * 42 --> foofoofoof..."); + + // string * real -> string + try {Variant v32 = v3 * v2; t.fail ("foo * 3.14 --> error");} + catch (...) {t.pass ("foo * 3.14 --> error");} + + // string * string -> string + try {Variant v33 = v3 * v3; t.fail ("foo * foo --> error");} + catch (...) {t.pass ("foo * foo --> error");} + + // string * date -> string + try {Variant v34 = v3 * v4; t.fail ("foo * 1234567890 --> error");} + catch (...) {t.pass ("foo * 1234567890 --> error");} + + // string * duration -> string + try {Variant v35 = v3 * v5; t.fail ("foo * 1200 --> error");} + catch (...) {t.pass ("foo * 1200 --> error");} + + // date * boolean -> ERROR + try {Variant v40 = v4 * v0; t.fail ("1234567890 * true --> error");} + catch (...) {t.pass ("1234567890 * true --> error");} + + // date * integer -> ERROR + try {Variant v41 = v4 * v1; t.fail ("1234567890 * 42 --> error");} + catch (...) {t.pass ("1234567890 * 42 --> error");} + + // date * real -> ERROR + try {Variant v42 = v4 * v2; t.fail ("1234567890 * 3.14 --> error");} + catch (...) {t.pass ("1234567890 * 3.14 --> error");} + + // date * string -> ERROR + try {Variant v43 = v4 * v3; t.fail ("1234567890 * foo --> error");} + catch (...) {t.pass ("1234567890 * foo --> error");} + + // date * date -> ERROR + try {Variant v44 = v4 * v4; t.fail ("1234567890 * 1234567890 --> error");} + catch (...) {t.pass ("1234567890 * 1234567890 --> error");} + + // date * duration -> ERROR + try {Variant v45 = v4 * v5; t.fail ("1234567890 * 1200 --> error");} + catch (...) {t.pass ("1234567890 * 1200 --> error");} + + // duration * boolean -> duration + Variant v50 = v5 * v0; + t.is (v50.type (), Variant::type_duration, "1200 * true --> duration"); + t.is (v50.get_duration (), 1200, "1200 * true --> 1200"); + + // duration * integer -> duration + Variant v51 = v5 * v1; + t.is (v51.type (), Variant::type_duration, "1200 * 42 --> duration"); + t.is (v51.get_duration (), 50400, "1200 * 42 --> 50400"); + + // duration * real -> duration + Variant v52 = v5 * v2; + t.is (v52.type (), Variant::type_duration, "1200 * 3.14 --> duration"); + t.is (v52.get_duration (), 3768, "1200 * 3.14 --> 3768"); + + // duration * string -> string + try {Variant v53 = v5 * v3; t.fail ("1200 * foo --> error");} + catch (...) {t.pass ("1200 * foo --> error");} + + // duration * date -> date + try {Variant v54 = v5 * v4; t.fail ("1200 * 1234567890 --> error");} + catch (...) {t.pass ("1200 * 1234567890 --> error");} + + // duration * duration -> duration + try {Variant v55 = v5 * v5; t.fail ("1200 * 1200 --> error");} + catch (...) {t.pass ("1200 * 1200 --> error");} + + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/test/variant_nomatch.t.cpp b/test/variant_nomatch.t.cpp new file mode 100644 index 000000000..53f0c5288 --- /dev/null +++ b/test/variant_nomatch.t.cpp @@ -0,0 +1,299 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2013 - 2014, Göteborg Bit Factory. +// +// 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. +// +// http://www.opensource.org/licenses/mit-license.php +// +//////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include +#include + +Context context; + +#define EPSILON 0.001 + +//////////////////////////////////////////////////////////////////////////////// +int main (int argc, char** argv) +{ + UnitTest t (120); + + Variant vs0 ("untrue"); // !~ true + Variant vs1 (8421); // !~ 42 + Variant vs2 (3.14159); // !~ 3.14 + Variant vs3 ("foolish"); // !~ foo + + Variant v0 (true); + Variant v1 (42); + Variant v2 (3.14); + Variant v3 ("foo"); + Variant v4 (1234567890, Variant::type_date); + Variant v5 (1200, Variant::type_duration); + + // Interesting cases. + Variant vs00 = vs0.operator_nomatch (v0); + t.is (vs00.type (), Variant::type_boolean, "untrue !~ true --> boolean"); + t.is (vs00.get_bool (), false, "untrue !~ true --> false"); + + Variant vs01 = vs0.operator_nomatch (v1); + t.is (vs01.type (), Variant::type_boolean, "untrue !~ 42 --> boolean"); + t.is (vs01.get_bool (), true, "untrue !~ 42 --> true"); + + Variant vs02 = vs0.operator_nomatch (v2); + t.is (vs02.type (), Variant::type_boolean, "untrue !~ 3.14 --> boolean"); + t.is (vs02.get_bool (), true, "untrue !~ 3.14 --> true"); + + Variant vs03 = vs0.operator_nomatch (v3); + t.is (vs03.type (), Variant::type_boolean, "untrue !~ 'foo' --> boolean"); + t.is (vs03.get_bool (), true, "untrue !~ 'foo' --> true"); + + Variant vs04 = vs0.operator_nomatch (v4); + t.is (vs04.type (), Variant::type_boolean, "untrue !~ 1234567890 --> boolean"); + t.is (vs04.get_bool (), true, "untrue !~ 1234567890 --> true"); + + Variant vs05 = vs0.operator_nomatch (v5); + t.is (vs05.type (), Variant::type_boolean, "untrue !~ 1200 --> boolean"); + t.is (vs05.get_bool (), true, "untrue !~ 1200 --> true"); + + Variant vs10 = vs1.operator_nomatch (v0); + t.is (vs10.type (), Variant::type_boolean, "8421 !~ true --> boolean"); + t.is (vs10.get_bool (), true, "8421 !~ true --> true"); + + Variant vs11 = vs1.operator_nomatch (v1); + t.is (vs11.type (), Variant::type_boolean, "8421 !~ 42 --> boolean"); + t.is (vs11.get_bool (), false, "8421 !~ 42 --> false"); + + Variant vs12 = vs1.operator_nomatch (v2); + t.is (vs12.type (), Variant::type_boolean, "8421 !~ 3.14 --> boolean"); + t.is (vs12.get_bool (), true, "8421 !~ 3.14 --> true"); + + Variant vs13 = vs1.operator_nomatch (v3); + t.is (vs13.type (), Variant::type_boolean, "8421 !~ 'foo' --> boolean"); + t.is (vs13.get_bool (), true, "8421 !~ 'foo' --> true"); + + Variant vs14 = vs1.operator_nomatch (v4); + t.is (vs14.type (), Variant::type_boolean, "8421 !~ 1234567890 --> boolean"); + t.is (vs14.get_bool (), true, "8421 !~ 1234567890 --> true"); + + Variant vs15 = vs1.operator_nomatch (v5); + t.is (vs15.type (), Variant::type_boolean, "8421 !~ 1200 --> boolean"); + t.is (vs15.get_bool (), true, "8421 !~ 1200 --> true"); + + Variant vs20 = vs2.operator_nomatch (v0); + t.is (vs20.type (), Variant::type_boolean, "3.14159 !~ true --> boolean"); + t.is (vs20.get_bool (), true, "3.14159 !~ true --> true"); + + Variant vs21 = vs2.operator_nomatch (v1); + t.is (vs21.type (), Variant::type_boolean, "3.14159 !~ 42 --> boolean"); + t.is (vs21.get_bool (), true, "3.14159 !~ 42 --> true"); + + Variant vs22 = vs2.operator_nomatch (v2); + t.is (vs22.type (), Variant::type_boolean, "3.14159 !~ 3.14 --> boolean"); + t.is (vs22.get_bool (), false, "3.14159 !~ 3.14 --> false"); + + Variant vs23 = vs2.operator_nomatch (v3); + t.is (vs23.type (), Variant::type_boolean, "3.14159 !~ 'foo' --> boolean"); + t.is (vs23.get_bool (), true, "3.14159 !~ 'foo' --> true"); + + Variant vs24 = vs2.operator_nomatch (v4); + t.is (vs24.type (), Variant::type_boolean, "3.14159 !~ 1234567890 --> boolean"); + t.is (vs24.get_bool (), true, "3.14159 !~ 1234567890 --> true"); + + Variant vs25 = vs2.operator_nomatch (v5); + t.is (vs25.type (), Variant::type_boolean, "3.14159 !~ 1200 --> boolean"); + t.is (vs25.get_bool (), true, "3.14159 !~ 1200 --> true"); + + Variant vs30 = vs3.operator_nomatch (v0); + t.is (vs30.type (), Variant::type_boolean, "foolish !~ true --> boolean"); + t.is (vs30.get_bool (), true, "foolish !~ true --> true"); + + Variant vs31 = vs3.operator_nomatch (v1); + t.is (vs31.type (), Variant::type_boolean, "foolish !~ 42 --> boolean"); + t.is (vs31.get_bool (), true, "foolish !~ 42 --> true"); + + Variant vs32 = vs3.operator_nomatch (v2); + t.is (vs32.type (), Variant::type_boolean, "foolish !~ 3.14 --> boolean"); + t.is (vs32.get_bool (), true, "foolish !~ 3.14 --> true"); + + Variant vs33 = vs3.operator_nomatch (v3); + t.is (vs33.type (), Variant::type_boolean, "foolish !~ 'foo' --> boolean"); + t.is (vs33.get_bool (), false, "foolish !~ 'foo' --> false"); + + Variant vs34 = vs3.operator_nomatch (v4); + t.is (vs34.type (), Variant::type_boolean, "foolish !~ 1234567890 --> boolean"); + t.is (vs34.get_bool (), true, "foolish !~ 1234567890 --> true"); + + Variant vs35 = vs3.operator_nomatch (v5); + t.is (vs35.type (), Variant::type_boolean, "foolish !~ 1200 --> boolean"); + t.is (vs35.get_bool (), true, "foolish !~ 1200 --> true"); + + // Exhaustive comparisons. + Variant v00 = v0.operator_nomatch (v0); + t.is (v00.type (), Variant::type_boolean, "true !~ true --> boolean"); + t.is (v00.get_bool (), false, "true !~ true --> false"); + + Variant v01 = v0.operator_nomatch (v1); + t.is (v01.type (), Variant::type_boolean, "true !~ 42 --> boolean"); + t.is (v01.get_bool (), true, "true !~ 42 --> true"); + + Variant v02 = v0.operator_nomatch (v2); + t.is (v02.type (), Variant::type_boolean, "true !~ 3.14 --> boolean"); + t.is (v02.get_bool (), true, "true !~ 3.14 --> true"); + + Variant v03 = v0.operator_nomatch (v3); + t.is (v03.type (), Variant::type_boolean, "true !~ 'foo' --> boolean"); + t.is (v03.get_bool (), true, "true !~ 'foo' --> true"); + + Variant v04 = v0.operator_nomatch (v4); + t.is (v04.type (), Variant::type_boolean, "true !~ 1234567890 --> boolean"); + t.is (v04.get_bool (), true, "true !~ 1234567890 --> true"); + + Variant v05 = v0.operator_nomatch (v5); + t.is (v05.type (), Variant::type_boolean, "true !~ 1200 --> boolean"); + t.is (v05.get_bool (), true, "true !~ 1200 --> true"); + + Variant v10 = v1.operator_nomatch (v0); + t.is (v10.type (), Variant::type_boolean, "42 !~ true --> boolean"); + t.is (v10.get_bool (), true, "42 !~ true --> true"); + + Variant v11 = v1.operator_nomatch (v1); + t.is (v11.type (), Variant::type_boolean, "42 !~ 42 --> boolean"); + t.is (v11.get_bool (), false, "42 !~ 42 --> false"); + + Variant v12 = v1.operator_nomatch (v2); + t.is (v12.type (), Variant::type_boolean, "42 !~ 3.14 --> boolean"); + t.is (v12.get_bool (), true, "42 !~ 3.14 --> true"); + + Variant v13 = v1.operator_nomatch (v3); + t.is (v13.type (), Variant::type_boolean, "42 !~ 'foo' --> boolean"); + t.is (v13.get_bool (), true, "42 !~ 'foo' --> true"); + + Variant v14 = v1.operator_nomatch (v4); + t.is (v04.type (), Variant::type_boolean, "42 !~ 1234567890 --> boolean"); + t.is (v04.get_bool (), true, "42 !~ 1234567890 --> true"); + + Variant v15 = v1.operator_nomatch (v5); + t.is (v15.type (), Variant::type_boolean, "42 !~ 1200 --> boolean"); + t.is (v15.get_bool (), true, "42 !~ 1200 --> true"); + + Variant v20 = v2.operator_nomatch (v0); + t.is (v20.type (), Variant::type_boolean, "3.14 !~ true --> boolean"); + t.is (v20.get_bool (), true, "3.14 !~ true --> true"); + + Variant v21 = v2.operator_nomatch (v1); + t.is (v21.type (), Variant::type_boolean, "3.14 !~ 42 --> boolean"); + t.is (v21.get_bool (), true, "3.14 !~ 42 --> true"); + + Variant v22 = v2.operator_nomatch (v2); + t.is (v22.type (), Variant::type_boolean, "3.14 !~ 3.14 --> boolean"); + t.is (v22.get_bool (), false, "3.14 !~ 3.14 --> false"); + + Variant v23 = v2.operator_nomatch (v3); + t.is (v23.type (), Variant::type_boolean, "3.14 !~ 'foo' --> boolean"); + t.is (v23.get_bool (), true, "3.14 !~ 'foo' --> true"); + + Variant v24 = v2.operator_nomatch (v4); + t.is (v24.type (), Variant::type_boolean, "3.14 !~ 1234567890 --> boolean"); + t.is (v24.get_bool (), true, "3.14 !~ 1234567890 --> true"); + + Variant v25 = v2.operator_nomatch (v5); + t.is (v25.type (), Variant::type_boolean, "3.14 !~ 1200 --> boolean"); + t.is (v25.get_bool (), true, "3.14 !~ 1200 --> true"); + + Variant v30 = v3.operator_nomatch (v0); + t.is (v30.type (), Variant::type_boolean, "'foo' !~ true --> boolean"); + t.is (v30.get_bool (), true, "'foo' !~ true --> true"); + + Variant v31 = v3.operator_nomatch (v1); + t.is (v31.type (), Variant::type_boolean, "'foo' !~ 42 --> boolean"); + t.is (v31.get_bool (), true, "'foo' !~ 42 --> true"); + + Variant v32 = v3.operator_nomatch (v2); + t.is (v32.type (), Variant::type_boolean, "'foo' !~ 3.14 --> boolean"); + t.is (v32.get_bool (), true, "'foo' !~ 3.14 --> true"); + + Variant v33 = v3.operator_nomatch (v3); + t.is (v33.type (), Variant::type_boolean, "'foo' !~ 'foo' --> boolean"); + t.is (v33.get_bool (), false, "'foo' !~ 'foo' --> false"); + + Variant v34 = v3.operator_nomatch (v4); + t.is (v34.type (), Variant::type_boolean, "'foo' !~ 1234567890 --> boolean"); + t.is (v34.get_bool (), true, "'foo' !~ 1234567890 --> true"); + + Variant v35 = v3.operator_nomatch (v5); + t.is (v35.type (), Variant::type_boolean, "'foo' !~ 1200 --> boolean"); + t.is (v35.get_bool (), true, "'foo' !~ 1200 --> true"); + + Variant v40 = v4.operator_nomatch (v0); + t.is (v40.type (), Variant::type_boolean, "1234567890 !~ true --> boolean"); + t.is (v40.get_bool (), true, "1234567890 !~ true --> true"); + + Variant v41 = v4.operator_nomatch (v1); + t.is (v41.type (), Variant::type_boolean, "1234567890 !~ 42 --> boolean"); + t.is (v41.get_bool (), true, "1234567890 !~ 42 --> true"); + + Variant v42 = v4.operator_nomatch (v2); + t.is (v42.type (), Variant::type_boolean, "1234567890 !~ 3.14 --> boolean"); + t.is (v42.get_bool (), true, "1234567890 !~ 3.14 --> true"); + + Variant v43 = v4.operator_nomatch (v3); + t.is (v43.type (), Variant::type_boolean, "1234567890 !~ 'foo' --> boolean"); + t.is (v43.get_bool (), true, "1234567890 !~ 'foo' --> true"); + + Variant v44 = v4.operator_nomatch (v4); + t.is (v44.type (), Variant::type_boolean, "1234567890 !~ 1234567890 --> boolean"); + t.is (v44.get_bool (), false, "1234567890 !~ 1234567890 --> false"); + + Variant v45 = v4.operator_nomatch (v5); + t.is (v45.type (), Variant::type_boolean, "1234567890 !~ 1200 --> boolean"); + t.is (v45.get_bool (), true, "1234567890 !~ 1200 --> true"); + + Variant v50 = v5.operator_nomatch (v0); + t.is (v50.type (), Variant::type_boolean, "1200 !~ true --> boolean"); + t.is (v50.get_bool (), true, "1200 !~ true --> true"); + + Variant v51 = v5.operator_nomatch (v1); + t.is (v51.type (), Variant::type_boolean, "1200 !~ 42 --> boolean"); + t.is (v51.get_bool (), true, "1200 !~ 42 --> true"); + + Variant v52 = v5.operator_nomatch (v2); + t.is (v52.type (), Variant::type_boolean, "1200 !~ 3.14 --> boolean"); + t.is (v52.get_bool (), true, "1200 !~ 3.14 --> true"); + + Variant v53 = v5.operator_nomatch (v3); + t.is (v53.type (), Variant::type_boolean, "1200 !~ 'foo' --> boolean"); + t.is (v53.get_bool (), true, "1200 !~ 'foo' --> true"); + + Variant v54 = v5.operator_nomatch (v4); + t.is (v04.type (), Variant::type_boolean, "1200 !~ 1234567890 --> boolean"); + t.is (v04.get_bool (), true, "1200 !~ 1234567890 --> true"); + + Variant v55 = v5.operator_nomatch (v5); + t.is (v55.type (), Variant::type_boolean, "1200 !~ 1200 --> boolean"); + t.is (v55.get_bool (), false, "1200 !~ 1200 --> false"); + + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/test/variant_not.t.cpp b/test/variant_not.t.cpp new file mode 100644 index 000000000..c2616567c --- /dev/null +++ b/test/variant_not.t.cpp @@ -0,0 +1,82 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2013 - 2014, Göteborg Bit Factory. +// +// 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. +// +// http://www.opensource.org/licenses/mit-license.php +// +//////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include +#include + +Context context; + +#define EPSILON 0.001 + +//////////////////////////////////////////////////////////////////////////////// +int main (int argc, char** argv) +{ + UnitTest t (14); + + Variant v0 (true); + Variant v1 (42); + Variant v2 (3.14); + Variant v3 ("foo"); + Variant v4 (1234567890, Variant::type_date); + Variant v5 (1200, Variant::type_duration); + + // Truth table. + Variant vFalse (false); + Variant vTrue (true); + t.is (!vFalse, true, "!false --> true"); + t.is (!vTrue, false, "!true --> false"); + + Variant v00 = ! v0; + t.is (v00.type (), Variant::type_boolean, "! true --> boolean"); + t.is (v00.get_bool (), false, "! true --> false"); + + Variant v01 = ! v1; + t.is (v01.type (), Variant::type_boolean, "! 42 --> boolean"); + t.is (v01.get_bool (), false, "! 42 --> false"); + + Variant v02 = ! v2; + t.is (v02.type (), Variant::type_boolean, "! 3.14 --> boolean"); + t.is (v02.get_bool (), false, "! 3.14 --> false"); + + Variant v03 = ! v3; + t.is (v03.type (), Variant::type_boolean, "! foo --> boolean"); + t.is (v03.get_bool (), false, "! foo --> false"); + + Variant v04 = ! v4; + t.is (v04.type (), Variant::type_boolean, "! 1234567890 --> boolean"); + t.is (v04.get_bool (), false, "! 1234567890 --> false"); + + Variant v05 = ! v5; + t.is (v05.type (), Variant::type_boolean, "! 1200 --> boolean"); + t.is (v05.get_bool (), false, "! 1200 --> false"); + + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/test/variant_or.t.cpp b/test/variant_or.t.cpp new file mode 100644 index 000000000..17db9d3f9 --- /dev/null +++ b/test/variant_or.t.cpp @@ -0,0 +1,204 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2013 - 2014, Göteborg Bit Factory. +// +// 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. +// +// http://www.opensource.org/licenses/mit-license.php +// +//////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include +#include + +Context context; + +#define EPSILON 0.001 + +//////////////////////////////////////////////////////////////////////////////// +int main (int argc, char** argv) +{ + UnitTest t (76); + + Variant v0 (true); + Variant v1 (42); + Variant v2 (3.14); + Variant v3 ("foo"); + Variant v4 (1234567890, Variant::type_date); + Variant v5 (1200, Variant::type_duration); + + // Truth table. + Variant vFalse (false); + Variant vTrue (true); + t.is (vFalse || vFalse, false, "false || false --> false"); + t.is (vFalse || vTrue, true, "false || true --> true"); + t.is (vTrue || vFalse, true, "true || false --> true"); + t.is (vTrue || vTrue, true, "true || true --> true"); + + Variant v00 = v0 || v0; + t.is (v00.type (), Variant::type_boolean, "true || true --> boolean"); + t.is (v00.get_bool (), true, "true || true --> true"); + + Variant v01 = v0 || v1; + t.is (v01.type (), Variant::type_boolean, "true || 42 --> boolean"); + t.is (v01.get_bool (), true, "true || 42 --> true"); + + Variant v02 = v0 || v2; + t.is (v02.type (), Variant::type_boolean, "true || 3.14 --> boolean"); + t.is (v02.get_bool (), true, "true || 3.14 --> true"); + + Variant v03 = v0 || v3; + t.is (v03.type (), Variant::type_boolean, "true || 'foo' --> boolean"); + t.is (v03.get_bool (), true, "true || 'foo' --> true"); + + Variant v04 = v0 || v4; + t.is (v04.type (), Variant::type_boolean, "true || 1234567890 --> boolean"); + t.is (v04.get_bool (), true, "true || 1234567890 --> true"); + + Variant v05 = v0 || v5; + t.is (v05.type (), Variant::type_boolean, "true || 1200 --> boolean"); + t.is (v05.get_bool (), true, "true || 1200 --> true"); + + Variant v10 = v1 || v0; + t.is (v10.type (), Variant::type_boolean, "42 || true --> boolean"); + t.is (v10.get_bool (), true, "42 || true --> true"); + + Variant v11 = v1 || v1; + t.is (v11.type (), Variant::type_boolean, "42 || 42 --> boolean"); + t.is (v11.get_bool (), true, "42 || 42 --> true"); + + Variant v12 = v1 || v2; + t.is (v12.type (), Variant::type_boolean, "42 || 3.14 --> boolean"); + t.is (v12.get_bool (), true, "42 || 3.14 --> true"); + + Variant v13 = v1 || v3; + t.is (v13.type (), Variant::type_boolean, "42 || 'foo' --> boolean"); + t.is (v13.get_bool (), true, "42 || 'foo' --> true"); + + Variant v14 = v1 || v4; + t.is (v04.type (), Variant::type_boolean, "42 || 1234567890 --> boolean"); + t.is (v04.get_bool (), true, "42 || 1234567890 --> true"); + + Variant v15 = v1 || v5; + t.is (v15.type (), Variant::type_boolean, "42 || 1200 --> boolean"); + t.is (v15.get_bool (), true, "42 || 1200 --> true"); + + Variant v20 = v2 || v0; + t.is (v20.type (), Variant::type_boolean, "3.14 || true --> boolean"); + t.is (v20.get_bool (), true, "3.14 || true --> true"); + + Variant v21 = v2 || v1; + t.is (v21.type (), Variant::type_boolean, "3.14 || 42 --> boolean"); + t.is (v21.get_bool (), true, "3.14 || 42 --> true"); + + Variant v22 = v2 || v2; + t.is (v22.type (), Variant::type_boolean, "3.14 || 3.14 --> boolean"); + t.is (v22.get_bool (), true, "3.14 || 3.14 --> true"); + + Variant v23 = v2 || v3; + t.is (v23.type (), Variant::type_boolean, "3.14 || 'foo' --> boolean"); + t.is (v23.get_bool (), true, "3.14 || 'foo' --> true"); + + Variant v24 = v2 || v4; + t.is (v24.type (), Variant::type_boolean, "3.14 || 1234567890 --> boolean"); + t.is (v24.get_bool (), true, "3.14 || 1234567890 --> true"); + + Variant v25 = v2 || v5; + t.is (v25.type (), Variant::type_boolean, "3.14 || 1200 --> boolean"); + t.is (v25.get_bool (), true, "3.14 || 1200 --> true"); + + Variant v30 = v3 || v0; + t.is (v30.type (), Variant::type_boolean, "'foo' || true --> boolean"); + t.is (v30.get_bool (), true, "'foo' || true --> true"); + + Variant v31 = v3 || v1; + t.is (v31.type (), Variant::type_boolean, "'foo' || 42 --> boolean"); + t.is (v31.get_bool (), true, "'foo' || 42 --> true"); + + Variant v32 = v3 || v2; + t.is (v32.type (), Variant::type_boolean, "'foo' || 3.14 --> boolean"); + t.is (v32.get_bool (), true, "'foo' || 3.14 --> true"); + + Variant v33 = v3 || v3; + t.is (v33.type (), Variant::type_boolean, "'foo' || 'foo' --> boolean"); + t.is (v33.get_bool (), true, "'foo' || 'foo' --> true"); + + Variant v34 = v3 || v4; + t.is (v34.type (), Variant::type_boolean, "'foo' || 1234567890 --> boolean"); + t.is (v34.get_bool (), true, "'foo' || 1234567890 --> true"); + + Variant v35 = v3 || v5; + t.is (v35.type (), Variant::type_boolean, "'foo' || 1200 --> boolean"); + t.is (v35.get_bool (), true, "'foo' || 1200 --> true"); + + Variant v40 = v4 || v0; + t.is (v40.type (), Variant::type_boolean, "1234567890 || true --> boolean"); + t.is (v40.get_bool (), true, "1234567890 || true --> true"); + + Variant v41 = v4 || v1; + t.is (v41.type (), Variant::type_boolean, "1234567890 || 42 --> boolean"); + t.is (v41.get_bool (), true, "1234567890 || 42 --> true"); + + Variant v42 = v4 || v2; + t.is (v42.type (), Variant::type_boolean, "1234567890 || 3.14 --> boolean"); + t.is (v42.get_bool (), true, "1234567890 || 3.14 --> true"); + + Variant v43 = v4 || v3; + t.is (v43.type (), Variant::type_boolean, "1234567890 || 'foo' --> boolean"); + t.is (v43.get_bool (), true, "1234567890 || 'foo' --> true"); + + Variant v44 = v4 || v4; + t.is (v44.type (), Variant::type_boolean, "1234567890 || 1234567890 --> boolean"); + t.is (v44.get_bool (), true, "1234567890 || 1234567890 --> true"); + + Variant v45 = v4 || v5; + t.is (v45.type (), Variant::type_boolean, "1234567890 || 1200 --> boolean"); + t.is (v45.get_bool (), true, "1234567890 || 1200 --> true"); + + Variant v50 = v5 || v0; + t.is (v50.type (), Variant::type_boolean, "1200 || true --> boolean"); + t.is (v50.get_bool (), true, "1200 || true --> true"); + + Variant v51 = v5 || v1; + t.is (v51.type (), Variant::type_boolean, "1200 || 42 --> boolean"); + t.is (v51.get_bool (), true, "1200 || 42 --> true"); + + Variant v52 = v5 || v2; + t.is (v52.type (), Variant::type_boolean, "1200 || 3.14 --> boolean"); + t.is (v52.get_bool (), true, "1200 || 3.14 --> true"); + + Variant v53 = v5 || v3; + t.is (v53.type (), Variant::type_boolean, "1200 || 'foo' --> boolean"); + t.is (v53.get_bool (), true, "1200 || 'foo' --> true"); + + Variant v54 = v5 || v4; + t.is (v04.type (), Variant::type_boolean, "1200 || 1234567890 --> boolean"); + t.is (v04.get_bool (), true, "1200 || 1234567890 --> true"); + + Variant v55 = v5 || v5; + t.is (v55.type (), Variant::type_boolean, "1200 || 1200 --> boolean"); + t.is (v55.get_bool (), true, "1200 || 1200 --> true"); + + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/test/variant_subtract.t.cpp b/test/variant_subtract.t.cpp new file mode 100644 index 000000000..8362e47b1 --- /dev/null +++ b/test/variant_subtract.t.cpp @@ -0,0 +1,177 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2013 - 2014, Göteborg Bit Factory. +// +// 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. +// +// http://www.opensource.org/licenses/mit-license.php +// +//////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include +#include + +Context context; + +#define EPSILON 0.001 + +//////////////////////////////////////////////////////////////////////////////// +int main (int argc, char** argv) +{ + UnitTest t (29); + + Variant v0 (true); + Variant v1 (42); + Variant v2 (3.14); + Variant v3 ("foo"); + Variant v4 (1234567890, Variant::type_date); + Variant v5 (1200, Variant::type_duration); + + // boolean - boolean -> ERROR + try {Variant v00 = v0 - v0; t.fail ("true - true --> error");} + catch (...) {t.pass ("true - true --> error");} + + // boolean - integer -> ERROR + try {Variant v01 = v0 - v1; t.fail ("true - 42 --> error");} + catch (...) {t.pass ("true - 42 --> error");} + + // boolean - real -> ERROR + try {Variant v02 = v0 - v2; t.fail ("true - 3.14 --> error");} + catch (...) {t.pass ("true - 3.14 --> error");} + + // boolean - string -> ERROR + try {Variant v03 = v0 - v3; t.fail ("true - foo --> error");} + catch (...) {t.pass ("true - foo --> error");} + + // boolean - date -> ERROR + try {Variant v04 = v0 - v4; t.fail ("true - 1234567890 --> error");} + catch (...) {t.pass ("true - 1234567890 --> error");} + + // boolean - duration -> ERROR + try {Variant v05 = v0 - v5; t.fail ("true - 1200 --> error");} + catch (...) {t.pass ("true - 1200 --> error");} + + // integer - boolean -> integer + Variant v10 = v1 - v0; + t.is (v10.type (), Variant::type_integer, "42 - true --> integer"); + t.is (v10.get_integer (), 41, "42 - true --> 41"); + + // integer - integer -> integer + Variant v11 = v1 - v1; + t.is (v11.type (), Variant::type_integer, "42 - 42 --> integer"); + t.is (v11.get_integer (), 0, "42 - 42 --> 0"); + + // integer - real -> real + Variant v12 = v1 - v2; + t.is (v12.type (), Variant::type_real, "42 - 3.14 --> real"); + t.is (v12.get_real (), 38.86, EPSILON, "42 - 3.14 --> 38.86"); + + // integer - string -> ERROR + try {Variant v13 = v1 - v3; t.fail ("42 - foo --> error");} + catch (...) {t.pass ("42 - foo --> error");} + + // TODO integer - date -> date + + // TODO integer - duration -> duration + + // real - boolean -> real + Variant v20 = v2 - v0; + t.is (v20.type (), Variant::type_real, "3.14 - true --> real"); + t.is (v20.get_real (), 2.14, EPSILON, "3.14 - true --> 2.14"); + + // real - integer -> real + Variant v21 = v2 - v1; + t.is (v21.type (), Variant::type_real, "3.14 - 42 --> real"); + t.is (v21.get_real (), -38.86, EPSILON, "3.14 - 42 --> -38.86"); + + // real - real -> real + Variant v22 = v2 - v2; + t.is (v22.type (), Variant::type_real, "3.14 - 3.14 --> real"); + t.is (v22.get_real (), 0.0, EPSILON, "3.14 - 3.14 --> 0.0"); + + // real - string -> ERROR + try {Variant v23 = v1 - v3; t.fail ("3.14 - foo --> error");} + catch (...) {t.pass ("3.14 - foo --> error");} + + // TODO real - date -> date + + // TODO real - duration -> duration + + // string - boolean -> ERROR + try {Variant v30 = v3 - v0; t.fail ("foo - foo --> error");} + catch (...) {t.pass ("foo - foo --> error");} + + // string - integer -> ERROR + try {Variant v31 = v3 - v1; t.fail ("foo - 42 --> error");} + catch (...) {t.pass ("foo - 42 --> error");} + + // string - real -> ERROR + try {Variant v32 = v3 - v2; t.fail ("foo - 3.14 --> error");} + catch (...) {t.pass ("foo - 3.14 --> error");} + + // string - string -> ERROR + try {Variant v33 = v3 - v3; t.fail ("foo - foo --> error");} + catch (...) {t.pass ("foo - foo --> error");} + + // string - date -> ERROR + try {Variant v34 = v3 - v4; t.fail ("foo - 1234567890 --> error");} + catch (...) {t.pass ("foo - 1234567890 --> error");} + + // string - duration -> ERROR + try {Variant v35 = v3 - v5; t.fail ("foo - 1200 --> error");} + catch (...) {t.pass ("foo - 1200 --> error");} + + // TODO date - boolean -> date + + // TODO date - integer -> date + + // TODO date - real -> date + + // date - string -> string + try {Variant v43 = v4 - v3; t.fail ("1234567890 - foo --> error");} + catch (...) {t.pass ("1234567890 - foo --> error");} + + // TODO date - date -> duration + + // TODO date - duration -> date + + + // TODO duration - boolean -> duration + + // TODO duration - integer -> duration + + // TODO duration - real -> duration + + // duration - string -> ERROR + try {Variant v53 = v5 - v3; t.fail ("1200 - foo --> error");} + catch (...) {t.pass ("1200 - foo --> error");} + + // duration - date -> ERROR + try {Variant v54 = v5 - v4; t.fail ("1200 - 1234567890 --> error");} + catch (...) {t.pass ("1200 - 1234567890 --> error");} + + // TODO duration - duration -> duration + + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/test/variant_xor.t.cpp b/test/variant_xor.t.cpp new file mode 100644 index 000000000..b573cfdca --- /dev/null +++ b/test/variant_xor.t.cpp @@ -0,0 +1,204 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2013 - 2014, Göteborg Bit Factory. +// +// 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. +// +// http://www.opensource.org/licenses/mit-license.php +// +//////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include +#include + +Context context; + +#define EPSILON 0.001 + +//////////////////////////////////////////////////////////////////////////////// +int main (int argc, char** argv) +{ + UnitTest t (76); + + Variant v0 (true); + Variant v1 (42); + Variant v2 (3.14); + Variant v3 ("foo"); + Variant v4 (1234567890, Variant::type_date); + Variant v5 (1200, Variant::type_duration); + + // Truth table. + Variant vFalse (false); + Variant vTrue (true); + t.is (vFalse.operator_xor (vFalse), false, "false xor false --> false"); + t.is (vFalse.operator_xor (vTrue), true, "false xor true --> false"); + t.is (vTrue.operator_xor (vFalse), true, "true xor false --> false"); + t.is (vTrue.operator_xor (vTrue), false, "true xor true --> false"); + + Variant v00 = v0.operator_xor (v0); + t.is (v00.type (), Variant::type_boolean, "true xor true --> boolean"); + t.is (v00.get_bool (), false, "true xor true --> false"); + + Variant v01 = v0.operator_xor (v1); + t.is (v01.type (), Variant::type_boolean, "true xor 42 --> boolean"); + t.is (v01.get_bool (), false, "true xor 42 --> false"); + + Variant v02 = v0.operator_xor (v2); + t.is (v02.type (), Variant::type_boolean, "true xor 3.14 --> boolean"); + t.is (v02.get_bool (), false, "true xor 3.14 --> false"); + + Variant v03 = v0.operator_xor (v3); + t.is (v03.type (), Variant::type_boolean, "true xor 'foo' --> boolean"); + t.is (v03.get_bool (), false, "true xor 'foo' --> false"); + + Variant v04 = v0.operator_xor (v4); + t.is (v04.type (), Variant::type_boolean, "true xor 1234567890 --> boolean"); + t.is (v04.get_bool (), false, "true xor 1234567890 --> false"); + + Variant v05 = v0.operator_xor (v5); + t.is (v05.type (), Variant::type_boolean, "true xor 1200 --> boolean"); + t.is (v05.get_bool (), false, "true xor 1200 --> false"); + + Variant v10 = v1.operator_xor (v0); + t.is (v10.type (), Variant::type_boolean, "42 xor true --> boolean"); + t.is (v10.get_bool (), false, "42 xor true --> false"); + + Variant v11 = v1.operator_xor (v1); + t.is (v11.type (), Variant::type_boolean, "42 xor 42 --> boolean"); + t.is (v11.get_bool (), false, "42 xor 42 --> false"); + + Variant v12 = v1.operator_xor (v2); + t.is (v12.type (), Variant::type_boolean, "42 xor 3.14 --> boolean"); + t.is (v12.get_bool (), false, "42 xor 3.14 --> false"); + + Variant v13 = v1.operator_xor (v3); + t.is (v13.type (), Variant::type_boolean, "42 xor 'foo' --> boolean"); + t.is (v13.get_bool (), false, "42 xor 'foo' --> false"); + + Variant v14 = v1.operator_xor (v4); + t.is (v04.type (), Variant::type_boolean, "42 xor 1234567890 --> boolean"); + t.is (v04.get_bool (), false, "42 xor 1234567890 --> false"); + + Variant v15 = v1.operator_xor (v5); + t.is (v15.type (), Variant::type_boolean, "42 xor 1200 --> boolean"); + t.is (v15.get_bool (), false, "42 xor 1200 --> false"); + + Variant v20 = v2.operator_xor (v0); + t.is (v20.type (), Variant::type_boolean, "3.14 xor true --> boolean"); + t.is (v20.get_bool (), false, "3.14 xor true --> false"); + + Variant v21 = v2.operator_xor (v1); + t.is (v21.type (), Variant::type_boolean, "3.14 xor 42 --> boolean"); + t.is (v21.get_bool (), false, "3.14 xor 42 --> false"); + + Variant v22 = v2.operator_xor (v2); + t.is (v22.type (), Variant::type_boolean, "3.14 xor 3.14 --> boolean"); + t.is (v22.get_bool (), false, "3.14 xor 3.14 --> false"); + + Variant v23 = v2.operator_xor (v3); + t.is (v23.type (), Variant::type_boolean, "3.14 xor 'foo' --> boolean"); + t.is (v23.get_bool (), false, "3.14 xor 'foo' --> false"); + + Variant v24 = v2.operator_xor (v4); + t.is (v24.type (), Variant::type_boolean, "3.14 xor 1234567890 --> boolean"); + t.is (v24.get_bool (), false, "3.14 xor 1234567890 --> false"); + + Variant v25 = v2.operator_xor (v5); + t.is (v25.type (), Variant::type_boolean, "3.14 xor 1200 --> boolean"); + t.is (v25.get_bool (), false, "3.14 xor 1200 --> false"); + + Variant v30 = v3.operator_xor (v0); + t.is (v30.type (), Variant::type_boolean, "'foo' xor true --> boolean"); + t.is (v30.get_bool (), false, "'foo' xor true --> false"); + + Variant v31 = v3.operator_xor (v1); + t.is (v31.type (), Variant::type_boolean, "'foo' xor 42 --> boolean"); + t.is (v31.get_bool (), false, "'foo' xor 42 --> false"); + + Variant v32 = v3.operator_xor (v2); + t.is (v32.type (), Variant::type_boolean, "'foo' xor 3.14 --> boolean"); + t.is (v32.get_bool (), false, "'foo' xor 3.14 --> false"); + + Variant v33 = v3.operator_xor (v3); + t.is (v33.type (), Variant::type_boolean, "'foo' xor 'foo' --> boolean"); + t.is (v33.get_bool (), false, "'foo' xor 'foo' --> false"); + + Variant v34 = v3.operator_xor (v4); + t.is (v34.type (), Variant::type_boolean, "'foo' xor 1234567890 --> boolean"); + t.is (v34.get_bool (), false, "'foo' xor 1234567890 --> false"); + + Variant v35 = v3.operator_xor (v5); + t.is (v35.type (), Variant::type_boolean, "'foo' xor 1200 --> boolean"); + t.is (v35.get_bool (), false, "'foo' xor 1200 --> false"); + + Variant v40 = v4.operator_xor (v0); + t.is (v40.type (), Variant::type_boolean, "1234567890 xor true --> boolean"); + t.is (v40.get_bool (), false, "1234567890 xor true --> false"); + + Variant v41 = v4.operator_xor (v1); + t.is (v41.type (), Variant::type_boolean, "1234567890 xor 42 --> boolean"); + t.is (v41.get_bool (), false, "1234567890 xor 42 --> false"); + + Variant v42 = v4.operator_xor (v2); + t.is (v42.type (), Variant::type_boolean, "1234567890 xor 3.14 --> boolean"); + t.is (v42.get_bool (), false, "1234567890 xor 3.14 --> false"); + + Variant v43 = v4.operator_xor (v3); + t.is (v43.type (), Variant::type_boolean, "1234567890 xor 'foo' --> boolean"); + t.is (v43.get_bool (), false, "1234567890 xor 'foo' --> false"); + + Variant v44 = v4.operator_xor (v4); + t.is (v44.type (), Variant::type_boolean, "1234567890 xor 1234567890 --> boolean"); + t.is (v44.get_bool (), false, "1234567890 xor 1234567890 --> false"); + + Variant v45 = v4.operator_xor (v5); + t.is (v45.type (), Variant::type_boolean, "1234567890 xor 1200 --> boolean"); + t.is (v45.get_bool (), false, "1234567890 xor 1200 --> false"); + + Variant v50 = v5.operator_xor (v0); + t.is (v50.type (), Variant::type_boolean, "1200 xor true --> boolean"); + t.is (v50.get_bool (), false, "1200 xor true --> false"); + + Variant v51 = v5.operator_xor (v1); + t.is (v51.type (), Variant::type_boolean, "1200 xor 42 --> boolean"); + t.is (v51.get_bool (), false, "1200 xor 42 --> false"); + + Variant v52 = v5.operator_xor (v2); + t.is (v52.type (), Variant::type_boolean, "1200 xor 3.14 --> boolean"); + t.is (v52.get_bool (), false, "1200 xor 3.14 --> false"); + + Variant v53 = v5.operator_xor (v3); + t.is (v53.type (), Variant::type_boolean, "1200 xor 'foo' --> boolean"); + t.is (v53.get_bool (), false, "1200 xor 'foo' --> false"); + + Variant v54 = v5.operator_xor (v4); + t.is (v04.type (), Variant::type_boolean, "1200 xor 1234567890 --> boolean"); + t.is (v04.get_bool (), false, "1200 xor 1234567890 --> false"); + + Variant v55 = v5.operator_xor (v5); + t.is (v55.type (), Variant::type_boolean, "1200 xor 1200 --> boolean"); + t.is (v55.get_bool (), false, "1200 xor 1200 --> false"); + + return 0; +} + +////////////////////////////////////////////////////////////////////////////////