Astro-satpass

 view release on metacpan or  search on metacpan

t/basic.t  view on Meta::CPAN


u_cmp_eql( vector_unitize => [ [ 3, 4 ] ], [ 1, .8 ], undef,
    'vector_unitize( [ 3, 4 ] ): Y component' );

u_cmp_eql( vector_dot_product => [ [ 1, 2, 3 ], [ 6, 5, 4 ] ], 28, undef,
    'vector_dot_product( [ 1, 2, 3 ], [ 6, 5, 4 ] )' );

u_cmp_eql( vector_cross_product => [ [ 1, 2, 3 ], [ 6, 5, 4 ] ],
    [ 0, -7 ], undef,
    'vector_cross_product( [ 1, 2, 3 ], [ 6, 5, 4 ] ): X component' );

u_cmp_eql( vector_cross_product => [ [ 1, 2, 3 ], [ 6, 5, 4 ] ],
    [ 1, 14 ], undef,
    'vector_cross_product( [ 1, 2, 3 ], [ 6, 5, 4 ] ): Y component' );

u_cmp_eql( vector_cross_product => [ [ 1, 2, 3 ], [ 6, 5, 4 ] ],
    [ 2, -7 ], undef,
    'vector_cross_product( [ 1, 2, 3 ], [ 6, 5, 4 ] ): Z component' );

u_cmp_eql( find_first_true => [
    0, 1, sub{ sin( $_[0] ) >= sin( .5 ) }, .0001 ], .5, '%.4f',
    'find_first_true looking for sin( $x ) >= sin( .5 )' );

*_pre_strftime = \&Astro::Coord::ECI::Utils::_pre_strftime;

is_deeply [ _pre_strftime( '%F %T', 2.5 ) ], [ '%Y-%m-%d %H:%M:%S', 2 ],
    q('%F %T', 2.5);

is_deeply [ _pre_strftime( '%H:%M:%.2S', 2.5 ) ], [ '%H:%M:%S.50', 2 ],
    q('%H:%M:%.2S', 2.5);

is_deeply [ _pre_strftime( '%H:%M:%S', 2.5, 2 ) ], [ '%H:%M:%S.50', 2 ],
    q('%H:%M:%S', 2.5, 2);

is_deeply [ _pre_strftime( '%F %.2T', 2.5 ) ], [ '%Y-%m-%d %H:%M:%S.50', 2 ],
    q('%F %.2T', 2.5);

*gm_strftime = \&Astro::Coord::ECI::Utils::gm_strftime;

is gm_strftime( '%F %T', timegm( 0, 30, 2, 10, 2, 124 ) ),
    '2024-03-10 02:30:00',
    q('%F %T' in middle of America/New_York time change);

u_cmp_eql( format_space_track_json_time => timegm( 0, 0, 0, 1, 3, 114 ),
    '2014-04-01 00:00:00', '%s', 'Format Space Track JSON time' );

u_cmp_eql( __format_epoch_time_usec => [
	timegm( 5, 4, 3, 1, 3, 114 ) + .25, '%F %T' ],
    '2014-04-01 03:04:05.250000', '%s',
    'Format epoch time with microseconds' );

note <<EOD;
The following test is from the example in the IDL Astronomy User's
Library source for posang().
EOD

TODO: {
#    local $TODO = 'position_angle() is a work-in-progress';

    note <<EOD;
This is one of the few of Meeus' formulae where he does not provide a
worked example. I am unable to duplicate the IDL Astronomy User's
Library posang() sample results, but neither is PyAstronomy's
positionAngle(), which claims to derive from the IDL implementation.
http://www.backyard-astro.com/deepsky/top100/07.html gives the position
angle from Mizar to Alcor as 72 degrees. PyAstronomy calculates 71 and a
bit using their SIMBAD positions as of July 21 2019, so I am testing
against that number.
EOD

    u_cmp_eql( position_angle => [
	deg_to_rad( 200.98141867 ),
	deg_to_rad(  54.92535197 ),
	deg_to_rad( 201.3064076387 ),
	deg_to_rad(  54.9879596614 ),
    ], deg_to_rad( 71.32015 ), '%.6f', 'position angle Alcor wrt Mizar' );
}

done_testing;

{
    my $obj;

    sub instantiate {
	my ( $class ) = @_;
	$obj = eval {
	    $class->new();
	};
	@_ = ( $obj, "Instantiate $class" );
	goto &ok;
    }

    sub get_object {
	return $obj;
    }
}

sub deg_to_rad {
    my ( $deg ) = @_;
    return $deg * PI / 180;
}

sub u_cmp_eql {
    my ( $sub, $arg, $want, $tplt, $title ) = @_;
    my $opt;
    if ( HASH_REF eq ref $tplt ) {
	$opt = { %{ $tplt } };	# Shallow clone
	$tplt = $opt->{template};
    } else {
	$opt = {};
    }
    $opt->{test} ||= ( defined $tplt && '%s' eq $tplt ) ? 'is' : 'numeric';
    ARRAY_REF eq ref $arg
	or $arg = [ $arg ];
    if ( my $code = Astro::Coord::ECI::Utils->can( $sub ) ) {
	my $got;
	if ( ARRAY_REF eq ref $want ) {
	    ( my $inx, $want ) = @{ $want };
	    my @rslt;
	    {
		# The following package() statement seems to be the most



( run in 0.516 second using v1.01-cache-2.11-cpan-fe3c2283af0 )