From 7856c3b75945c72572d9fc42bc46c906b5e45a7a Mon Sep 17 00:00:00 2001 From: Paul Mensonides Date: Thu, 3 Oct 2002 21:55:27 +0000 Subject: [PATCH] new tests [SVN r15688] --- test/arithmetic.cpp | 63 +++++++++++++++++++++++++++++++++++++++++++++ test/array.cpp | 26 +++++++++++++++++++ test/comparison.cpp | 46 +++++++++++++++++++++++++++++++++ test/control.cpp | 41 +++++++++++++++++++++++++++++ test/debug.cpp | 22 ++++++++++++++++ test/facilities.cpp | 29 +++++++++++++++++++++ test/iteration.cpp | 34 ++++++++++++++++++++++++ test/list.cpp | 55 +++++++++++++++++++++++++++++++++++++++ test/logical.cpp | 37 ++++++++++++++++++++++++++ test/repetition.cpp | 51 ++++++++++++++++++++++++++++++++++++ test/selection.cpp | 22 ++++++++++++++++ test/slot.cpp | 28 ++++++++++++++++++++ test/tuple.cpp | 25 ++++++++++++++++++ 13 files changed, 479 insertions(+) create mode 100644 test/arithmetic.cpp create mode 100644 test/array.cpp create mode 100644 test/comparison.cpp create mode 100644 test/control.cpp create mode 100644 test/debug.cpp create mode 100644 test/facilities.cpp create mode 100644 test/iteration.cpp create mode 100644 test/list.cpp create mode 100644 test/logical.cpp create mode 100644 test/repetition.cpp create mode 100644 test/selection.cpp create mode 100644 test/slot.cpp create mode 100644 test/tuple.cpp diff --git a/test/arithmetic.cpp b/test/arithmetic.cpp new file mode 100644 index 0000000..6d3cf31 --- /dev/null +++ b/test/arithmetic.cpp @@ -0,0 +1,63 @@ +# /* ************************************************************************** +# * * +# * (C) Copyright Paul Mensonides 2002. Permission to copy, use, * +# * modify, sell, and distribute this software is granted provided * +# * this copyright notice appears in all copies. This software is * +# * provided "as is" without express or implied warranty, and with * +# * no claim at to its suitability for any purpose. * +# * * +# ************************************************************************** */ +# +# /* See http://www.boost.org for most recent version. */ +# +# include +# include +# include + +// addition + +BEGIN BOOST_PP_ADD(2, 3) == 5 END + +BEGIN BOOST_PP_ADD(BOOST_PP_ADD(2, 2), 2) == 6 END +BEGIN BOOST_PP_ADD(2, BOOST_PP_ADD(1, 4)) == 7 END +BEGIN BOOST_PP_ADD(BOOST_PP_ADD(2, 2), BOOST_PP_ADD(2, 2)) == 8 END + +// subtraction + +BEGIN BOOST_PP_SUB(11, 0) == 11 END +BEGIN BOOST_PP_SUB(12, 1) == 11 END +BEGIN BOOST_PP_SUB(3, 4) == 0 END + +BEGIN BOOST_PP_SUB(5, BOOST_PP_SUB(3, 2)) == 4 END +BEGIN BOOST_PP_SUB(BOOST_PP_SUB(10, 5), 2) == 3 END +BEGIN BOOST_PP_SUB(BOOST_PP_SUB(7, 3), BOOST_PP_SUB(10, 8)) == 2 END + +// multiplication + +BEGIN BOOST_PP_MUL(0, 1) == 0 END +BEGIN BOOST_PP_MUL(1, 0) == 0 END +BEGIN BOOST_PP_MUL(1, 1) == 1 END +BEGIN BOOST_PP_MUL(4, 3) == 12 END + +BEGIN BOOST_PP_MUL(BOOST_PP_MUL(2, 2), 2) == 8 END +BEGIN BOOST_PP_MUL(2, BOOST_PP_MUL(2, 2)) == 8 END +BEGIN BOOST_PP_MUL(BOOST_PP_MUL(2, 2), BOOST_PP_MUL(2, 2)) == 16 END + +// division + +BEGIN BOOST_PP_DIV(2, 1) == 2 END +BEGIN BOOST_PP_DIV(0, 5) == 0 END +BEGIN BOOST_PP_DIV(7, 3) == 2 END + +BEGIN BOOST_PP_DIV(BOOST_PP_DIV(4, 2), 2) == 1 END +BEGIN BOOST_PP_DIV(10, BOOST_PP_DIV(10, 2)) == 2 END +BEGIN BOOST_PP_DIV(BOOST_PP_DIV(10, 2), BOOST_PP_DIV(4, 2)) == 2 END + +// modulus + +BEGIN BOOST_PP_MOD(5, 5) == 0 END +BEGIN BOOST_PP_MOD(9, 5) == 4 END +BEGIN BOOST_PP_MOD(7, 4) == 3 END + +BEGIN BOOST_PP_MOD(BOOST_PP_MOD(5, 3), 3) == 2 END +BEGIN BOOST_PP_MOD(5, BOOST_PP_MOD(4, 3)) == 0 END diff --git a/test/array.cpp b/test/array.cpp new file mode 100644 index 0000000..a093c76 --- /dev/null +++ b/test/array.cpp @@ -0,0 +1,26 @@ +# /* ************************************************************************** +# * * +# * (C) Copyright Paul Mensonides 2002. Permission to copy, use, * +# * modify, sell, and distribute this software is granted provided * +# * this copyright notice appears in all copies. This software is * +# * provided "as is" without express or implied warranty, and with * +# * no claim at to its suitability for any purpose. * +# * * +# ************************************************************************** */ +# +# /* See http://www.boost.org for most recent version. */ +# +# include +# include + +# define ARRAY (3, (0, 1, 2)) + +// element access + +BEGIN BOOST_PP_ARRAY_ELEM(1, ARRAY) == 1 END +BEGIN BOOST_PP_ARRAY_ELEM(2, (5, (0, 1, 2, 3, 4))) == 2 END + +// size + +BEGIN BOOST_PP_ARRAY_SIZE(ARRAY) == 3 END +BEGIN BOOST_PP_ARRAY_SIZE((5, (0, 1, 2, 3, 4))) == 5 END diff --git a/test/comparison.cpp b/test/comparison.cpp new file mode 100644 index 0000000..a8cd002 --- /dev/null +++ b/test/comparison.cpp @@ -0,0 +1,46 @@ +# /* ************************************************************************** +# * * +# * (C) Copyright Paul Mensonides 2002. Permission to copy, use, * +# * modify, sell, and distribute this software is granted provided * +# * this copyright notice appears in all copies. This software is * +# * provided "as is" without express or implied warranty, and with * +# * no claim at to its suitability for any purpose. * +# * * +# ************************************************************************** */ +# +# /* See http://www.boost.org for most recent version. */ +# +# include +# include + +// equality + +BEGIN BOOST_PP_EQUAL(2, 0) == 0 END +BEGIN BOOST_PP_EQUAL(2, 2) == 1 END + +// inequality + +BEGIN BOOST_PP_NOT_EQUAL(2, 0) == 1 END +BEGIN BOOST_PP_NOT_EQUAL(2, 2) == 0 END + +// less + +BEGIN BOOST_PP_LESS(2, 1) == 0 END +BEGIN BOOST_PP_LESS(1, 2) == 1 END + +// less_equal + +BEGIN BOOST_PP_LESS_EQUAL(2, 1) == 0 END +BEGIN BOOST_PP_LESS_EQUAL(1, 2) == 1 END +BEGIN BOOST_PP_LESS_EQUAL(2, 2) == 1 END + +// greater + +BEGIN BOOST_PP_GREATER(2, 1) == 1 END +BEGIN BOOST_PP_GREATER(1, 2) == 0 END + +// greater_equal + +BEGIN BOOST_PP_GREATER_EQUAL(2, 1) == 1 END +BEGIN BOOST_PP_GREATER_EQUAL(1, 2) == 0 END +BEGIN BOOST_PP_GREATER_EQUAL(2, 2) == 1 END diff --git a/test/control.cpp b/test/control.cpp new file mode 100644 index 0000000..ffa54a8 --- /dev/null +++ b/test/control.cpp @@ -0,0 +1,41 @@ +# /* ************************************************************************** +# * * +# * (C) Copyright Paul Mensonides 2002. Permission to copy, use, * +# * modify, sell, and distribute this software is granted provided * +# * this copyright notice appears in all copies. This software is * +# * provided "as is" without express or implied warranty, and with * +# * no claim at to its suitability for any purpose. * +# * * +# ************************************************************************** */ +# +# /* See http://www.boost.org for most recent version. */ +# +# include +# include +# include +# include + +# define TR(x) 1 + +BEGIN BOOST_PP_EXPR_IIF(0, TR)(0) == 0 END +BEGIN BOOST_PP_EXPR_IIF(1, TR)(0) == 1 END + +BEGIN BOOST_PP_EXPR_IF(3, TR)(0) == 1 END +BEGIN BOOST_PP_EXPR_IF(0, TR)(0) == 0 END + +BEGIN BOOST_PP_IIF(0, 1, 0) == 0 END +BEGIN BOOST_PP_IIF(1, 1, 0) == 1 END + +BEGIN BOOST_PP_IF(0, 1, 0) == 0 END +BEGIN BOOST_PP_IF(9, 1, 0) == 1 END + +# define PRED(d, state) state +# define OP_1(d, state) BOOST_PP_DEC(state) + +BEGIN BOOST_PP_WHILE(PRED, OP_1, 50) == 0 END + +# define OP_2(d, state) BOOST_PP_DEC(BOOST_PP_ADD(BOOST_PP_WHILE(PRED, OP_1, state), state)) +# define OP_3(d, state) BOOST_PP_DEC(BOOST_PP_ADD_D(d, BOOST_PP_WHILE_ ## d(PRED, OP_1, state), state)) + +BEGIN BOOST_PP_WHILE(PRED, OP_3, 10) == 0 END +BEGIN BOOST_PP_WHILE(PRED, OP_3, 10) == 0 END diff --git a/test/debug.cpp b/test/debug.cpp new file mode 100644 index 0000000..d4094bf --- /dev/null +++ b/test/debug.cpp @@ -0,0 +1,22 @@ +# /* ************************************************************************** +# * * +# * (C) Copyright Paul Mensonides 2002. Permission to copy, use, * +# * modify, sell, and distribute this software is granted provided * +# * this copyright notice appears in all copies. This software is * +# * provided "as is" without express or implied warranty, and with * +# * no claim at to its suitability for any purpose. * +# * * +# ************************************************************************** */ +# +# /* See http://www.boost.org for most recent version. */ +# +# include +# include + +BEGIN sizeof(BOOST_PP_ASSERT_MSG(0, "text") "") / sizeof(char) != 1 END +BEGIN sizeof(BOOST_PP_ASSERT_MSG(1, "text") "") / sizeof(char) == 1 END + +BOOST_PP_ASSERT(10) + +# line BOOST_PP_LINE(100, __FILE__) +BEGIN __LINE__ == 100 END diff --git a/test/facilities.cpp b/test/facilities.cpp new file mode 100644 index 0000000..9a8f3e6 --- /dev/null +++ b/test/facilities.cpp @@ -0,0 +1,29 @@ +# /* ************************************************************************** +# * * +# * (C) Copyright Paul Mensonides 2002. Permission to copy, use, * +# * modify, sell, and distribute this software is granted provided * +# * this copyright notice appears in all copies. This software is * +# * provided "as is" without express or implied warranty, and with * +# * no claim at to its suitability for any purpose. * +# * * +# ************************************************************************** */ +# +# /* See http://www.boost.org for most recent version. */ +# +# include +# include +# include + +BEGIN BOOST_PP_APPLY(BOOST_PP_NIL) 0 == 0 END +BEGIN BOOST_PP_APPLY((0)) == 0 END + +BEGIN BOOST_PP_APPLY((BOOST_PP_EMPTY))() 0 == 0 END + +# define MACRO(x, y, z) 1 +# define ARGS (1, 2, 3) + +BEGIN BOOST_PP_EXPAND(MACRO ARGS) == 1 END + +BEGIN BOOST_PP_IDENTITY(1)() == 1 END + +BEGIN BOOST_PP_CAT(BOOST_PP_INTERCEPT, 2) 1 == 1 END diff --git a/test/iteration.cpp b/test/iteration.cpp new file mode 100644 index 0000000..d7d7949 --- /dev/null +++ b/test/iteration.cpp @@ -0,0 +1,34 @@ +# /* ************************************************************************** +# * * +# * (C) Copyright Paul Mensonides 2002. Permission to copy, use, * +# * modify, sell, and distribute this software is granted provided * +# * this copyright notice appears in all copies. This software is * +# * provided "as is" without express or implied warranty, and with * +# * no claim at to its suitability for any purpose. * +# * * +# ************************************************************************** */ +# +# /* See http://www.boost.org for most recent version. */ +# +# if !BOOST_PP_IS_SELFISH +# +# include +# +# define TEST(n) BEGIN n == n END +# +# define BOOST_PP_LOCAL_MACRO(n) TEST(n) +# define BOOST_PP_LOCAL_LIMITS (1, 5) +# include BOOST_PP_LOCAL_ITERATE() +# +# define BOOST_PP_LOCAL_MACRO(n) TEST(n) +# define BOOST_PP_LOCAL_LIMITS (5, 1) +# include BOOST_PP_LOCAL_ITERATE() +# +# define BOOST_PP_INDIRECT_SELF +# include BOOST_PP_INCLUDE_SELF() +# +# else + +BEGIN BOOST_PP_IS_SELFISH == 1 END + +# endif diff --git a/test/list.cpp b/test/list.cpp new file mode 100644 index 0000000..7e84f5a --- /dev/null +++ b/test/list.cpp @@ -0,0 +1,55 @@ +# /* ************************************************************************** +# * * +# * (C) Copyright Paul Mensonides 2002. Permission to copy, use, * +# * modify, sell, and distribute this software is granted provided * +# * this copyright notice appears in all copies. This software is * +# * provided "as is" without express or implied warranty, and with * +# * no claim at to its suitability for any purpose. * +# * * +# ************************************************************************** */ +# +# /* See http://www.boost.org for most recent version. */ +# +# include +# include +# include +# include +# include +# include + +# define LIST (4, (1, (5, (2, BOOST_PP_NIL)))) + +# define REVERSAL(d, x, y) BOOST_PP_SUB_D(d, y, x) + +BEGIN BOOST_PP_LIST_FOLD_LEFT(BOOST_PP_SUB_D, 22, LIST) == 10 END +BEGIN BOOST_PP_LIST_FOLD_RIGHT(BOOST_PP_ADD_D, 0, LIST) == 12 END +BEGIN BOOST_PP_LIST_FOLD_RIGHT(REVERSAL, 0, LIST) == 4 END + +BEGIN BOOST_PP_LIST_CAT(BOOST_PP_LIST_REVERSE(LIST)) == 2514 END + +BEGIN BOOST_PP_LIST_CAT(BOOST_PP_LIST_REST_N(2, LIST)) == 52 END +BEGIN BOOST_PP_LIST_CAT(BOOST_PP_LIST_FIRST_N(2, LIST)) == 41 END + +BEGIN BOOST_PP_LIST_AT(LIST, 2) == 5 END +BEGIN BOOST_PP_LIST_SIZE(LIST) == 4 END + +BEGIN BOOST_PP_LIST_CAT(BOOST_PP_LIST_TRANSFORM(BOOST_PP_ADD_D, 2, LIST)) == 6374 END +BEGIN BOOST_PP_LIST_CAT(BOOST_PP_LIST_APPEND(BOOST_PP_LIST_REST(LIST), LIST)) == 1524152 END + +# define F1(r, state, x) + x + state +BEGIN BOOST_PP_LIST_FOR_EACH(F1, 1, LIST) == 16 END + +BEGIN BOOST_PP_TUPLE_ELEM(4, 3, BOOST_PP_LIST_TO_TUPLE(LIST)) == 2 END + +BEGIN BOOST_PP_LIST_CAT(BOOST_PP_LIST_FILTER(BOOST_PP_LESS_D, 3, LIST)) == 45 END + +# define F2(r, x) + BOOST_PP_TUPLE_ELEM(2, 0, x) + 2 - BOOST_PP_TUPLE_ELEM(2, 1, x) +BEGIN BOOST_PP_LIST_FOR_EACH_PRODUCT(F2, 2, ( (1, (0, BOOST_PP_NIL)), (2, (3, BOOST_PP_NIL)) )) == 0 END + +# define L1 (0, (x, BOOST_PP_NIL)) +# define L2 (a, (1, (b, (2, BOOST_PP_NIL)))) +# define L3 (c, (3, (d, BOOST_PP_NIL))) + +# define LL (L1, (L2, (L3, BOOST_PP_NIL))) + +BEGIN BOOST_PP_LIST_CAT(BOOST_PP_LIST_FOLD_LEFT(BOOST_PP_LIST_APPEND_D, BOOST_PP_NIL, LL)) == 0x0a1b2c3d END diff --git a/test/logical.cpp b/test/logical.cpp new file mode 100644 index 0000000..178aa1b --- /dev/null +++ b/test/logical.cpp @@ -0,0 +1,37 @@ +# /* ************************************************************************** +# * * +# * (C) Copyright Paul Mensonides 2002. Permission to copy, use, * +# * modify, sell, and distribute this software is granted provided * +# * this copyright notice appears in all copies. This software is * +# * provided "as is" without express or implied warranty, and with * +# * no claim at to its suitability for any purpose. * +# * * +# ************************************************************************** */ +# +# /* See http://www.boost.org for most recent version. */ +# +# include +# include + +BEGIN BOOST_PP_NOT(0) == 1 END +BEGIN BOOST_PP_NOT(2) == 0 END + +BEGIN BOOST_PP_AND(0, 0) == 0 END +BEGIN BOOST_PP_AND(0, 3) == 0 END +BEGIN BOOST_PP_AND(4, 0) == 0 END +BEGIN BOOST_PP_AND(5, 6) == 1 END + +BEGIN BOOST_PP_OR(0, 0) == 0 END +BEGIN BOOST_PP_OR(0, 7) == 1 END +BEGIN BOOST_PP_OR(8, 0) == 1 END +BEGIN BOOST_PP_OR(9, 1) == 1 END + +BEGIN BOOST_PP_XOR(0, 0) == 0 END +BEGIN BOOST_PP_XOR(0, 2) == 1 END +BEGIN BOOST_PP_XOR(3, 0) == 1 END +BEGIN BOOST_PP_XOR(4, 5) == 0 END + +BEGIN BOOST_PP_NOR(0, 0) == 1 END +BEGIN BOOST_PP_NOR(0, 6) == 0 END +BEGIN BOOST_PP_NOR(7, 0) == 0 END +BEGIN BOOST_PP_NOR(8, 9) == 0 END diff --git a/test/repetition.cpp b/test/repetition.cpp new file mode 100644 index 0000000..cde9a4c --- /dev/null +++ b/test/repetition.cpp @@ -0,0 +1,51 @@ +# /* ************************************************************************** +# * * +# * (C) Copyright Paul Mensonides 2002. Permission to copy, use, * +# * modify, sell, and distribute this software is granted provided * +# * this copyright notice appears in all copies. This software is * +# * provided "as is" without express or implied warranty, and with * +# * no claim at to its suitability for any purpose. * +# * * +# ************************************************************************** */ +# +# /* See http://www.boost.org for most recent version. */ +# +# include +# include +# include +# include +# include +# include +# include + +# define MAX 10 + +# define NTH(z, n, data) data ## n + +int add(BOOST_PP_ENUM_PARAMS(MAX, int x)) { + return BOOST_PP_REPEAT(MAX, NTH, + x); +} + +const int r = add(BOOST_PP_ENUM_PARAMS(MAX, 1 BOOST_PP_INTERCEPT)); + +# define CONSTANT(z, n, text) BOOST_PP_CAT(text, n) = n +const int BOOST_PP_ENUM(MAX, CONSTANT, default_param_); + +# define TEST(n) \ + void BOOST_PP_CAT(test_enum_params, n)(BOOST_PP_ENUM_PARAMS(n, int x)); \ + void BOOST_PP_CAT(test_enum_params_with_a_default, n)(BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(n, int x, 0)); \ + void BOOST_PP_CAT(test_enum_params_with_defaults, n)(BOOST_PP_ENUM_PARAMS_WITH_DEFAULTS(n, int x, default_param_)); + +TEST(0) +TEST(MAX) + +template struct no_rescan; + +# define F1(z, n, p) p n +BEGIN 1 + (4+5+6) BOOST_PP_REPEAT_FROM_TO(4, 7, F1, -) END + +# define PRED(r, state) BOOST_PP_NOT_EQUAL(state, BOOST_PP_INC(MAX)) +# define OP(r, state) BOOST_PP_INC(state) +# define MACRO(r, state) BOOST_PP_COMMA_IF(BOOST_PP_NOT_EQUAL(state, 1)) BOOST_PP_CAT(class T, state) + +template struct for_test; diff --git a/test/selection.cpp b/test/selection.cpp new file mode 100644 index 0000000..3491f72 --- /dev/null +++ b/test/selection.cpp @@ -0,0 +1,22 @@ +# /* ************************************************************************** +# * * +# * (C) Copyright Paul Mensonides 2002. Permission to copy, use, * +# * modify, sell, and distribute this software is granted provided * +# * this copyright notice appears in all copies. This software is * +# * provided "as is" without express or implied warranty, and with * +# * no claim at to its suitability for any purpose. * +# * * +# ************************************************************************** */ +# +# /* See http://www.boost.org for most recent version. */ +# +# include +# include + +BEGIN BOOST_PP_MAX(2, 2) == 2 END +BEGIN BOOST_PP_MAX(2, 1) == 2 END +BEGIN BOOST_PP_MAX(1, 2) == 2 END + +BEGIN BOOST_PP_MIN(2, 2) == 2 END +BEGIN BOOST_PP_MIN(2, 1) == 1 END +BEGIN BOOST_PP_MIN(1, 2) == 1 END diff --git a/test/slot.cpp b/test/slot.cpp new file mode 100644 index 0000000..24047a0 --- /dev/null +++ b/test/slot.cpp @@ -0,0 +1,28 @@ +# /* ************************************************************************** +# * * +# * (C) Copyright Paul Mensonides 2002. Permission to copy, use, * +# * modify, sell, and distribute this software is granted provided * +# * this copyright notice appears in all copies. This software is * +# * provided "as is" without express or implied warranty, and with * +# * no claim at to its suitability for any purpose. * +# * * +# ************************************************************************** */ +# +# /* See http://www.boost.org for most recent version. */ +# +# include +# include + +# define X() 4 + +# define BOOST_PP_VALUE 1 + 2 + 3 + X() +# include BOOST_PP_ASSIGN_SLOT(1) + +# undef X + +BEGIN BOOST_PP_SLOT(1) == 10 END + +# define BOOST_PP_VALUE BOOST_PP_SLOT(1) * BOOST_PP_SLOT(1) +# include BOOST_PP_ASSIGN_SLOT(1) + +BEGIN BOOST_PP_SLOT(1) == 100 END diff --git a/test/tuple.cpp b/test/tuple.cpp new file mode 100644 index 0000000..9e1dc8d --- /dev/null +++ b/test/tuple.cpp @@ -0,0 +1,25 @@ +# /* ************************************************************************** +# * * +# * (C) Copyright Paul Mensonides 2002. Permission to copy, use, * +# * modify, sell, and distribute this software is granted provided * +# * this copyright notice appears in all copies. This software is * +# * provided "as is" without express or implied warranty, and with * +# * no claim at to its suitability for any purpose. * +# * * +# ************************************************************************** */ +# +# /* See http://www.boost.org for most recent version. */ +# +# include +# include + +# define TUPLE (0, 1, 2, 3, 4, 5) + +BEGIN BOOST_PP_TUPLE_ELEM(6, 3, TUPLE) == 3 END +BEGIN BOOST_PP_TUPLE_ELEM(6, 5, TUPLE) == 5 END + +# define CALC(x) BOOST_PP_TUPLE_ELEM(3, 0, x) BOOST_PP_TUPLE_ELEM(3, 1, x) BOOST_PP_TUPLE_ELEM(3, 2, x) +# define T2 (+3, /2, +6) + +BEGIN CALC(T2) == 7 END +BEGIN CALC(BOOST_PP_TUPLE_REVERSE(3, T2)) == 6 END