@@ -76,8 +76,7 @@ impl From<csv::Error> for EopParserError {
7676
7777#[ derive( Default ) ]
7878pub struct EopParser {
79- iau1980 : Option < PathBuf > ,
80- iau2000 : Option < PathBuf > ,
79+ paths : ( Option < PathBuf > , Option < PathBuf > ) ,
8180 lsp : Option < Box < dyn LeapSecondsProvider > > ,
8281}
8382
@@ -86,28 +85,28 @@ impl EopParser {
8685 Self :: default ( )
8786 }
8887
89- pub fn with_iau1980 ( & mut self , path : impl AsRef < Path > ) -> & mut Self {
90- self . iau1980 = Some ( path. as_ref ( ) . to_owned ( ) ) ;
88+ pub fn from_path ( & mut self , path : impl AsRef < Path > ) -> & mut Self {
89+ self . paths = ( Some ( path. as_ref ( ) . to_owned ( ) ) , None ) ;
9190 self
9291 }
9392
94- pub fn with_iau2000 ( & mut self , path : impl AsRef < Path > ) -> & mut Self {
95- self . iau2000 = Some ( path. as_ref ( ) . to_owned ( ) ) ;
93+ pub fn from_paths ( & mut self , path1 : impl AsRef < Path > , path2 : impl AsRef < Path > ) -> & mut Self {
94+ self . paths = (
95+ Some ( path1. as_ref ( ) . to_owned ( ) ) ,
96+ Some ( path2. as_ref ( ) . to_owned ( ) ) ,
97+ ) ;
9698 self
9799 }
98100
99- pub fn with_leap_seconds_provider ( & mut self , lsp : Box < dyn LeapSecondsProvider > ) -> & mut Self {
101+ pub fn leap_seconds_provider ( & mut self , lsp : Box < dyn LeapSecondsProvider > ) -> & mut Self {
100102 self . lsp = Some ( lsp) ;
101103 self
102104 }
103105
104106 pub fn parse ( & self ) -> Result < EopProvider , EopParserError > {
105- let n = if let Some ( iau1980) = self . iau1980 . as_ref ( ) {
107+ let n = if let Some ( iau1980) = self . paths . 0 . as_ref ( ) {
106108 let mut reader = ReaderBuilder :: new ( ) . delimiter ( b';' ) . from_path ( iau1980) ?;
107109 reader. records ( ) . count ( )
108- } else if let Some ( iau2000) = self . iau2000 . as_ref ( ) {
109- let mut reader = ReaderBuilder :: new ( ) . delimiter ( b';' ) . from_path ( iau2000) ?;
110- reader. records ( ) . count ( )
111110 } else {
112111 return Err ( EopParserError :: NoFiles ) ;
113112 } ;
@@ -123,10 +122,10 @@ impl EopParser {
123122
124123 let mut rdr1 = ReaderBuilder :: new ( )
125124 . delimiter ( b';' )
126- . from_path ( self . iau1980 . as_ref ( ) . or ( self . iau2000 . as_ref ( ) ) . unwrap ( ) ) ?;
125+ . from_path ( self . paths . 0 . as_ref ( ) . unwrap ( ) ) ?;
127126 let mut rdr2 = ReaderBuilder :: new ( )
128127 . delimiter ( b';' )
129- . from_path ( self . iau2000 . as_ref ( ) . or ( self . iau1980 . as_ref ( ) ) . unwrap ( ) ) ?;
128+ . from_path ( self . paths . 1 . as_ref ( ) . or ( self . paths . 0 . as_ref ( ) ) . unwrap ( ) ) ?;
130129 let mut raw1 = ByteRecord :: new ( ) ;
131130 let mut raw2 = ByteRecord :: new ( ) ;
132131 let headers = rdr1. byte_headers ( ) ?. clone ( ) ;
@@ -315,3 +314,39 @@ impl EopProvider {
315314 Ok ( -TimeDelta :: try_from_decimal_seconds ( val) . unwrap ( ) )
316315 }
317316}
317+
318+ #[ cfg( test) ]
319+ mod tests {
320+ use lox_test_utils:: data_dir;
321+ use lox_time:: { Time , time_scales:: Tai } ;
322+
323+ use super :: * ;
324+
325+ #[ test]
326+ #[ should_panic( expected = "NoFiles" ) ]
327+ fn test_eop_parser_no_files ( ) {
328+ EopParser :: new ( ) . parse ( ) . unwrap ( ) ;
329+ }
330+
331+ #[ test]
332+ #[ should_panic( expected = "MissingIau2000" ) ]
333+ fn test_eop_provider_missing_iau2000 ( ) {
334+ let t: Time < Tai > = Time :: default ( ) ;
335+ let eop = EopParser :: new ( )
336+ . from_path ( data_dir ( ) . join ( "finals.all.csv" ) )
337+ . parse ( )
338+ . unwrap ( ) ;
339+ eop. nutation_precession_iau2000 ( t) . unwrap ( ) ;
340+ }
341+
342+ #[ test]
343+ #[ should_panic( expected = "MissingIau1980" ) ]
344+ fn test_eop_provider_missing_iau1980 ( ) {
345+ let t: Time < Tai > = Time :: default ( ) ;
346+ let eop = EopParser :: new ( )
347+ . from_path ( data_dir ( ) . join ( "finals2000A.all.csv" ) )
348+ . parse ( )
349+ . unwrap ( ) ;
350+ eop. nutation_precession_iau1980 ( t) . unwrap ( ) ;
351+ }
352+ }
0 commit comments