This section contains a number of small scripts that exercise
the sidereal.py module. Their names are keyed to the section numbers
in Duffett-Smith, except
for tests of modules that are not from the book.
This script exercises the MixedUnits class by
using it to convert various mixed values in the
days-hours-minutes-seconds system, convert them back, and
format them with and without left zero fill.
#!/usr/bin/env python
#================================================================
# testmix: Exercise the MixedUnits class.
# For documentation, see:
# http://www.nmt.edu/tcc/help/lang/python/examples/sidereal/ims/
#----------------------------------------------------------------
from sidereal import *
dhmsSystem = MixedUnits ( (24, 60, 60) )
testValues = [
(),
(3.9,),
(2,12),
(1,4,10),
(0,1,30,15),
(1, 2, 3, 4, 5), # Not valid
(1, 0, 0, 59.999999),
(1, 0, 0, 59.9),
(1, 2, 3, 59.5),
(1, 0, 0, 59.499999) ]
def test(seq):
"""Test one tuple.
"""
#--
# Convert the sequence to a single value. This can fail
# if the sequence is too long.
#--
try:
single = dhmsSystem.mixToSingle(seq)
except ValueError, detail:
print "Bad value:", detail
return
#--
# Convert it back to a sequence, and show all three values.
# Then format it in a range of precisions, with/without zeroes.
#--
check = dhmsSystem.singleToMix(single)
print "%s -> %s -> %s" % (seq, single, check)
for digits in range(4):
noZeroes = dhmsSystem.format ( check, digits )
withZeroes = dhmsSystem.format ( check, digits, lz=True )
print " %d %s %s" % (digits, noZeroes, withZeroes)
#================================================================
# Main
#----------------------------------------------------------------
for valueList in testValues:
test(valueList)