1package main;
2
3use strict;
4use warnings;
5
6use Test::More 0.88;	# Because of done_testing()
7
8use Astro::Coord::ECI::TLE;
9use Astro::Coord::ECI::TLE::Set;
10use Time::Local;
11
12our $SKIP_TEST;
13
14plan( tests => 25 );
15
16my $epoch = timelocal(0, 0, 0, 1, 3, 109);	# April 1 2009;
17my $backdate = Astro::Coord::ECI::TLE->new(
18    id => 11111, epoch => $epoch);
19my $nobackdate = Astro::Coord::ECI::TLE->new(
20    id => 11111, epoch => $epoch, backdate => 0);
21my $asof = $epoch - 86400;
22my $effective = Astro::Coord::ECI::TLE->new(
23    id => 11111, epoch => $epoch, effective => $asof);
24my $past = $asof - 86400;
25
26is($backdate->max_effective_date(), undef,
27    '$backdate->max_effective_date() is undef');
28is($nobackdate->max_effective_date(), $epoch,
29    '$nobackdate->max_effective_date() is $epoch');
30is($effective->max_effective_date(), $asof,
31    '$effective->max_effective_date() is $asof');
32
33is($backdate->max_effective_date($past), $past,
34    '$backdate->max_effective_date($past) is $past');
35is($nobackdate->max_effective_date($past), $epoch,
36    '$nobackdate->max_effective_date($past) is $epoch');
37is($effective->max_effective_date($past), $asof,
38    '$effective->max_effective_date($past) is $asof');
39
40is($backdate->max_effective_date($asof), $asof,
41    '$backdate->max_effective_date($asof) is $asof');
42is($nobackdate->max_effective_date($asof), $epoch,
43    '$nobackdate->max_effective_date($asof) is $epoch');
44is($effective->max_effective_date($asof), $asof,
45    '$effective->max_effective_date($asof) is $asof');
46
47my ($set) = Astro::Coord::ECI::TLE::Set->aggregate($backdate, $effective);
48
49is($set->max_effective_date($past), $asof,
50    '$set->max_effective_date($past) is $asof');
51is($set->select(), $effective,
52    '$set->max_effective_date($past) selects $effective');
53is($set->max_effective_date($asof), $asof,
54    '$set->max_effective_date($asof) is $asof');
55is($set->select(), $effective,
56    '$set->max_effective_date($asof) selects $effective');
57is($set->max_effective_date($epoch), $epoch,
58    '$set->max_effective_date($epoch) is $epoch');
59is($set->select(), $backdate,
60    '$set->max_effective_date($epoch) selects $backdate');
61
62my ( $tle, $err );
63eval {
64    local $SIG{__WARN__} = sub { $err = $_[0] };
65    ( $tle ) = Astro::Coord::ECI::TLE->parse( <<'EOD' );
66Satellite X --effective 1980/275/12:00:00.0 --rcs 25.0
671 88888U          80275.98708465  .00073094  13844-3  66816-4 0    8
682 88888  72.8435 115.9689 0086731  52.6988 110.5714 16.05824518  105
69EOD
70    1;
71} or do {
72    $err = $@;
73};
74
75ok $tle, 'Parse TLE with --effective and --rcs specs'
76    or diag $err;
77
78SKIP: {
79
80    my $tests = 3;
81
82    $tle or skip 'Failed to parse TLE', $tests;
83
84    $SKIP_TEST and skip $SKIP_TEST, $tests;
85
86    ok ! defined $err, 'Got no warnings'
87	or diag "Warning was '$err'";
88
89    cmp_ok( $tle->get( 'effective' ), '==', timegm( 0, 0, 12, 1, 9, 80 ),
90	'Effective date is noon October 1 1980' );
91
92    cmp_ok( $tle->get( 'rcs' ), '==', 25,
93	'Radar cross-section is 25' );
94
95}
96
97( $tle, $err ) = ( undef, undef );
98eval {
99    local $SIG{__WARN__} = sub { $err = $_[0] };
100    ( $tle ) = Astro::Coord::ECI::TLE->parse( <<'EOD' );
101Satellite X --effective 1980/275/12:00:00
1021 88888U          80275.98708465  .00073094  13844-3  66816-4 0    8
1032 88888  72.8435 115.9689 0086731  52.6988 110.5714 16.05824518  105
104EOD
105    1;
106} or do {
107    $err = $@;
108};
109
110ok $tle, 'Parse TLE with --effective date lacking fractional seconds'
111    or diag $err;
112
113SKIP: {
114
115    my $tests = 2;
116
117    $tle or skip 'Failed to parse TLE', $tests;
118
119    $SKIP_TEST and skip $SKIP_TEST, $tests;
120
121    ok ! defined $err, 'Got no warnings'
122	or diag "Warning was '$err'";
123
124    cmp_ok( $tle->get( 'effective' ), '==', timegm( 0, 0, 12, 1, 9, 80 ),
125	'Effective date is noon October 1 1980' );
126
127}
128
129( $tle, $err ) = ( undef, undef );
130eval {
131    local $SIG{__WARN__} = sub { $err = $_[0] };
132    ( $tle ) = Astro::Coord::ECI::TLE->parse( <<'EOD' );
133Satellite X --effective 1980/275/12:00
1341 88888U          80275.98708465  .00073094  13844-3  66816-4 0    8
1352 88888  72.8435 115.9689 0086731  52.6988 110.5714 16.05824518  105
136EOD
137    1;
138} or do {
139    $err = $@;
140};
141
142ok $tle, 'Parse TLE with --effective date lacking seconds'
143    or diag $err;
144
145SKIP: {
146
147    my $tests = 2;
148
149    $tle or skip 'Failed to parse TLE', $tests;
150
151    $SKIP_TEST and skip $SKIP_TEST, $tests;
152
153    ok defined $err, 'Got a warning';
154
155    ok ! defined $tle->get( 'effective' ), 'Effective date is undef';
156
157}
158
1591;
160