src/simulator/time.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Thu, 17 Apr 2008 13:42:25 -0700
changeset 2965 4b28e9740e3b
parent 2953 db884a56c5c1
child 3188 080e43146c47
permissions -rw-r--r--
get rid of Attribute class. Use AttributeValue subclasses directly.
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
 *
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     6
 * 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
     7
 * 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
     8
 * 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
     9
 *
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    10
 * 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
    11
 * 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
    12
 * 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
    13
 * 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
    14
 *
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    15
 * 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
    16
 * 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
    17
 * 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
    18
 *
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    19
 * 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
    20
 * 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
    21
 */
679
0c4773ca0f29 avoid cyclic dependency between Simulator and Time code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 678
diff changeset
    22
#include "nstime.h"
372
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    23
#include "ns3/fatal-error.h"
2577
5b41cb5c3fcf kill DefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2447
diff changeset
    24
#include "ns3/global-value.h"
5b41cb5c3fcf kill DefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2447
diff changeset
    25
#include "ns3/enum.h"
5b41cb5c3fcf kill DefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2447
diff changeset
    26
#include "ns3/string.h"
2390
7e6dfae536cd add Value support to Time
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2170
diff changeset
    27
#include "ns3/object.h"
2577
5b41cb5c3fcf kill DefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2447
diff changeset
    28
#include "ns3/config.h"
679
0c4773ca0f29 avoid cyclic dependency between Simulator and Time code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 678
diff changeset
    29
#include <math.h>
25
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    30
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    31
namespace ns3 {
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    32
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    33
namespace TimeStepPrecision {
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    34
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
    35
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
    36
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
    37
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
    38
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
    39
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
    40
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
    41
2577
5b41cb5c3fcf kill DefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2447
diff changeset
    42
static GlobalValue g_precisionDefaultValue ("TimeStepPrecision", 
5b41cb5c3fcf kill DefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2447
diff changeset
    43
                                            "The time unit of the internal 64 bit integer time.",
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2953
diff changeset
    44
                                            EnumValue (NS),
2577
5b41cb5c3fcf kill DefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2447
diff changeset
    45
                                            MakeEnumChecker (NS, "NS",
5b41cb5c3fcf kill DefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2447
diff changeset
    46
                                                             S, "S",
5b41cb5c3fcf kill DefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2447
diff changeset
    47
                                                             MS, "MS",
5b41cb5c3fcf kill DefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2447
diff changeset
    48
                                                             US, "US",
5b41cb5c3fcf kill DefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2447
diff changeset
    49
                                                             PS, "PS",
5b41cb5c3fcf kill DefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2447
diff changeset
    50
                                                             FS, "FS")
5b41cb5c3fcf kill DefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2447
diff changeset
    51
                                            );
684
333ec02c9cc9 add DefaultValue support for TimeStepPrecision
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 680
diff changeset
    52
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    53
precision_t
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    54
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
    55
{
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2953
diff changeset
    56
  EnumValue v;
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2953
diff changeset
    57
  g_precisionDefaultValue.GetValue (v);
2577
5b41cb5c3fcf kill DefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2447
diff changeset
    58
  return (precision_t) v.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
    59
}
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
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
    61
void 
684
333ec02c9cc9 add DefaultValue support for TimeStepPrecision
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 680
diff changeset
    62
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
    63
{
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2953
diff changeset
    64
  g_precisionDefaultValue.SetValue (EnumValue (precision));
684
333ec02c9cc9 add DefaultValue support for TimeStepPrecision
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 680
diff changeset
    65
  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
    66
}
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
    67
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    68
} // namespace TimeStepPrecision
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    69
372
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    70
TimeUnit<1>::TimeUnit(const std::string& s)
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    71
{
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    72
  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
    73
  if (n != std::string::npos)
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    74
  { // Found non-numeric
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    75
    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
    76
    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
    77
    if (trailer == std::string("s"))
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    78
    {
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
    79
      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
    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("ms"))
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,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
    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("us"))
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,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
    91
                              false);
372
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    92
      return;
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    93
    }
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
    94
    if (trailer == std::string("ns"))
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
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,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
    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("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
   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,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
   103
                              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
   104
      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
   105
    }
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   106
    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
   107
    {
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   108
      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
   109
                              false);
372
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
   110
      return;
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
   111
    }
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
   112
    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
   113
  }
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
   114
  //else
c242f488ef0b Added back corrected version of TimeUnit(string)
Raj@rajib-bhattacharjeas-computer.local
parents: 367
diff changeset
   115
  //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
   116
  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
   117
}
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
   118
143
552ff26b4224 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   119
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
   120
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
   121
{
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   122
  double timeValue = GetHighPrecision ().GetDouble ();
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   123
  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
   124
}
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   125
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   126
int64_t
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   127
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
   128
{
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   129
  uint64_t precFactor;
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   130
  // 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
   131
  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
   132
    {
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   133
      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
   134
      timeValue = timeValue * precFactor;
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   135
    }
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   136
  else
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   137
    {
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   138
      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
   139
      timeValue = timeValue / precFactor;
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   140
    }
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   141
  return timeValue;
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   142
}
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   143
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   144
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
   145
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
   146
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
   147
{
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   148
  int64_t ts = GetTimeStep();
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   149
  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
   150
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   151
  return ms;
143
552ff26b4224 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   152
}
144
f07f6fb0f660 fix Time::ApproximateTo* return type
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
   153
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
   154
TimeUnit<1>::GetMicroSeconds (void) const
143
552ff26b4224 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   155
{
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   156
  int64_t ts = GetTimeStep();
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   157
  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
   158
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   159
  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
   160
}
144
f07f6fb0f660 fix Time::ApproximateTo* return type
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
   161
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
   162
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
   163
{
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   164
  int64_t ts = GetTimeStep();
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   165
  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
   166
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   167
  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
   168
}
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   169
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
   170
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
   171
{
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   172
  int64_t ts = GetTimeStep();
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   173
  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
   174
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   175
  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
   176
}
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
   177
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
   178
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
   179
{
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   180
  int64_t ts = GetTimeStep();
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   181
  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
   182
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   183
  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
   184
}
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
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   186
/**
684
333ec02c9cc9 add DefaultValue support for TimeStepPrecision
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 680
diff changeset
   187
 * 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
   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
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
   190
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
   191
{
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   192
  int64_t timeValue = GetHighPrecision ().GetInteger ();
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   193
  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
   194
}
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   195
143
552ff26b4224 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   196
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
   197
std::ostream& 
2409
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   198
operator<< (std::ostream& os, const Time & time)
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
   199
{
911
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   200
  std::string unit;
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   201
  switch (TimeStepPrecision::Get ()) {
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   202
  case TimeStepPrecision::S:
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   203
    unit = "s";
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::MS:
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   206
    unit = "ms";
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::US:
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   209
    unit = "us";
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::NS:
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   212
    unit = "ns";
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
  case TimeStepPrecision::PS:
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   215
    unit = "ps";
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   216
    break;
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   217
  case TimeStepPrecision::FS:
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   218
    unit = "fs";
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   219
    break;
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   220
  }
de8102a51fbf append correct unit when printing Time objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 684
diff changeset
   221
  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
   222
  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
   223
}
2409
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   224
std::istream& operator>> (std::istream& is, Time & time)
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   225
{
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   226
  std::string value;
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   227
  is >> value;
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   228
  std::string::size_type n = value.find_first_not_of("0123456789.");
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   229
  if (n == std::string::npos)
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   230
    {
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   231
      is.setstate (std::ios_base::failbit);
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   232
      return is;
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   233
    }
2953
db884a56c5c1 -1 cuts the trailing s if the time postfix is longer than 1 char.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2947
diff changeset
   234
  std::string trailer = value.substr(n, value.size ()-n);
2409
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   235
  std::istringstream iss;
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   236
  iss.str (value.substr(0, n));
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   237
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   238
  if (trailer == std::string("s"))
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   239
    {
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   240
      double v;
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   241
      iss >> v;
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   242
      time = Seconds (v);
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   243
      return is;
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   244
    }
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   245
  uint64_t integer;
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   246
  iss >> integer;
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   247
  if (is.bad () || is.fail ())
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   248
    {
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   249
      is.setstate (std::ios_base::failbit);
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   250
    }
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   251
  else if (trailer == std::string("ms"))
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   252
    {
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   253
      time = MilliSeconds (integer);
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   254
    }
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   255
  else if (trailer == std::string("us"))
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   256
    {
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   257
      time = MicroSeconds (integer);
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   258
    }
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   259
  else if (trailer == std::string("ns"))
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   260
    {
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   261
      time = NanoSeconds (integer);
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   262
    }
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   263
  else if (trailer == std::string("ps"))
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   264
    {
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   265
      time = PicoSeconds (integer);
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   266
    }
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   267
  else if (trailer == std::string("fs"))
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   268
    {
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   269
      time = FemtoSeconds (integer);
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   270
    }
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   271
  else
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   272
    {
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   273
      is.setstate (std::ios_base::failbit);
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   274
      // XXX: problem ?
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   275
    }
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   276
  return is;
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2396
diff changeset
   277
}
143
552ff26b4224 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   278
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
   279
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
   280
{
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   281
  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
   282
  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
   283
  //  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
   284
}
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
   285
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   286
uint64_t
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   287
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
   288
                              uint64_t unitFactor)
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   289
{
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   290
  uint64_t precFactor;
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   291
  // 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
   292
  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
   293
    {
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   294
      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
   295
      unitValue = unitValue / precFactor;
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   296
    }
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   297
  else
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   298
    {
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   299
      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
   300
      unitValue = unitValue * precFactor;
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   301
    }
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   302
  return unitValue;
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   303
}
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   304
2447
eee344085a96 convert to new helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2436
diff changeset
   305
ATTRIBUTE_VALUE_IMPLEMENT (Time);
eee344085a96 convert to new helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2436
diff changeset
   306
ATTRIBUTE_CHECKER_IMPLEMENT (Time);
2427
9245ec163111 split checker from ParamSpec.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2409
diff changeset
   307
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
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
   309
{
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   310
  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
   311
  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
   312
}
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
   313
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
   314
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
   315
{
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   316
  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
   317
  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
   318
}
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
   319
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
   320
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
   321
{
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   322
  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
   323
  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
   324
}
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
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
   326
{
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   327
  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
   328
  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
   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
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
   331
{
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   332
  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
   333
  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
   334
}
2390
7e6dfae536cd add Value support to Time
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2170
diff changeset
   335
7e6dfae536cd add Value support to Time
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2170
diff changeset
   336
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   337
/*
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   338
 * 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
   339
 * 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
   340
 */
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
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
   342
{
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
  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
   344
}
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
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
   346
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
   347
  : m_data (HighPrecision (scalar))
143
552ff26b4224 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   348
{}
156
3b1563e95ea7 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 151
diff changeset
   349
158
47af319de4b8 implement Scalar::GetDouble
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 157
diff changeset
   350
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
   351
TimeUnit<0>::GetDouble (void) const
158
47af319de4b8 implement Scalar::GetDouble
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 157
diff changeset
   352
{
47af319de4b8 implement Scalar::GetDouble
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 157
diff changeset
   353
  return GetHighPrecision ().GetDouble ();
47af319de4b8 implement Scalar::GetDouble
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 157
diff changeset
   354
}
47af319de4b8 implement Scalar::GetDouble
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 157
diff changeset
   355
2390
7e6dfae536cd add Value support to Time
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2170
diff changeset
   356
} // namespace ns3
143
552ff26b4224 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   357
552ff26b4224 new Time implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   358
157
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   359
#ifdef RUN_SELF_TESTS
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   360
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   361
#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
   362
//#include <iostream>
157
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   363
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   364
namespace ns3 {
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   365
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   366
class TimeTests : public Test
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   367
{
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   368
public:
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   369
  TimeTests ();
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   370
  virtual ~TimeTests ();
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   371
  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
   372
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   373
  /*
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
   374
   * 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
   375
   * 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
   376
   */ 
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
  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
   378
                    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
   379
                    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
   380
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   381
  /*
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
   * 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
   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
  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
   385
                 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
   386
                 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
   387
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   388
  /*
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
   389
   * 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
   390
   */
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
  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
   392
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   393
  /*
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
   394
   * 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
   395
   * 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
   396
   * 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
   397
   */
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   398
  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
   399
                      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
   400
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   401
  /*
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
   402
   * 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
   403
   * 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
   404
   * 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
   405
   */
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   406
  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
   407
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   408
  /*
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
   409
   * 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
   410
   */
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
  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
   412
};
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   413
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   414
TimeTests::TimeTests ()
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   415
  : Test ("Time")
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   416
{}
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   417
TimeTests::~TimeTests ()
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   418
{}
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
   419
157
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   420
bool TimeTests::RunTests (void)
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   421
{
1829
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   422
  bool result = true;
176
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
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
  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
   425
1829
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   426
  CheckOld(&result);
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
   427
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
  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
   429
  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
   430
1829
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   431
  CheckOperations(t0, t1, &result);
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
   432
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
  //  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
   434
  //  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
   435
1829
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   436
  //  CheckOperations(t0, t1, &result);
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
   437
1829
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   438
  CheckConversions((uint64_t)5, &result);
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   439
  CheckConversions((uint64_t)0, &result);
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   440
  CheckConversions((uint64_t)783, &result);
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   441
  CheckConversions((uint64_t)1132, &result);
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   442
  //  CheckConversions((uint64_t)3341039, &result);
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
   443
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
  // 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
   445
  if (TimeStepPrecision::Get () != TimeStepPrecision::NS) {
1829
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   446
    result = false;
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
   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
1829
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   449
  CheckPrecision(TimeStepPrecision::US, 7, &result);
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
   450
1829
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   451
  CheckConversions((uint64_t)7, &result);
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   452
  CheckConversions((uint64_t)546, &result);
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   453
  CheckConversions((uint64_t)6231, &result);
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   454
  //  CheckConversions((uint64_t)1234639, &result);
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
   455
1829
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   456
  CheckPrecision(TimeStepPrecision::MS, 3, &result);
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
   457
1829
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   458
  CheckConversions((uint64_t)3, &result);
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   459
  CheckConversions((uint64_t)134, &result);
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   460
  CheckConversions((uint64_t)2341, &result);
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   461
  //  CheckConversions((uint64_t)8956239, &result);
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
   462
1829
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   463
  CheckPrecision(TimeStepPrecision::PS, 21, &result);
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
   464
1829
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   465
  CheckConversions((uint64_t)4, &result);
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   466
  CheckConversions((uint64_t)342, &result);
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   467
  CheckConversions((uint64_t)1327, &result);
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   468
  //  CheckConversions((uint64_t)5439627, &result);
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
   469
1829
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   470
  CheckPrecision(TimeStepPrecision::NS, 12, &result);
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   471
  CheckConversions((uint64_t)12, &result);
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
   472
1829
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   473
  CheckPrecision(TimeStepPrecision::S, 7, &result);
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   474
  CheckConversions((uint64_t)7, &result);
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
1829
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   476
  CheckPrecision(TimeStepPrecision::FS, 5, &result);
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   477
  CheckConversions((uint64_t)5, &result);
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
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   479
  TimeStepPrecision::Set (TimeStepPrecision::NS);
676
0cf407300fa6 Fixed the problems that were found by Mathieu Lacage in the first
Emmanuelle Laprise
parents: 675
diff changeset
   480
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2953
diff changeset
   481
  Config::SetGlobal ("TimeStepPrecision", StringValue ("S"));
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2953
diff changeset
   482
  Config::SetGlobal ("TimeStepPrecision", StringValue ("MS"));
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2953
diff changeset
   483
  Config::SetGlobal ("TimeStepPrecision", StringValue ("US"));
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2953
diff changeset
   484
  Config::SetGlobal ("TimeStepPrecision", StringValue ("NS"));
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2953
diff changeset
   485
  Config::SetGlobal ("TimeStepPrecision", StringValue ("PS"));
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2953
diff changeset
   486
  Config::SetGlobal ("TimeStepPrecision", StringValue ("FS"));
684
333ec02c9cc9 add DefaultValue support for TimeStepPrecision
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 680
diff changeset
   487
1829
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   488
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   489
  Time tooBig = TimeStep (0x8000000000000000LL);
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   490
  NS_TEST_ASSERT (tooBig.IsNegative ());
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   491
  tooBig = TimeStep (0xffffffffffffffffLL);
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   492
  NS_TEST_ASSERT (tooBig.IsNegative ());
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   493
  tooBig = TimeStep (0x7fffffffffffffffLL);
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   494
  NS_TEST_ASSERT (tooBig.IsPositive ());
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   495
  tooBig += TimeStep (1);
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   496
  NS_TEST_ASSERT (tooBig.IsNegative ());
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   497
4a4799006fab check for Time bounds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1696
diff changeset
   498
  return result;
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
}
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
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
   502
{
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
  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
   504
  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
   505
157
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   506
  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
   507
  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
   508
157
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   509
  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
   510
  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
   511
176
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   512
  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
   513
  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
   514
176
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   515
  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
   516
  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
   517
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
   518
  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
   519
  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
   520
  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
   521
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
  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
   523
  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
   524
  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
   525
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   526
  Time t2, t3;
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   527
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   528
  t2 = t1 - t0;
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   529
  if (!t2.IsStrictlyPositive ())
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   530
    {
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   531
      ok = false;
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   532
    }
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
   533
  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
   534
  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
   535
176
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   536
  t2 = t1 - t1;
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   537
  if (!t2.IsZero ())
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   538
    {
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   539
      ok = false;
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   540
    }
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
   541
  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
   542
  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
   543
157
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   544
  t2 = t0 - t1;
176
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   545
  if (!t2.IsStrictlyNegative ())
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   546
    {
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   547
      ok = false;
74494759f122 more tests for Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 170
diff changeset
   548
    }
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
   549
  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
   550
  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
   551
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
   552
  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
   553
  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
   554
  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
   555
  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
   556
  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
   557
            ok, 1e9);
157
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   558
211
395e8b0d32a9 add a few more tests for the Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 209
diff changeset
   559
  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
   560
  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
   561
      (tmp > NanoSeconds (0)) ||
395e8b0d32a9 add a few more tests for the Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 209
diff changeset
   562
      (tmp < NanoSeconds (0)))
395e8b0d32a9 add a few more tests for the Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 209
diff changeset
   563
    {
395e8b0d32a9 add a few more tests for the Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 209
diff changeset
   564
      ok = false;
395e8b0d32a9 add a few more tests for the Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 209
diff changeset
   565
    }
395e8b0d32a9 add a few more tests for the Time class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 209
diff changeset
   566
229
37f1ee32c76f avoid unused variable compiler warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 215
diff changeset
   567
  Time t4;
37f1ee32c76f avoid unused variable compiler warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 215
diff changeset
   568
  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
   569
  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
   570
229
37f1ee32c76f avoid unused variable compiler warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 215
diff changeset
   571
  Time t5;
37f1ee32c76f avoid unused variable compiler warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 215
diff changeset
   572
  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
   573
  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
   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
  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
   576
  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
   577
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
  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
   579
  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
   580
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
   581
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
   582
  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
   583
  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
   584
  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
   585
  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
   586
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
   587
  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
   588
  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
   589
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
   590
  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
   591
  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
   592
}
157
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   593
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
   594
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
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
   596
{
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
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
  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
   599
    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
   600
              << 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
   601
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
  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
   603
  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
   604
  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
   605
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
  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
   607
  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
   608
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
  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
   610
  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
   611
  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
   612
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
  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
   614
  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
   615
  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
   616
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
  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
   618
  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
   619
  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
   620
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
  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
   622
  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
   623
  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
   624
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
  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
   626
  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
   627
  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
   628
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
  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
   630
  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
   631
  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
   632
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
  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
   634
  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
   635
  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
   636
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
  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
   638
  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
   639
  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
   640
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
  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
   642
  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
   643
  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
   644
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
  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
   646
  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
   647
  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
   648
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
  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
   650
  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
   651
  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
   652
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
  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
   654
  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
   655
  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
   656
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
  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
   658
  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
   659
  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
   660
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
  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
   662
  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
   663
  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
   664
  // 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
   665
  //  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
   666
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
  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
   668
  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
   669
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
  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
   671
  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
   672
  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
   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
  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
   675
  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
   676
  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
   677
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
  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
   679
  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
   680
  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
   681
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
  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
   683
  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
   684
  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
   685
               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
   686
  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
   687
  
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
  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
   689
  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
   690
  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
   691
               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
   692
  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
   693
}
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   694
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
   695
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
   696
  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
   697
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
  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
   699
    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
   700
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
  // 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
   702
  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
   703
  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
   704
  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
   705
  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
   706
  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
   707
  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
   708
            (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
   709
  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
   710
            (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
   711
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
  // 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
   713
  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
   714
  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
   715
  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
   716
  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
   717
  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
   718
  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
   719
  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
   720
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
  // 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
   722
  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
   723
  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
   724
  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
   725
  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
   726
  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
   727
  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
   728
  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
   729
  
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
  // 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
   731
  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
   732
  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
   733
  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
   734
  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
   735
  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
   736
  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
   737
  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
   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
  // 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
   740
  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
   741
  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
   742
  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
   743
  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
   744
  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
   745
  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
   746
  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
   747
  
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
  // 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
   749
  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
   750
  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
   751
  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
   752
  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
   753
  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
   754
  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
   755
  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
   756
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
  
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
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   760
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
   761
                               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
   762
  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
   763
    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
   764
  }
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   765
677
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   766
  TimeStepPrecision::Set (prec);
de21f6a2435e namespace the precision values properly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 676
diff changeset
   767
  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
   768
    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
   769
  }
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   770
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   771
  /* 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
   772
  // 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
   773
  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
   774
  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
   775
               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
   776
  
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   777
  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
   778
  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
   779
  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
   780
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   781
  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
   782
  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
   783
  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
   784
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   785
  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
   786
  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
   787
  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
   788
    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
   789
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   790
  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
   791
  */  
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   792
}
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   793
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   794
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
   795
                              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
   796
                              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
   797
{
684
333ec02c9cc9 add DefaultValue support for TimeStepPrecision
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 680
diff changeset
   798
  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
   799
  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
   800
    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
   801
              << " 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
   802
              << " 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
   803
              << " 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
   804
    *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
   805
  } 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
   806
    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
   807
      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
   808
                << " 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
   809
                << " 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
   810
                << " 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
   811
    }
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   812
  }
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   813
}
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   814
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   815
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
   816
                           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
   817
                           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
   818
{
684
333ec02c9cc9 add DefaultValue support for TimeStepPrecision
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 680
diff changeset
   819
  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
   820
  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
   821
    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
   822
              << " 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
   823
              << " 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
   824
              << " 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
   825
    *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
   826
  } 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
   827
    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
   828
      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
   829
                << " 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
   830
                << " 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
   831
                << " 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
   832
    }
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   833
  }
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   834
}
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   835
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 372
diff changeset
   836
157
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   837
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
   838
  
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   839
};
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   840
19ffb62f521e add a bunch of tests for Time classes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 156
diff changeset
   841
#endif /* RUN_SELF_TESTS */