A Discrete-Event Network Simulator
API
one-uniform-random-variable-many-get-value-calls-test-suite.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2012 University of Washington
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Mitch Watrous (watrous@u.washington.edu)
19  */
20 
21 #include "ns3/test.h"
22 #include "ns3/config.h"
23 #include "ns3/double.h"
24 #include "ns3/random-variable-stream.h"
25 #include <vector>
26 
35 namespace ns3 {
36 
37  namespace tests {
38 
39 
45 {
46 public:
51 
52 private:
53  virtual void DoRun (void);
54 };
55 
57  : TestCase ("One Uniform Random Variable with Many GetValue() Calls")
58 {
59 }
60 
62 {
63 }
64 
65 void
67 {
68  const double min = 0.0;
69  const double max = 10.0;
70 
71  Config::SetDefault ("ns3::UniformRandomVariable::Min", DoubleValue (min));
72  Config::SetDefault ("ns3::UniformRandomVariable::Max", DoubleValue (max));
73 
74  Ptr<UniformRandomVariable> uniform = CreateObject<UniformRandomVariable> ();
75 
76  // Get many values from 1 random number generator.
77  double value;
78  const int count = 100000000;
79  for (int i = 0; i < count; i++)
80  {
81  value = uniform->GetValue ();
82 
83  NS_TEST_ASSERT_MSG_GT (value, min, "Value less than minimum.");
84  NS_TEST_ASSERT_MSG_LT (value, max, "Value greater than maximum.");
85  }
86 }
87 
93 {
94 public:
97 };
98 
100  : TestSuite ("one-uniform-random-variable-many-get-value-calls", PERFORMANCE)
101 {
103 }
104 
110 
111 
112  } // namespace tests
113 
114 } // namespace ns3
A suite of tests to run.
Definition: test.h:1342
encapsulates test code
Definition: test.h:1155
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
Test suite for one uniform distribution random variable stream generator.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double GetValue(double min, double max)
Get the next random value, as a double in the specified range .
double max(double x, double y)
Test case for one uniform distribution random variable stream generator.
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:810
double min(double x, double y)
static OneUniformRandomVariableManyGetValueCallsTestSuite g_oneUniformRandomVariableManyGetValueCallsTestSuite
OneUniformRandomVariableManyGetValueCallsTestSuite instance variable.
#define NS_TEST_ASSERT_MSG_GT(actual, limit, msg)
Test that an actual value is greater than a limit and report and abort if not.
Definition: test.h:997
This class can be used to hold variables of floating point type such as &#39;double&#39; or &#39;float&#39;...
Definition: double.h:41
#define NS_TEST_ASSERT_MSG_LT(actual, limit, msg)
Test that an actual value is less than a limit and report and abort if not.
Definition: test.h:811