A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
one-uniform-random-variable-many-get-value-calls-test-suite.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012 University of Washington
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mitch Watrous (watrous@u.washington.edu)
7 */
8
9#include "ns3/config.h"
10#include "ns3/double.h"
11#include "ns3/random-variable-stream.h"
12#include "ns3/test.h"
13
14/**
15 * @file
16 * @ingroup core-tests
17 * @ingroup randomvariable
18 * @ingroup rng-tests
19 * Test for one uniform random variable stream.
20 */
21
22namespace ns3
23{
24
25namespace tests
26{
27
28/**
29 * @ingroup rng-tests
30 * Test case for one uniform distribution random variable stream generator
31 */
41
44 : TestCase("One Uniform Random Variable with Many GetValue() Calls")
45{
46}
47
52
53void
55{
56 const double min = 0.0;
57 const double max = 10.0;
58
59 Config::SetDefault("ns3::UniformRandomVariable::Min", DoubleValue(min));
60 Config::SetDefault("ns3::UniformRandomVariable::Max", DoubleValue(max));
61
63
64 // Get many values from 1 random number generator.
65 double value;
66 const int count = 100000000;
67 for (int i = 0; i < count; i++)
68 {
69 value = uniform->GetValue();
70
71 NS_TEST_ASSERT_MSG_GT(value, min, "Value less than minimum.");
72 NS_TEST_ASSERT_MSG_LT(value, max, "Value greater than maximum.");
73 }
74}
75
76/**
77 * @ingroup rng-tests
78 * Test suite for one uniform distribution random variable stream generator
79 */
85
92
93/**
94 * @ingroup rng-tests
95 * OneUniformRandomVariableManyGetValueCallsTestSuite instance variable.
96 */
99
100} // namespace tests
101
102} // namespace ns3
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:296
TestCase(const TestCase &)=delete
Caller graph was not generated because of its size.
Type
Type of test.
Definition test.h:1271
TestSuite(std::string name, Type type=Type::UNIT)
Construct a new test suite.
Definition test.cc:494
void SetDefault(std::string name, const AttributeValue &value)
Definition config.cc:886
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:627
static OneUniformRandomVariableManyGetValueCallsTestSuite g_oneUniformRandomVariableManyGetValueCallsTestSuite
OneUniformRandomVariableManyGetValueCallsTestSuite instance variable.
#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:698
#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:863
Namespace for test files, TestCases and TestSuites.
Every class exported by the ns3 library is enclosed in the ns3 namespace.