src/simulator/time.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Wed, 08 Aug 2007 16:41:59 +0200
changeset 1224 7cbc1d661b89
parent 911 de8102a51fbf
child 1696 0de65f4c8c43
permissions -rw-r--r--
rename Bind to DefaultValue::Bind. fix bug 62
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 144
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
25
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     2
/*
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     3
 * Copyright (c) 2005,2006 INRIA
680
0bbe0e4d73c6 add reference to Emmanuelle in Authors/Copyright
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 679
diff changeset
     4
 * Copyright (c) 2007 Emmanuelle Laprise
25
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     5
 * All rights reserved.
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     6
 *
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     7
 * This program is free software; you can redistribute it and/or modify
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     8
 * it under the terms of the GNU General Public License version 2 as
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     9
 * published by the Free Software Foundation;
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    10
 *
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    11
 * This program is distributed in the hope that it will be useful,
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    14
 * GNU General Public License for more details.
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    15
 *
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    17
 * along with this program; if not, write to the Free Software
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    19
 *
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    20
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
680
0bbe0e4d73c6 add reference to Emmanuelle in Authors/Copyright
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 679
diff changeset
    21
 * TimeStep support by Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
25
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    22
 */
679
0c4773ca0f29 avoid cyclic dependency between Simulator and Time code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 678
diff changeset
    23
#include "nstime.h"
372
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    24
#include "ns3/fatal-error.h"
684
333ec02c9cc9 add DefaultValue support for TimeStepPrecision
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 680
diff changeset
    25
#include "ns3/default-value.h"
679
0c4773ca0f29 avoid cyclic dependency between Simulator and Time code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 678
diff changeset
    26
#include <math.h>
25
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    27
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    28
namespace ns3 {
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    29
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    30
namespace TimeStepPrecision {
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    31
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
    32
static const uint64_t MS_FACTOR = (uint64_t)pow(10,3);
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
    33
static const uint64_t US_FACTOR = (uint64_t)pow(10,6);
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
    34
static const uint64_t NS_FACTOR = (uint64_t)pow(10,9);
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
    35
static const uint64_t PS_FACTOR = (uint64_t)pow(10,12);
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
    36
static const uint64_t FS_FACTOR = (uint64_t)pow(10,15);
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    37
static uint64_t g_tsPrecFactor = NS_FACTOR;
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
    38
684
333ec02c9cc9 add DefaultValue support for TimeStepPrecision
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 680
diff changeset
    39
static EnumDefaultValue<enum precision_t> g_precisionDefaultValue ("TimeStepPrecision", 
333ec02c9cc9 add DefaultValue support for TimeStepPrecision
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 680
diff changeset
    40
                                                                   "The time unit of the internal 64 bit integer time.",
333ec02c9cc9 add DefaultValue support for TimeStepPrecision
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 680
diff changeset
    41
                                                                   NS, "NS",
333ec02c9cc9 add DefaultValue support for TimeStepPrecision
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 680
diff changeset
    42
                                                                   S, "S",
333ec02c9cc9 add DefaultValue support for TimeStepPrecision
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 680
diff changeset
    43
                                                                   MS, "MS",
333ec02c9cc9 add DefaultValue support for TimeStepPrecision
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 680
diff changeset
    44
                                                                   US, "US",
333ec02c9cc9 add DefaultValue support for TimeStepPrecision
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 680
diff changeset
    45
                                                                   PS, "PS",
333ec02c9cc9 add DefaultValue support for TimeStepPrecision
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 680
diff changeset
    46
                                                                   FS, "FS",
333ec02c9cc9 add DefaultValue support for TimeStepPrecision
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 680
diff changeset
    47
                                                                   0, (void *)0);
333ec02c9cc9 add DefaultValue support for TimeStepPrecision
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 680
diff changeset
    48
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    49
precision_t
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    50
Get (void)
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
    51
{
684
333ec02c9cc9 add DefaultValue support for TimeStepPrecision
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 680
diff changeset
    52
  return g_precisionDefaultValue.GetValue ();
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
    53
}
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
    54
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
    55
void 
684
333ec02c9cc9 add DefaultValue support for TimeStepPrecision
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 680
diff changeset
    56
Set (precision_t precision)
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
    57
{
684
333ec02c9cc9 add DefaultValue support for TimeStepPrecision
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 680
diff changeset
    58
  g_precisionDefaultValue.SetValue (precision);
333ec02c9cc9 add DefaultValue support for TimeStepPrecision
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 680
diff changeset
    59
  g_tsPrecFactor = (uint64_t)pow(10, precision);
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
    60
}
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
    61
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    62
} // namespace TimeStepPrecision
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    63
372
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    64
TimeUnit<1>::TimeUnit(const std::string& s)
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    65
{
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    66
  std::string::size_type n = s.find_first_not_of("0123456789.");
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    67
  if (n != std::string::npos)
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    68
  { // Found non-numeric
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    69
    double r = atof(s.substr(0, n).c_str());
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    70
    std::string trailer = s.substr(n, std::string::npos);
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    71
    if (trailer == std::string("s"))
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    72
    {
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    73
      m_data = HighPrecision (r * TimeStepPrecision::g_tsPrecFactor);
372
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    74
      return;
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    75
    }
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    76
    if (trailer == std::string("ms"))
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    77
    {
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    78
      m_data = HighPrecision ((int64_t)(r * (TimeStepPrecision::g_tsPrecFactor/pow(10,3))), 
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
    79
                              false);
372
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    80
      return;
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    81
    }
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    82
    if (trailer == std::string("us"))
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    83
    {
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    84
      m_data = HighPrecision ((int64_t)(r * (TimeStepPrecision::g_tsPrecFactor/pow(10,6))), 
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
    85
                              false);
372
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    86
      return;
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    87
    }
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    88
    if (trailer == std::string("ns"))
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    89
    {
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    90
      m_data = HighPrecision ((int64_t)(r * (TimeStepPrecision::g_tsPrecFactor/pow(10,9))), 
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
    91
                              false);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
    92
      return;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
    93
    }
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
    94
    if (trailer == std::string("ps"))
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
    95
    {
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    96
      m_data = HighPrecision ((int64_t)(r * (TimeStepPrecision::g_tsPrecFactor/pow(10,12))), 
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
    97
                              false);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
    98
      return;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
    99
    }
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   100
    if (trailer == std::string("fs"))
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   101
    {
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   102
      m_data = HighPrecision ((int64_t)(r * (TimeStepPrecision::g_tsPrecFactor/pow(10,15))), 
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   103
                              false);
372
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
   104
      return;
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
   105
    }
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
   106
    NS_FATAL_ERROR("Can't Parse Time "<<s);
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
   107
  }
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
   108
  //else
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
   109
  //they didn't provide units, assume seconds
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   110
  m_data = HighPrecision (atof(s.c_str()) * TimeStepPrecision::g_tsPrecFactor);
372
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
   111
}
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   112
143
552ff26b4224 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   113
double 
339
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 229
diff changeset
   114
TimeUnit<1>::GetSeconds (void) const
36
e622fb7a8262 use ns as internal time and export time as ns.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 25
diff changeset
   115
{
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   116
  double timeValue = GetHighPrecision ().GetDouble ();
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   117
  return timeValue/TimeStepPrecision::g_tsPrecFactor;
25
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   118
}
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   119
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   120
int64_t
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   121
TimeUnit<1>::ConvertToUnits (int64_t timeValue, uint64_t unitFactor) const
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   122
{
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   123
  uint64_t precFactor;
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   124
  // In order to avoid conversion to double, precFactor can't be less 1
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   125
  if (TimeStepPrecision::g_tsPrecFactor < unitFactor)
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   126
    {
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   127
      precFactor = unitFactor / TimeStepPrecision::g_tsPrecFactor;
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   128
      timeValue = timeValue * precFactor;
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   129
    }
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   130
  else
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   131
    {
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   132
      precFactor = TimeStepPrecision::g_tsPrecFactor / unitFactor;
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   133
      timeValue = timeValue / precFactor;
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   134
    }
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   135
  return timeValue;
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   136
}
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   137
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   138
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   139
int64_t 
339
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 229
diff changeset
   140
TimeUnit<1>::GetMilliSeconds (void) const
36
e622fb7a8262 use ns as internal time and export time as ns.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 25
diff changeset
   141
{
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   142
  int64_t ts = GetTimeStep();
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   143
  int64_t ms = ConvertToUnits(ts, TimeStepPrecision::MS_FACTOR);
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   144
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   145
  return ms;
143
552ff26b4224 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   146
}
144
f07f6fb0f660 fix Time::ApproximateTo* return type
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
   147
int64_t 
339
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 229
diff changeset
   148
TimeUnit<1>::GetMicroSeconds (void) const
143
552ff26b4224 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   149
{
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   150
  int64_t ts = GetTimeStep();
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   151
  int64_t us = ConvertToUnits(ts, TimeStepPrecision::US_FACTOR);
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   152
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   153
  return us;
36
e622fb7a8262 use ns as internal time and export time as ns.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 25
diff changeset
   154
}
144
f07f6fb0f660 fix Time::ApproximateTo* return type
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
   155
int64_t 
339
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 229
diff changeset
   156
TimeUnit<1>::GetNanoSeconds (void) const
25
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   157
{
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   158
  int64_t ts = GetTimeStep();
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   159
  int64_t ns = ConvertToUnits(ts, TimeStepPrecision::NS_FACTOR);
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   160
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   161
  return ns;
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   162
}
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   163
int64_t 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   164
TimeUnit<1>::GetPicoSeconds (void) const
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   165
{
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   166
  int64_t ts = GetTimeStep();
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   167
  int64_t ps = ConvertToUnits(ts, TimeStepPrecision::PS_FACTOR);
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   168
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   169
  return ps;
36
e622fb7a8262 use ns as internal time and export time as ns.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 25
diff changeset
   170
}
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   171
int64_t 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   172
TimeUnit<1>::GetFemtoSeconds (void) const
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   173
{
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   174
  int64_t ts = GetTimeStep();
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   175
  int64_t fs = ConvertToUnits(ts, TimeStepPrecision::FS_FACTOR);
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   176
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   177
  return fs;
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   178
}
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   179
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   180
/**
684
333ec02c9cc9 add DefaultValue support for TimeStepPrecision
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 680
diff changeset
   181
 * This returns the value with the precision returned by TimeStepPrecision::Get
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   182
 */
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   183
int64_t
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   184
TimeUnit<1>::GetTimeStep (void) const
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   185
{
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   186
  int64_t timeValue = GetHighPrecision ().GetInteger ();
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   187
  return timeValue;
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   188
}
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   189
143
552ff26b4224 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   190
209
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
   191
std::ostream& 
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
   192
operator<< (std::ostream& os, Time const& time)
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
   193
{
911
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   194
  std::string unit;
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   195
  switch (TimeStepPrecision::Get ()) {
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   196
  case TimeStepPrecision::S:
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   197
    unit = "s";
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   198
    break;
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   199
  case TimeStepPrecision::MS:
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   200
    unit = "ms";
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   201
    break;
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   202
  case TimeStepPrecision::US:
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   203
    unit = "us";
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   204
    break;
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   205
  case TimeStepPrecision::NS:
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   206
    unit = "ns";
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   207
    break;
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   208
  case TimeStepPrecision::PS:
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   209
    unit = "ps";
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   210
    break;
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   211
  case TimeStepPrecision::FS:
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   212
    unit = "fs";
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   213
    break;
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   214
  }
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   215
  os << time.GetTimeStep () << unit;
209
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
   216
  return os;
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
   217
}
143
552ff26b4224 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   218
209
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
   219
Time Seconds (double seconds)
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
   220
{
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   221
  double d_sec = seconds * TimeStepPrecision::g_tsPrecFactor;
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   222
  return Time (HighPrecision (d_sec));
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   223
  //  return Time (HighPrecision ((int64_t)d_sec, false));
209
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
   224
}
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   225
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   226
uint64_t
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   227
TimeUnit<1>::UnitsToTimestep (uint64_t unitValue, 
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   228
                              uint64_t unitFactor)
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   229
{
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   230
  uint64_t precFactor;
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   231
  // In order to avoid conversion to double, precFactor can't be less 1
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   232
  if (TimeStepPrecision::g_tsPrecFactor < unitFactor)
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   233
    {
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   234
      precFactor = unitFactor / TimeStepPrecision::g_tsPrecFactor;
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   235
      unitValue = unitValue / precFactor;
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   236
    }
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   237
  else
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   238
    {
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   239
      precFactor = TimeStepPrecision::g_tsPrecFactor / unitFactor;
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   240
      unitValue = unitValue * precFactor;
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   241
    }
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   242
  return unitValue;
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   243
}
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   244
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   245
Time MilliSeconds (uint64_t ms)
209
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
   246
{
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   247
  uint64_t ts = TimeUnit<1>::UnitsToTimestep(ms, TimeStepPrecision::MS_FACTOR);
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   248
  return TimeStep(ts);
209
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
   249
}
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   250
209
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
   251
Time MicroSeconds (uint64_t us)
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
   252
{
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   253
  uint64_t ts = TimeUnit<1>::UnitsToTimestep(us, TimeStepPrecision::US_FACTOR);
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   254
  return TimeStep(ts);
209
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
   255
}
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   256
209
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
   257
Time NanoSeconds (uint64_t ns)
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
   258
{
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   259
  uint64_t ts = TimeUnit<1>::UnitsToTimestep(ns, TimeStepPrecision::NS_FACTOR);
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   260
  return TimeStep(ts);
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   261
}
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   262
Time PicoSeconds (uint64_t ps)
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   263
{
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   264
  uint64_t ts = TimeUnit<1>::UnitsToTimestep(ps, TimeStepPrecision::PS_FACTOR);
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   265
  return TimeStep(ts);
209
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 199
diff changeset
   266
}
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   267
Time FemtoSeconds (uint64_t fs)
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   268
{
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   269
  uint64_t ts = TimeUnit<1>::UnitsToTimestep(fs, TimeStepPrecision::FS_FACTOR);
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   270
  return TimeStep(ts);
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   271
}
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   272
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   273
/*
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   274
 * The timestep value passed to this function must be of the precision
684
333ec02c9cc9 add DefaultValue support for TimeStepPrecision
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 680
diff changeset
   275
 * of TimeStepPrecision::Get
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   276
 */
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   277
Time TimeStep (uint64_t ts)
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   278
{
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   279
  return Time (HighPrecision (ts, false));
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   280
}
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   281
339
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 229
diff changeset
   282
TimeUnit<0>::TimeUnit (double scalar)
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 229
diff changeset
   283
  : m_data (HighPrecision (scalar))
143
552ff26b4224 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   284
{}
156
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   285
158
47af319de4b8 implement Scalar::GetDouble
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 157
diff changeset
   286
double
339
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 229
diff changeset
   287
TimeUnit<0>::GetDouble (void) const
158
47af319de4b8 implement Scalar::GetDouble
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 157
diff changeset
   288
{
47af319de4b8 implement Scalar::GetDouble
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 157
diff changeset
   289
  return GetHighPrecision ().GetDouble ();
47af319de4b8 implement Scalar::GetDouble
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 157
diff changeset
   290
}
47af319de4b8 implement Scalar::GetDouble
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 157
diff changeset
   291
156
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   292
}; // namespace ns3
143
552ff26b4224 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   293
552ff26b4224 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   294
157
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   295
#ifdef RUN_SELF_TESTS
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   296
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   297
#include "ns3/test.h"
211
395e8b0d32a9 add a few more tests for the Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 209
diff changeset
   298
//#include <iostream>
157
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   299
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   300
namespace ns3 {
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   301
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   302
class TimeTests : public Test
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   303
{
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   304
public:
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   305
  TimeTests ();
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   306
  virtual ~TimeTests ();
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   307
  virtual bool RunTests (void);
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   308
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   309
  /*
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   310
   * Verifies that a calculated time value is as expected using
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   311
   * doubles since GetSeconds() returns a double
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   312
   */ 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   313
  void CheckTimeSec(std::string test_id, double actual, double expected, 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   314
                    bool *flag, double precMultFactor = 1, 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   315
                    bool verbose = false);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   316
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   317
  /*
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   318
   * Verifies that a calculated time value is as expected.
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   319
   */ 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   320
  void CheckTime(std::string test_id, int64_t actual, int64_t expected, 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   321
                 bool *flag, double precMultFactor = 1, 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   322
                 bool verbose = false);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   323
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   324
  /*
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   325
   * Verifies the +, -, * and / operations for the TimeUnit<1> or Time class
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   326
   */
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   327
  void CheckOperations(Time t0, Time t1, bool *ok, bool verbose = false);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   328
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   329
  /*
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   330
   * Verifies that the TimeUnit class stores values with the precision
684
333ec02c9cc9 add DefaultValue support for TimeStepPrecision
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 680
diff changeset
   331
   * set in the variable TimeStepPrecision::Get
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   332
   * Checks that overflow and underflow occur at expected numbers
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   333
   */
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   334
  void CheckPrecision(TimeStepPrecision::precision_t prec, uint64_t val, bool *ok,
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   335
                      bool verbose = false);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   336
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   337
  /*
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   338
   * Verifies that the conversion between units in the class
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   339
   * TimeUnit<1> or Time is done correctly. This is verified both when
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   340
   * setting and retrieving a Time value
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   341
   */
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   342
  void CheckConversions(uint64_t tval, bool *ok, bool verbose = false);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   343
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   344
  /*
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   345
   * These are the old tests that used to be run
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   346
   */
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   347
  void CheckOld(bool *ok);
157
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   348
};
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   349
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   350
TimeTests::TimeTests ()
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   351
  : Test ("Time")
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   352
{}
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   353
TimeTests::~TimeTests ()
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   354
{}
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   355
157
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   356
bool TimeTests::RunTests (void)
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   357
{
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   358
  bool ok = true;
176
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   359
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   360
  Time t0, t1;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   361
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   362
  CheckOld(&ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   363
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   364
  t0 = MilliSeconds ((uint64_t)10.0);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   365
  t1 = MilliSeconds ((uint64_t)11.0);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   366
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   367
  CheckOperations(t0, t1, &ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   368
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   369
  //  t0 = Seconds ((uint64_t)10.0);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   370
  //  t1 = Seconds ((uint64_t)11.0);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   371
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   372
  //  CheckOperations(t0, t1, &ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   373
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   374
  CheckConversions((uint64_t)5, &ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   375
  CheckConversions((uint64_t)0, &ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   376
  CheckConversions((uint64_t)783, &ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   377
  CheckConversions((uint64_t)1132, &ok);
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   378
  //  CheckConversions((uint64_t)3341039, &ok);
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   379
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   380
  // Now vary the precision and check the conversions
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   381
  if (TimeStepPrecision::Get () != TimeStepPrecision::NS) {
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   382
    ok = false;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   383
  }
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   384
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   385
  CheckPrecision(TimeStepPrecision::US, 7, &ok);
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   386
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   387
  CheckConversions((uint64_t)7, &ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   388
  CheckConversions((uint64_t)546, &ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   389
  CheckConversions((uint64_t)6231, &ok);
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   390
  //  CheckConversions((uint64_t)1234639, &ok);
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   391
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   392
  CheckPrecision(TimeStepPrecision::MS, 3, &ok);
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   393
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   394
  CheckConversions((uint64_t)3, &ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   395
  CheckConversions((uint64_t)134, &ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   396
  CheckConversions((uint64_t)2341, &ok);
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   397
  //  CheckConversions((uint64_t)8956239, &ok);
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   398
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   399
  CheckPrecision(TimeStepPrecision::PS, 21, &ok);
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   400
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   401
  CheckConversions((uint64_t)4, &ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   402
  CheckConversions((uint64_t)342, &ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   403
  CheckConversions((uint64_t)1327, &ok);
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   404
  //  CheckConversions((uint64_t)5439627, &ok);
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   405
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   406
  CheckPrecision(TimeStepPrecision::NS, 12, &ok);
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   407
  CheckConversions((uint64_t)12, &ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   408
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   409
  CheckPrecision(TimeStepPrecision::S, 7, &ok);
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   410
  CheckConversions((uint64_t)7, &ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   411
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   412
  CheckPrecision(TimeStepPrecision::FS, 5, &ok);
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   413
  CheckConversions((uint64_t)5, &ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   414
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   415
  TimeStepPrecision::Set (TimeStepPrecision::NS);
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   416
1224
7cbc1d661b89 rename Bind to DefaultValue::Bind. fix bug 62
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 911
diff changeset
   417
  DefaultValue::Bind ("TimeStepPrecision", "S");
7cbc1d661b89 rename Bind to DefaultValue::Bind. fix bug 62
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 911
diff changeset
   418
  DefaultValue::Bind ("TimeStepPrecision", "MS");
7cbc1d661b89 rename Bind to DefaultValue::Bind. fix bug 62
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 911
diff changeset
   419
  DefaultValue::Bind ("TimeStepPrecision", "US");
7cbc1d661b89 rename Bind to DefaultValue::Bind. fix bug 62
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 911
diff changeset
   420
  DefaultValue::Bind ("TimeStepPrecision", "NS");
7cbc1d661b89 rename Bind to DefaultValue::Bind. fix bug 62
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 911
diff changeset
   421
  DefaultValue::Bind ("TimeStepPrecision", "PS");
7cbc1d661b89 rename Bind to DefaultValue::Bind. fix bug 62
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 911
diff changeset
   422
  DefaultValue::Bind ("TimeStepPrecision", "FS");
684
333ec02c9cc9 add DefaultValue support for TimeStepPrecision
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 680
diff changeset
   423
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   424
  return ok;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   425
}
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   426
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   427
void TimeTests::CheckOld (bool *ok)
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   428
{
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   429
  double dt0, dt1, dt2;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   430
  int64_t it0, it1;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   431
157
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   432
  Time t0 = Seconds (10.0);
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   433
  CheckTimeSec("old 1", t0.GetSeconds(), 10.0, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   434
157
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   435
  Time t1 = Seconds (11.0);
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   436
  CheckTimeSec("old 2", t1.GetSeconds(), 11.0, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   437
176
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   438
  t0 = Seconds (1.5);
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   439
  CheckTimeSec("old 3", t0.GetSeconds(), 1.5, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   440
176
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   441
  t0 = Seconds (-1.5);
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   442
  CheckTimeSec("old 4", t0.GetSeconds(), -1.5, ok);
176
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   443
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   444
  t0 = MilliSeconds ((uint64_t)10.0);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   445
  dt0 = t0.GetSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   446
  CheckTimeSec("old 5", dt0, 0.01, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   447
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   448
  t1 = MilliSeconds ((uint64_t)11.0);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   449
  dt1 = t1.GetSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   450
  CheckTimeSec("old 6", dt1, 0.011, ok);
176
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   451
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   452
  Time t2, t3;
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   453
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   454
  t2 = t1 - t0;
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   455
  if (!t2.IsStrictlyPositive ())
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   456
    {
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   457
      ok = false;
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   458
    }
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   459
  dt2 = t2.GetSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   460
  CheckTimeSec("old 7", dt2, dt1-dt0, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   461
176
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   462
  t2 = t1 - t1;
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   463
  if (!t2.IsZero ())
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   464
    {
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   465
      ok = false;
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   466
    }
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   467
  dt2 = t2.GetSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   468
  CheckTimeSec("old 8", dt2, dt1-dt1, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   469
157
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   470
  t2 = t0 - t1;
176
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   471
  if (!t2.IsStrictlyNegative ())
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   472
    {
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   473
      ok = false;
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   474
    }
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   475
  dt2 = t2.GetSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   476
  CheckTimeSec("old 9", dt2, dt0-dt1, ok);
176
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   477
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   478
  t1 = NanoSeconds(15);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   479
  it0 = t0.GetNanoSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   480
  it1 = t1.GetNanoSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   481
  TimeUnit<-2> tu4 = t0 / (t1 * t1 * t1);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   482
  CheckTime("old 10", tu4.GetHighPrecision().GetInteger(), it0 / (it1*it1*it1), 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   483
            ok, 1e9);
157
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   484
211
395e8b0d32a9 add a few more tests for the Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 209
diff changeset
   485
  Time tmp = MilliSeconds (0);
395e8b0d32a9 add a few more tests for the Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 209
diff changeset
   486
  if ((tmp != NanoSeconds (0)) ||
395e8b0d32a9 add a few more tests for the Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 209
diff changeset
   487
      (tmp > NanoSeconds (0)) ||
395e8b0d32a9 add a few more tests for the Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 209
diff changeset
   488
      (tmp < NanoSeconds (0)))
395e8b0d32a9 add a few more tests for the Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 209
diff changeset
   489
    {
395e8b0d32a9 add a few more tests for the Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 209
diff changeset
   490
      ok = false;
395e8b0d32a9 add a few more tests for the Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 209
diff changeset
   491
    }
395e8b0d32a9 add a few more tests for the Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 209
diff changeset
   492
229
37f1ee32c76f avoid unused variable compiler warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 215
diff changeset
   493
  Time t4;
37f1ee32c76f avoid unused variable compiler warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 215
diff changeset
   494
  t4 = Seconds (10.0) * Scalar (1.5);
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   495
  CheckTimeSec("old 11", t4.GetSeconds(), 10, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   496
229
37f1ee32c76f avoid unused variable compiler warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 215
diff changeset
   497
  Time t5;
37f1ee32c76f avoid unused variable compiler warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 215
diff changeset
   498
  t5 = NanoSeconds (10) * Scalar (1.5);
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   499
  CheckTime("old 12", t5.GetNanoSeconds(), 10, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   500
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   501
  t4 = Seconds (10.0) * Scalar (15) / Scalar (10);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   502
  CheckTimeSec("old 13", t4.GetSeconds(), 15, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   503
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   504
  t5 = NanoSeconds (10) * Scalar (15) / Scalar (10);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   505
  CheckTime("old 14", t5.GetNanoSeconds(), 15, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   506
339
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 229
diff changeset
   507
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 229
diff changeset
   508
  double foo = (t1 + t2).GetSeconds ();
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   509
  dt1 = t1.GetSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   510
  dt2 = t2.GetSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   511
  CheckTimeSec("old 15", foo, dt1+dt2, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   512
339
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 229
diff changeset
   513
  foo += (t4 == t5)? 1 : 0;
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   514
  CheckTimeSec("old 16", foo, dt1+dt2, ok);
339
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 229
diff changeset
   515
0ce0402e419f make TimeUnit<1>.GetSeconds() work, and similar for scalars. Patch by Gustavo Carneiro.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 229
diff changeset
   516
  foo = (t1/t2).GetDouble ();
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   517
  CheckTimeSec("old 17", foo, dt1/dt2, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   518
}
157
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   519
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   520
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   521
void TimeTests::CheckOperations(Time t0, Time t1, bool *ok, bool verbose) 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   522
{
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   523
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   524
  if (verbose) 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   525
    std::cout << std::endl << "Check operations: " 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   526
              << t0 << " " << t1 << std::endl;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   527
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   528
  Time t2, t3;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   529
  double it0, it1, it2, it3, itu2, itu3;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   530
  int64_t iti0;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   531
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   532
  it0 = t0.GetSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   533
  it1 = t1.GetSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   534
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   535
  t2 = t0 - t1;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   536
  it2 = t2.GetSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   537
  CheckTimeSec("ops 1", it2, it0-it1, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   538
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   539
  t3 = t2 * t0 / t0;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   540
  it3 = t3.GetSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   541
  CheckTimeSec("ops 2a", it3, it2*it0/it0, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   542
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   543
  t3 = t2 * t0 / t1;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   544
  it3 = t3.GetSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   545
  CheckTimeSec("ops 2", it3, it2*it0/it1, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   546
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   547
  t3 = t0 * t2 / t1;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   548
  it3 = t3.GetSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   549
  CheckTimeSec("ops 3", it3, it0*it2/it1, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   550
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   551
  t3 = t0 * t1 / t2;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   552
  it3 = t3.GetSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   553
  CheckTimeSec("ops 4", it3, it0*it1/it2, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   554
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   555
  t3 = t0 * (t1 / t2);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   556
  it3 = t3.GetSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   557
  CheckTimeSec("ops 5", it3, it0*(it1/it2), ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   558
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   559
  t3 = (t0 * t1) / t2;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   560
  it3 = t3.GetSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   561
  CheckTimeSec("ops 6", it3, (it0*it1)/it2, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   562
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   563
  t3 = t0 / t1 * t2;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   564
  it3 = t3.GetSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   565
  CheckTimeSec("ops 7", it3, it0/it1*it2, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   566
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   567
  t3 = (t0 / t1) * t2;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   568
  it3 = t3.GetSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   569
  CheckTimeSec("ops 8", it3, (it0/it1)*it2, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   570
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   571
  t3 = t0 * Scalar (10.0);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   572
  it3 = t3.GetSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   573
  CheckTimeSec("ops 9", it3, it0*10, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   574
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   575
  t3 = Scalar (10.0) * t0;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   576
  it3 = t3.GetSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   577
  CheckTimeSec("ops 10", it3, 10 * it0, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   578
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   579
  t3 = Scalar (10.0) * t0 / t2 * t1;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   580
  it3 = t3.GetSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   581
  CheckTimeSec("ops 11", it3, 10 * it0 / it2 * it1, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   582
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   583
  t3 = (Scalar (10.0) * t0 ) / t2 * t1;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   584
  it3 = t3.GetSeconds();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   585
  CheckTimeSec("ops 12", it3, (10 * it0) / it2 * it1, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   586
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   587
  TimeInvert ti0;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   588
  ti0 = t0 / (t1 * t2);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   589
  iti0 = ti0.GetHighPrecision().GetInteger();
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   590
  // This check is not quite working yet.
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   591
  //  CheckTime("ops 13", iti0, (int64_t)(it0/(it1*it2)), ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   592
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   593
  Scalar s0 = t0 / t1;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   594
  CheckTimeSec("ops 14", s0.GetDouble(), it0/it1, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   595
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   596
  Scalar s1;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   597
  s1 = t0 * t1 / (t2 * t0);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   598
  CheckTimeSec("ops 15", s1.GetDouble(), it0*it1/(it2*it0), ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   599
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   600
  TimeUnit<0> tu0;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   601
  tu0 = s0;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   602
  CheckTimeSec("ops 16", tu0.GetDouble(), s0.GetDouble(), ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   603
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   604
  TimeUnit<1> tu1;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   605
  tu1 = t0;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   606
  CheckTimeSec("ops 17", tu1.GetSeconds(), it0, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   607
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   608
  TimeUnit<2> tu2;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   609
  tu2 = t0 * t1;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   610
  CheckTimeSec("ops 18", tu2.GetHighPrecision().GetInteger()/(1e18), 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   611
               it0 * it1, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   612
  itu2 = tu2.GetHighPrecision().GetInteger()/(1e18);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   613
  
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   614
  TimeUnit<3> tu3;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   615
  tu3 = t0 / Scalar(10e6) * tu2;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   616
  CheckTimeSec("ops 19", tu3.GetHighPrecision().GetInteger()/(1e27), 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   617
               it0 / 1000000 * itu2, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   618
  itu3 = tu3.GetHighPrecision().GetInteger()/(1e27);
157
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   619
}
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   620
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   621
void TimeTests::CheckConversions(uint64_t tval, bool *ok, bool verbose) {
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   622
  Time t_sec, t_ms, t_us, t_ns, t_ps, t_fs;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   623
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   624
  if (verbose) 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   625
    std::cout << std::endl << "Check conversions: " << tval << std::endl;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   626
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   627
  // First check the seconds
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   628
  t_sec = Seconds((double)tval);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   629
  CheckTimeSec("conv sec sec", t_sec.GetSeconds(), (double)tval, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   630
  CheckTime("conv sec ms", t_sec.GetMilliSeconds(), (int64_t)(tval*1e3), ok, 1e3);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   631
  CheckTime("conv sec us", t_sec.GetMicroSeconds(), (int64_t)(tval*1e6), ok, 1e6);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   632
  CheckTime("conv sec ns", t_sec.GetNanoSeconds(), (int64_t)(tval*1e9), ok, 1e9);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   633
  CheckTime("conv sec ps", t_sec.GetPicoSeconds(), 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   634
            (int64_t)(tval*1e12), ok, 1e12);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   635
  CheckTime("conv sec fs", t_sec.GetFemtoSeconds(), 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   636
            (int64_t)(tval*1e15), ok, 1e15);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   637
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   638
  // Then check the milliseconds
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   639
  t_ms = MilliSeconds(tval);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   640
  CheckTimeSec("conv ms sec", t_ms.GetSeconds(), (double)tval/1e3, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   641
  CheckTime("conv ms ms", t_ms.GetMilliSeconds(), (int64_t)(tval), ok, 1e3);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   642
  CheckTime("conv ms us", t_ms.GetMicroSeconds(), (int64_t)(tval*1e3), ok, 1e6);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   643
  CheckTime("conv ms ns", t_ms.GetNanoSeconds(), (int64_t)(tval*1e6), ok, 1e9);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   644
  CheckTime("conv ms ps", t_ms.GetPicoSeconds(), (int64_t)(tval*1e9), ok, 1e12);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   645
  CheckTime("conv ms fs", t_ms.GetFemtoSeconds(), (int64_t)(tval*1e12), ok, 1e15);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   646
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   647
  // Then check the microseconds
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   648
  t_us = MicroSeconds(tval);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   649
  CheckTimeSec("conv us sec", t_us.GetSeconds(), (double)tval/1e6, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   650
  CheckTime("conv us ms", t_us.GetMilliSeconds(), (int64_t)(tval/1e3), ok, 1e3);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   651
  CheckTime("conv us us", t_us.GetMicroSeconds(), (int64_t)(tval), ok, 1e6);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   652
  CheckTime("conv us ns", t_us.GetNanoSeconds(), (int64_t)(tval*1e3), ok, 1e9);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   653
  CheckTime("conv us ps", t_us.GetPicoSeconds(), (int64_t)(tval*1e6), ok, 1e12);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   654
  CheckTime("conv us fs", t_us.GetFemtoSeconds(), (int64_t)(tval*1e9), ok, 1e15);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   655
  
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   656
  // Then check the nanoseconds
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   657
  t_ns = NanoSeconds(tval);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   658
  CheckTimeSec("conv ns sec", t_ns.GetSeconds(), (double)tval/1e9, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   659
  CheckTime("conv ns ms", t_ns.GetMilliSeconds(), (int64_t)(tval/1e6), ok, 1e3);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   660
  CheckTime("conv ns us", t_ns.GetMicroSeconds(), (int64_t)(tval/1e3), ok, 1e6);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   661
  CheckTime("conv ns ns", t_ns.GetNanoSeconds(), (int64_t)(tval), ok, 1e9);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   662
  CheckTime("conv ns ps", t_ns.GetPicoSeconds(), (int64_t)(tval*1e3), ok, 1e12);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   663
  CheckTime("conv ns fs", t_ns.GetFemtoSeconds(), (int64_t)(tval*1e6), ok, 1e15);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   664
  
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   665
  // Then check the picoseconds
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   666
  t_ps = PicoSeconds(tval);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   667
  CheckTimeSec("conv ps sec", t_ps.GetSeconds(), (double)tval/1e12, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   668
  CheckTime("conv ps ms", t_ps.GetMilliSeconds(), (int64_t)(tval/1e9), ok, 1e3);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   669
  CheckTime("conv ps us", t_ps.GetMicroSeconds(), (int64_t)(tval/1e6), ok, 1e6);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   670
  CheckTime("conv ps ns", t_ps.GetNanoSeconds(), (int64_t)(tval/1e3), ok, 1e9);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   671
  CheckTime("conv ps ps", t_ps.GetPicoSeconds(), (int64_t)(tval), ok, 1e12);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   672
  CheckTime("conv ps fs", t_ps.GetFemtoSeconds(), (int64_t)(tval*1e3), ok, 1e15);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   673
  
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   674
  // Then check the femtoseconds
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   675
  t_fs = FemtoSeconds(tval);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   676
  CheckTimeSec("conv fs sec", t_fs.GetSeconds(), (double)tval/1e15, ok);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   677
  CheckTime("conv fs ms", t_fs.GetMilliSeconds(), (int64_t)(tval/1e12), ok, 1e3);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   678
  CheckTime("conv fs us", t_fs.GetMicroSeconds(), (int64_t)(tval/1e9), ok, 1e6);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   679
  CheckTime("conv fs ns", t_fs.GetNanoSeconds(), (int64_t)(tval/1e6), ok, 1e9);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   680
  CheckTime("conv fs ps", t_fs.GetPicoSeconds(), (int64_t)(tval/1e3), ok, 1e12);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   681
  CheckTime("conv fs fs", t_fs.GetFemtoSeconds(), (int64_t)(tval), ok, 1e15);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   682
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   683
  
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   684
}
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   685
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   686
void TimeTests::CheckPrecision(TimeStepPrecision::precision_t prec, uint64_t val, bool *ok, 
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   687
                               bool verbose) {
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   688
  if (verbose) {
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   689
    std::cout << "check precision 10^-" << prec << std::endl;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   690
  }
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   691
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   692
  TimeStepPrecision::Set (prec);
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   693
  if (TimeStepPrecision::Get () != prec) {
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   694
    ok = false;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   695
  }
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   696
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   697
  /* These still need to be fixed.
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   698
  // The smallest value that can be stored is 1x10^(-prec)
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   699
  Time smallest = Seconds(pow(10,-prec));
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   700
  CheckTimeSec("Prec small:     ", smallest.GetSeconds(), pow(10,-prec), ok, 0.1, 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   701
               true);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   702
  
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   703
  double d_ts = pow(10,-prec) - pow(10, -(prec+3));
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   704
  Time too_small = Seconds(d_ts);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   705
  CheckTimeSec("Prec too small: ", too_small.GetSeconds(), 0, ok, 0.1, true);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   706
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   707
  double d_la = 0xFFFFFFFF*pow(10,-prec);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   708
  Time largest = Seconds(d_la);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   709
  CheckTimeSec("Prec large:     ", largest.GetSeconds(), d_la, ok, 0.1, true);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   710
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   711
  double d_tl = (0xFFFFFFFF*pow(10,-prec)) + 1;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   712
  Time too_large = Seconds(d_tl);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   713
  if ((largest.GetSeconds() + 1) == too_large.GetSeconds())
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   714
    std::cout << "Overflow did not occur." << std::endl;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   715
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   716
  NS_ASSERT(d_la+1 == d_tl);
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   717
  */  
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   718
}
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   719
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   720
void TimeTests::CheckTimeSec (std::string test_id, double actual, 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   721
                              double expected, bool *flag, double precMultFactor,
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   722
                              bool verbose)
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   723
{
684
333ec02c9cc9 add DefaultValue support for TimeStepPrecision
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 680
diff changeset
   724
  double prec = pow(10,-((double)(ns3::TimeStepPrecision::Get ()))) * precMultFactor;
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   725
  if ((actual < (expected-prec)) || (actual > (expected+prec))) {
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   726
    std::cout << "FAIL " << test_id 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   727
              << " Expected:" << expected 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   728
              << " Actual: " << actual
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   729
              << " Precision: " << prec << std::endl;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   730
    *flag = false;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   731
  } else {
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   732
    if (verbose) {
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   733
      std::cout << "PASS " << test_id 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   734
                << " Expected:" << expected 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   735
                << " Actual: " << actual
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   736
                << " Precision: " << prec << std::endl;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   737
    }
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   738
  }
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   739
}
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   740
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   741
void TimeTests::CheckTime (std::string test_id, int64_t actual, 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   742
                           int64_t expected, bool *flag, double precMultFactor,
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   743
                           bool verbose)
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   744
{
684
333ec02c9cc9 add DefaultValue support for TimeStepPrecision
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 680
diff changeset
   745
  double prec = pow(10,-((double)(ns3::TimeStepPrecision::Get ()))) * precMultFactor;
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   746
  if ((actual < (expected-prec)) || (actual > (expected+prec))) {
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   747
    std::cout << "FAIL " << test_id 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   748
              << " Expected:" << expected 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   749
              << " Actual: " << actual
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   750
              << " Precision: " << prec << std::endl;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   751
    *flag = false;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   752
  } else {
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   753
    if (verbose) {
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   754
      std::cout << "PASS " << test_id 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   755
                << " Expected:" << expected 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   756
                << " Actual: " << actual 
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   757
                << " Precision: " << prec << std::endl;
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   758
    }
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   759
  }
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   760
}
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   761
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   762
157
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   763
static TimeTests g_time_tests;
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   764
  
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   765
};
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   766
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   767
#endif /* RUN_SELF_TESTS */