예제 #1
0
 def test_03(self):
     """TestUnitsBasic.test_03(): 1e5  fixed units converted to and fro and tested to 10 Sig. Fig."""
     myCats = Units.unitCategories()
     cCount = 0
     random.seed()
     tS = time.perf_counter()
     while cCount < 1e2:
         # Choose a category at random
         iC = random.randint(0, len(myCats) - 1)
         myUnits = Units.units(myCats[iC])
         iU_1 = random.randint(0, len(myUnits) - 1)
         iU_2 = random.randint(0, len(myUnits) - 1)
         val = random.random()
         uCount = 0
         while uCount < 1e3:
             newVal = Units.convert(val, myUnits[iU_1], myUnits[iU_2])
             self.assertAlmostEqual(
                 Units.convert(newVal, myUnits[iU_2], myUnits[iU_1]),
                 val,
                 places=10,
             )
             uCount += 1
         cCount += 1
     tE = time.perf_counter() - tS
     sys.stderr.write('Time: %8.3f rate %10.3f k/S ' %
                      (tE, (cCount * uCount) / (1024 * tE)))
예제 #2
0
 def test_01(self):
     """TestUnitsBasic.test_01(): 1e5 random units converted to and fro and tested to 10 Sig. Fig."""
     myCats = Units.unitCategories()
     cCount = 0
     random.seed()
     tS = time.clock()
     while cCount < 1e2:
         # Choose a category at random
         iC = random.randint(0, len(myCats) - 1)
         myUnits = Units.units(myCats[iC])
         #print 'Category: %s' % myCats[iC]
         #print '   Units: %s' % ', '.join(myUnits)
         uCount = 0
         while uCount < 1e3:
             iU_1 = random.randint(0, len(myUnits) - 1)
             iU_2 = random.randint(0, len(myUnits) - 1)
             val = random.random()
             newVal = Units.convert(val, myUnits[iU_1], myUnits[iU_2])
             oldVal = Units.convert(newVal, myUnits[iU_2], myUnits[iU_1])
             #print
             #print(oldVal)
             self.assertAlmostEqual(oldVal, val, places=10)
             #self.assertAlmostEqual(oldVal, val)
             uCount += 1
         cCount += 1
     tE = time.clock() - tS
     sys.stderr.write('Time: %8.3f rate %10.3f k/S ' %
                      (tE, (cCount * uCount) / (1024 * tE)))
예제 #3
0
 def test_01(self):
     """TestInternals(): __UNIT_MAP."""
     #print
     #print Units.unitCategories()
     self.assertEqual(
         sorted(Units.unitCategories()),
         sorted([
             b'VELO',
             b'CURR',
             b'ACCE',
             b'VISC',
             b'COND',
             b'ENER',
             b'TTIM',
             b'V/LE',
             b'DFRA',
             b'TEMP',
             b'HTRA',
             b'DENS',
             b'PERM',
             b'ATTE',
             b'MASS',
             b'ROTA',
             b'EGR ',
             b'T/L ',
             b'POWE',
             b'UNKN',
             b'LENG',
             b'DIME',
             b'FORC',
             b'ILEN',
             b'VOLU',
             b'RESI',
             b'C/T ',
             b'M/L ',
             b'PLEN',
             b'FREQ',
             b'IMAS',
             b'ERES',
             b'EPOT',
             b'RVEL',
             b'AREA',
             b'TIME',
             b'A/L ',
             b'PRES',
         ]),
     )
예제 #4
0
 def test_04(self):
     """TestUnitsBasic.test_04(): 1e5  fixed units converted to and fro untested."""
     myCats = Units.unitCategories()
     cCount = 0
     random.seed()
     tS = time.perf_counter()
     while cCount < 1e1:
         # Choose a category at random
         iC = random.randint(0, len(myCats) - 1)
         myUnits = Units.units(myCats[iC])
         iU_1 = random.randint(0, len(myUnits) - 1)
         iU_2 = random.randint(0, len(myUnits) - 1)
         val = random.random()
         uCount = 0
         while uCount < 1e4:
             newVal = Units.convert(val, myUnits[iU_1], myUnits[iU_2])
             uCount += 1
         cCount += 1
     tE = time.perf_counter() - tS
     sys.stderr.write('Time: %8.3f rate %10.3f k/S ' %
                      (tE, (cCount * uCount) / (1024 * tE)))