PageRenderTime 14ms CodeModel.GetById 2ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 1ms

/indra/llcommon/tests/llrand_test.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 127 lines | 89 code | 12 blank | 26 comment | 7 complexity | e4eec1bc35d584b940d040a2faf22af1 MD5 | raw file
  1/** 
  2 * @file llrandom_test.cpp
  3 * @author Phoenix
  4 * @date 2007-01-25
  5 *
  6 * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  7 * Second Life Viewer Source Code
  8 * Copyright (C) 2010, Linden Research, Inc.
  9 * 
 10 * This library is free software; you can redistribute it and/or
 11 * modify it under the terms of the GNU Lesser General Public
 12 * License as published by the Free Software Foundation;
 13 * version 2.1 of the License only.
 14 * 
 15 * This library is distributed in the hope that it will be useful,
 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 18 * Lesser General Public License for more details.
 19 * 
 20 * You should have received a copy of the GNU Lesser General Public
 21 * License along with this library; if not, write to the Free Software
 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 23 * 
 24 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 25 * $/LicenseInfo$
 26 */
 27
 28#include "linden_common.h"
 29#include "../test/lltut.h"
 30
 31#include "../llrand.h"
 32
 33
 34namespace tut
 35{
 36	struct random
 37	{
 38	};
 39
 40	typedef test_group<random> random_t;
 41	typedef random_t::object random_object_t;
 42	tut::random_t tut_random("LLSeedRand");
 43
 44	template<> template<>
 45	void random_object_t::test<1>()
 46	{
 47		F32 number = 0.0f;
 48		for(S32 ii = 0; ii < 100000; ++ii)
 49		{
 50			number = ll_frand();
 51			ensure("frand >= 0", (number >= 0.0f));
 52			ensure("frand < 1", (number < 1.0f));
 53		}
 54	}
 55
 56	template<> template<>
 57	void random_object_t::test<2>()
 58	{
 59		F64 number = 0.0f;
 60		for(S32 ii = 0; ii < 100000; ++ii)
 61		{
 62			number = ll_drand();
 63			ensure("drand >= 0", (number >= 0.0));
 64			ensure("drand < 1", (number < 1.0));
 65		}
 66	}
 67
 68	template<> template<>
 69	void random_object_t::test<3>()
 70	{
 71		F32 number = 0.0f;
 72		for(S32 ii = 0; ii < 100000; ++ii)
 73		{
 74			number = ll_frand(2.0f) - 1.0f;
 75			ensure("frand >= 0", (number >= -1.0f));
 76			ensure("frand < 1", (number <= 1.0f));
 77		}
 78	}
 79
 80	template<> template<>
 81	void random_object_t::test<4>()
 82	{
 83		F32 number = 0.0f;
 84		for(S32 ii = 0; ii < 100000; ++ii)
 85		{
 86			number = ll_frand(-7.0);
 87			ensure("drand <= 0", (number <= 0.0));
 88			ensure("drand > -7", (number > -7.0));
 89		}
 90	}
 91
 92	template<> template<>
 93	void random_object_t::test<5>()
 94	{
 95		F64 number = 0.0f;
 96		for(S32 ii = 0; ii < 100000; ++ii)
 97		{
 98			number = ll_drand(-2.0);
 99			ensure("drand <= 0", (number <= 0.0));
100			ensure("drand > -2", (number > -2.0));
101		}
102	}
103
104	template<> template<>
105	void random_object_t::test<6>()
106	{
107		S32 number = 0;
108		for(S32 ii = 0; ii < 100000; ++ii)
109		{
110			number = ll_rand(100);
111			ensure("rand >= 0", (number >= 0));
112			ensure("rand < 100", (number < 100));
113		}
114	}
115
116	template<> template<>
117	void random_object_t::test<7>()
118	{
119		S32 number = 0;
120		for(S32 ii = 0; ii < 100000; ++ii)
121		{
122			number = ll_rand(-127);
123			ensure("rand <= 0", (number <= 0));
124			ensure("rand > -127", (number > -127));
125		}
126	}
127}