stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject svn commit: r453816 - in /incubator/stdcxx/trunk/tests: include/rw_rand.h src/rand.cpp
Date Sat, 07 Oct 2006 00:12:44 GMT
Author: sebor
Date: Fri Oct  6 17:12:43 2006
New Revision: 453816

URL: http://svn.apache.org/viewvc?view=rev&rev=453816
Log:
2006-10-06  Martin Sebor  <sebor@roguewave.com>

	STDCXX-3
	* rw_rand.h: New. Declarations of testsuite random generator helpers.
	* random.cpp: New. Definitions of the above.

Added:
    incubator/stdcxx/trunk/tests/include/rw_rand.h   (with props)
    incubator/stdcxx/trunk/tests/src/rand.cpp   (with props)

Added: incubator/stdcxx/trunk/tests/include/rw_rand.h
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/include/rw_rand.h?view=auto&rev=453816
==============================================================================
--- incubator/stdcxx/trunk/tests/include/rw_rand.h (added)
+++ incubator/stdcxx/trunk/tests/include/rw_rand.h Fri Oct  6 17:12:43 2006
@@ -0,0 +1,71 @@
+/************************************************************************
+ *
+ * rw_rand.h - declarations of testsuite random number generators
+ *
+ * $Id$
+ *
+ ***************************************************************************
+ *
+ * Licensed to the Apache Software  Foundation (ASF) under one or more
+ * contributor  license agreements.  See  the NOTICE  file distributed
+ * with  this  work  for  additional information  regarding  copyright
+ * ownership.   The ASF  licenses this  file to  you under  the Apache
+ * License, Version  2.0 (the  "License"); you may  not use  this file
+ * except in  compliance with the License.   You may obtain  a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the  License is distributed on an  "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY  KIND, either  express or
+ * implied.   See  the License  for  the  specific language  governing
+ * permissions and limitations under the License.
+ *
+ * Copyright 2005-2006 Rogue Wave Software.
+ * 
+ **************************************************************************/
+
+#ifndef RW_RAND_H_INCLUDED
+#define RW_RAND_H_INCLUDED
+
+#include <rw/_defs.h>   // for libstd config macros
+#include <testdefs.h>   // for test config macros
+
+// seeds the 32-bit random number generator
+// if the seed is equal UINT32_MAX picks a random value to seed
+// the generator with
+_TEST_EXPORT void
+rw_seed32 (_RWSTD_UINT32_T);
+
+// returns a 32-bit random number in the range [0, limit)
+// if limit is non-zero, otherwise in the range [0, UINT32_MAX)
+_TEST_EXPORT _RWSTD_UINT32_T
+rw_rand32 (_RWSTD_UINT32_T = 0);
+
+#ifdef _RWSTD_UINT64_T
+
+// seeds the 64-bit random number generator
+// if the seed is equal UINT64_MAX picks a random value to seed
+// the generator with
+_TEST_EXPORT void
+rw_seed64 (_RWSTD_UINT64_T);
+
+// returns a 64-bit random number in the range [0, limit)
+// if limit is non-zero, otherwise in the range [0, UINT64_MAX)
+_TEST_EXPORT _RWSTD_UINT64_T
+rw_rand64 (_RWSTD_UINT64_T = 0);
+
+#  if 32 == _RWSTD_INT_SIZE
+#    define rw_seed(limit)   rw_seed32 (limit)
+#    define rw_rand(limit)   rw_rand32 (limit)
+#  else   // if 32 != _RWSTD_INT_SIZE
+#    define rw_seed(limit)   rw_seed64 (limit)
+#    define rw_rand(limit)   rw_rand64 (limit)
+#  endif   // 32 == _RWSTD_INT_SIZE
+#else   // if !defined (_RWSTD_UINT64_T)
+#  define rw_seed(limit)   rw_seed32 (limit)
+#  define rw_rand(limit)   rw_rand32 (limit)
+#endif   // _RWSTD_UINT64_T
+
+#endif   // RW_RAND_H_INCLUDED

Propchange: incubator/stdcxx/trunk/tests/include/rw_rand.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/stdcxx/trunk/tests/include/rw_rand.h
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/stdcxx/trunk/tests/src/rand.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/src/rand.cpp?view=auto&rev=453816
==============================================================================
--- incubator/stdcxx/trunk/tests/src/rand.cpp (added)
+++ incubator/stdcxx/trunk/tests/src/rand.cpp Fri Oct  6 17:12:43 2006
@@ -0,0 +1,137 @@
+/************************************************************************
+ *
+ * rand.cpp - definitions of testsuite random number generators
+ *
+ * $Id$
+ *
+ ************************************************************************
+ *
+ * Licensed to the Apache Software  Foundation (ASF) under one or more
+ * contributor  license agreements.  See  the NOTICE  file distributed
+ * with  this  work  for  additional information  regarding  copyright
+ * ownership.   The ASF  licenses this  file to  you under  the Apache
+ * License, Version  2.0 (the  "License"); you may  not use  this file
+ * except in  compliance with the License.   You may obtain  a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the  License is distributed on an  "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY  KIND, either  express or
+ * implied.   See  the License  for  the  specific language  governing
+ * permissions and limitations under the License.
+ *
+ * Copyright 2005-2006 Rogue Wave Software.
+ * 
+ **************************************************************************/
+
+#include <time.h>   // for clock()
+
+// expand _TEST_EXPORT macros
+#define _RWSTD_TEST_SRC
+#include <rw_rand.h>
+
+
+enum { TABLE_SIZE = 55 };
+
+static _RWSTD_UINT32_T table32 [TABLE_SIZE];
+static _RWSTD_SIZE_T   inx32 [2];
+
+
+// seeds the 32-bit random number generator
+_TEST_EXPORT void
+rw_seed32 (_RWSTD_UINT32_T seed)
+{
+    if (0xffffffffUL == seed)
+        seed = clock ();
+
+    table32 [TABLE_SIZE - 1] = seed;
+
+    _RWSTD_SIZE_T i;
+    _RWSTD_SIZE_T k = 1;
+
+    for (i = 0; i != TABLE_SIZE - 1U; ++i) {
+
+        const _RWSTD_SIZE_T ii = 21U * i % TABLE_SIZE;
+        table32 [ii] =  k;
+        k            = seed - k;
+        seed         = _RWSTD_STATIC_CAST (_RWSTD_SIZE_T, table32 [ii]);
+    }
+
+    for (i = 0; i != 4U; ++i) {
+        for (_RWSTD_SIZE_T ii = 0; ii != TABLE_SIZE; ++ii)
+            table32 [i] = table32 [i] - table32 [(i + 31U) % TABLE_SIZE];
+    }
+
+    inx32 [0] = 0U;
+    inx32 [1] = TABLE_SIZE * 2U / 3U - 1U;
+}
+
+
+// returns a 32-bit random number in the range [0, limit)
+// if limit is non-zero, otherwise in the range [0, UINT32_MAX)
+_TEST_EXPORT _RWSTD_UINT32_T
+rw_rand32 (_RWSTD_UINT32_T limit /* = 0 */)
+{
+    if (0 == inx32 [0] && 0 == inx32 [1])
+        rw_seed32 (161803398);
+
+    table32 [++inx32 [0] %= TABLE_SIZE] -=
+        table32 [++inx32 [1] %= TABLE_SIZE];
+
+    return limit ? table32 [inx32 [0]] % limit : table32 [inx32 [0]];
+}
+
+
+#ifdef _RWSTD_UINT64_T
+
+static _RWSTD_UINT64_T table64 [TABLE_SIZE];
+static _RWSTD_SIZE_T   inx64 [2];
+
+
+// seeds the 64-bit random number generator
+_TEST_EXPORT void
+rw_seed64 (_RWSTD_UINT64_T seed)
+{
+    if ((_RWSTD_UINT64_T)-1 == seed)
+        seed = clock ();
+
+    table64 [TABLE_SIZE - 1] = seed;
+
+    _RWSTD_SIZE_T i;
+    _RWSTD_SIZE_T k = 1;
+
+    for (i = 0; i != TABLE_SIZE - 1U; ++i) {
+
+        const _RWSTD_SIZE_T ii = 21U * i % TABLE_SIZE;
+        table64 [ii] =  k;
+        k            = seed - k;
+        seed         = _RWSTD_STATIC_CAST (_RWSTD_SIZE_T, table64 [ii]);
+    }
+
+    for (i = 0; i != 4U; ++i) {
+        for (_RWSTD_SIZE_T ii = 0; ii != TABLE_SIZE; ++ii)
+            table64 [i] = table64 [i] - table64 [(i + 31U) % TABLE_SIZE];
+    }
+
+    inx64 [0] = 0U;
+    inx64 [1] = TABLE_SIZE * 2U / 3U - 1U;
+}
+
+
+// returns a 64-bit random number in the range [0, limit)
+// if limit is non-zero, otherwise in the range [0, UINT64_MAX)
+_TEST_EXPORT _RWSTD_UINT64_T
+rw_rand64 (_RWSTD_UINT64_T limit)
+{
+    if (0 == inx64 [0] && 0 == inx64 [1])
+        rw_seed64 (161803398);
+
+    table64 [++inx64 [0] %= TABLE_SIZE] -=
+        table64 [++inx64 [1] %= TABLE_SIZE];
+
+    return limit ? table64 [inx64 [0]] % limit : table64 [inx64 [0]];
+}
+
+#endif   // _RWSTD_UINT64_T

Propchange: incubator/stdcxx/trunk/tests/src/rand.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/stdcxx/trunk/tests/src/rand.cpp
------------------------------------------------------------------------------
    svn:keywords = Id



Mime
View raw message