LEFT | RIGHT |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2009-12 University of Washington | 3 * Copyright (c) 2009-12 University of Washington |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 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 | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 2585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2596 // | 2596 // |
2597 // zeta(alpha - 1) | 2597 // zeta(alpha - 1) |
2598 // E[value] = --------------- for alpha > 2 , | 2598 // E[value] = --------------- for alpha > 2 , |
2599 // zeta(alpha) | 2599 // zeta(alpha) |
2600 //·························· | 2600 //·························· |
2601 // where zeta(alpha) is the Riemann zeta function. | 2601 // where zeta(alpha) is the Riemann zeta function. |
2602 //················· | 2602 //················· |
2603 // There are no simple analytic forms for the Riemann zeta function, | 2603 // There are no simple analytic forms for the Riemann zeta function, |
2604 // which is why the gsl library is used in this test to calculate | 2604 // which is why the gsl library is used in this test to calculate |
2605 // the known mean of the values. | 2605 // the known mean of the values. |
2606 double expectedMean = gsl_sf_zeta_int (static_cast<int>(alpha - 1)) / gsl_sf_z
eta_int (static_cast<int>(alpha)); | 2606 double expectedMean =· |
| 2607 gsl_sf_zeta_int (static_cast<int> (alpha - 1)) /· |
| 2608 gsl_sf_zeta_int (static_cast<int> (alpha) ); |
2607 | 2609 |
2608 // Test that values have approximately the right mean value. | 2610 // Test that values have approximately the right mean value. |
2609 double TOLERANCE = expectedMean * 1e-2; | 2611 double TOLERANCE = expectedMean * 1e-2; |
2610 NS_TEST_ASSERT_MSG_EQ_TOL (valueMean, expectedMean, TOLERANCE, "Wrong mean val
ue.");· | 2612 NS_TEST_ASSERT_MSG_EQ_TOL (valueMean, expectedMean, TOLERANCE, "Wrong mean val
ue.");· |
2611 } | 2613 } |
2612 | 2614 |
2613 // =========================================================================== | 2615 // =========================================================================== |
2614 // Test case for antithetic Zeta distribution random variable stream generator | 2616 // Test case for antithetic Zeta distribution random variable stream generator |
2615 // =========================================================================== | 2617 // =========================================================================== |
2616 class RandomVariableStreamZetaAntitheticTestCase : public TestCase | 2618 class RandomVariableStreamZetaAntitheticTestCase : public TestCase |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2663 // | 2665 // |
2664 // zeta(alpha - 1) | 2666 // zeta(alpha - 1) |
2665 // E[value] = --------------- for alpha > 2 , | 2667 // E[value] = --------------- for alpha > 2 , |
2666 // zeta(alpha) | 2668 // zeta(alpha) |
2667 //·························· | 2669 //·························· |
2668 // where zeta(alpha) is the Riemann zeta function. | 2670 // where zeta(alpha) is the Riemann zeta function. |
2669 //················· | 2671 //················· |
2670 // There are no simple analytic forms for the Riemann zeta function, | 2672 // There are no simple analytic forms for the Riemann zeta function, |
2671 // which is why the gsl library is used in this test to calculate | 2673 // which is why the gsl library is used in this test to calculate |
2672 // the known mean of the values. | 2674 // the known mean of the values. |
2673 double expectedMean = gsl_sf_zeta_int (static_cast<int>(alpha) - 1) / gsl_sf_z
eta_int (static_cast<int>(alpha)); | 2675 double expectedMean =· |
| 2676 gsl_sf_zeta_int (static_cast<int> (alpha) - 1) /· |
| 2677 gsl_sf_zeta_int (static_cast<int> (alpha) ); |
2674 | 2678 |
2675 // Test that values have approximately the right mean value. | 2679 // Test that values have approximately the right mean value. |
2676 double TOLERANCE = expectedMean * 1e-2; | 2680 double TOLERANCE = expectedMean * 1e-2; |
2677 NS_TEST_ASSERT_MSG_EQ_TOL (valueMean, expectedMean, TOLERANCE, "Wrong mean val
ue.");· | 2681 NS_TEST_ASSERT_MSG_EQ_TOL (valueMean, expectedMean, TOLERANCE, "Wrong mean val
ue.");· |
2678 } | 2682 } |
2679 | 2683 |
2680 // =========================================================================== | 2684 // =========================================================================== |
2681 // Test case for deterministic random variable stream generator | 2685 // Test case for deterministic random variable stream generator |
2682 // =========================================================================== | 2686 // =========================================================================== |
2683 class RandomVariableStreamDeterministicTestCase : public TestCase | 2687 class RandomVariableStreamDeterministicTestCase : public TestCase |
(...skipping 24 matching lines...) Expand all Loading... |
2708 { | 2712 { |
2709 SetTestSuiteSeed (); | 2713 SetTestSuiteSeed (); |
2710 | 2714 |
2711 Ptr<DeterministicRandomVariable> s = CreateObject<DeterministicRandomVariable>
(); | 2715 Ptr<DeterministicRandomVariable> s = CreateObject<DeterministicRandomVariable>
(); |
2712 | 2716 |
2713 // The following array should give the sequence | 2717 // The following array should give the sequence |
2714 // | 2718 // |
2715 // 4, 4, 7, 7, 10, 10 . | 2719 // 4, 4, 7, 7, 10, 10 . |
2716 // | 2720 // |
2717 double array1 [] = { 4, 4, 7, 7, 10, 10}; | 2721 double array1 [] = { 4, 4, 7, 7, 10, 10}; |
2718 uint32_t count1 = 6; | 2722 std::size_t count1 = 6; |
2719 s->SetValueArray (array1, count1); | 2723 s->SetValueArray (array1, count1); |
2720 | 2724 |
2721 double value; | 2725 double value; |
2722 | 2726 |
2723 // Test that the first sequence is correct. | 2727 // Test that the first sequence is correct. |
2724 value = s->GetValue ();· | 2728 value = s->GetValue ();· |
2725 NS_TEST_ASSERT_MSG_EQ_TOL (value, 4, TOLERANCE, "Sequence 1 value 1 wrong.");· | 2729 NS_TEST_ASSERT_MSG_EQ_TOL (value, 4, TOLERANCE, "Sequence 1 value 1 wrong.");· |
2726 value = s->GetValue ();· | 2730 value = s->GetValue ();· |
2727 NS_TEST_ASSERT_MSG_EQ_TOL (value, 4, TOLERANCE, "Sequence 1 value 2 wrong.");· | 2731 NS_TEST_ASSERT_MSG_EQ_TOL (value, 4, TOLERANCE, "Sequence 1 value 2 wrong.");· |
2728 value = s->GetValue ();· | 2732 value = s->GetValue ();· |
2729 NS_TEST_ASSERT_MSG_EQ_TOL (value, 7, TOLERANCE, "Sequence 1 value 3 wrong.");· | 2733 NS_TEST_ASSERT_MSG_EQ_TOL (value, 7, TOLERANCE, "Sequence 1 value 3 wrong.");· |
2730 value = s->GetValue ();· | 2734 value = s->GetValue ();· |
2731 NS_TEST_ASSERT_MSG_EQ_TOL (value, 7, TOLERANCE, "Sequence 1 value 4 wrong.");· | 2735 NS_TEST_ASSERT_MSG_EQ_TOL (value, 7, TOLERANCE, "Sequence 1 value 4 wrong.");· |
2732 value = s->GetValue ();· | 2736 value = s->GetValue ();· |
2733 NS_TEST_ASSERT_MSG_EQ_TOL (value, 10, TOLERANCE, "Sequence 1 value 5 wrong.");········ | 2737 NS_TEST_ASSERT_MSG_EQ_TOL (value, 10, TOLERANCE, "Sequence 1 value 5 wrong.");········ |
2734 value = s->GetValue ();· | 2738 value = s->GetValue ();· |
2735 NS_TEST_ASSERT_MSG_EQ_TOL (value, 10, TOLERANCE, "Sequence 1 value 6 wrong.");········ | 2739 NS_TEST_ASSERT_MSG_EQ_TOL (value, 10, TOLERANCE, "Sequence 1 value 6 wrong.");········ |
2736 | 2740 |
2737 // The following array should give the sequence | 2741 // The following array should give the sequence |
2738 // | 2742 // |
2739 // 1000, 2000, 7, 7 . | 2743 // 1000, 2000, 7, 7 . |
2740 // | 2744 // |
2741 double array2 [] = { 1000, 2000, 3000, 4000}; | 2745 double array2 [] = { 1000, 2000, 3000, 4000}; |
2742 uint32_t count2 = 4; | 2746 std::size_t count2 = 4; |
2743 s->SetValueArray (array2, count2); | 2747 s->SetValueArray (array2, count2); |
2744 | 2748 |
2745 // Test that the second sequence is correct. | 2749 // Test that the second sequence is correct. |
2746 value = s->GetValue ();· | 2750 value = s->GetValue ();· |
2747 NS_TEST_ASSERT_MSG_EQ_TOL (value, 1000, TOLERANCE, "Sequence 2 value 1 wrong."
);· | 2751 NS_TEST_ASSERT_MSG_EQ_TOL (value, 1000, TOLERANCE, "Sequence 2 value 1 wrong."
);· |
2748 value = s->GetValue ();· | 2752 value = s->GetValue ();· |
2749 NS_TEST_ASSERT_MSG_EQ_TOL (value, 2000, TOLERANCE, "Sequence 2 value 2 wrong."
);· | 2753 NS_TEST_ASSERT_MSG_EQ_TOL (value, 2000, TOLERANCE, "Sequence 2 value 2 wrong."
);· |
2750 value = s->GetValue ();· | 2754 value = s->GetValue ();· |
2751 NS_TEST_ASSERT_MSG_EQ_TOL (value, 3000, TOLERANCE, "Sequence 2 value 3 wrong."
);· | 2755 NS_TEST_ASSERT_MSG_EQ_TOL (value, 3000, TOLERANCE, "Sequence 2 value 3 wrong."
);· |
2752 value = s->GetValue ();· | 2756 value = s->GetValue ();· |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2918 AddTestCase (new RandomVariableStreamZipfTestCase, TestCase::QUICK); | 2922 AddTestCase (new RandomVariableStreamZipfTestCase, TestCase::QUICK); |
2919 AddTestCase (new RandomVariableStreamZipfAntitheticTestCase, TestCase::QUICK); | 2923 AddTestCase (new RandomVariableStreamZipfAntitheticTestCase, TestCase::QUICK); |
2920 AddTestCase (new RandomVariableStreamZetaTestCase, TestCase::QUICK); | 2924 AddTestCase (new RandomVariableStreamZetaTestCase, TestCase::QUICK); |
2921 AddTestCase (new RandomVariableStreamZetaAntitheticTestCase, TestCase::QUICK); | 2925 AddTestCase (new RandomVariableStreamZetaAntitheticTestCase, TestCase::QUICK); |
2922 AddTestCase (new RandomVariableStreamDeterministicTestCase, TestCase::QUICK); | 2926 AddTestCase (new RandomVariableStreamDeterministicTestCase, TestCase::QUICK); |
2923 AddTestCase (new RandomVariableStreamEmpiricalTestCase, TestCase::QUICK); | 2927 AddTestCase (new RandomVariableStreamEmpiricalTestCase, TestCase::QUICK); |
2924 AddTestCase (new RandomVariableStreamEmpiricalAntitheticTestCase, TestCase::QU
ICK); | 2928 AddTestCase (new RandomVariableStreamEmpiricalAntitheticTestCase, TestCase::QU
ICK); |
2925 } | 2929 } |
2926 | 2930 |
2927 static RandomVariableStreamTestSuite randomVariableStreamTestSuite; | 2931 static RandomVariableStreamTestSuite randomVariableStreamTestSuite; |
LEFT | RIGHT |