package tle import ( "encoding/json" "fmt" "os" "reflect" "testing" ) func ExampleNewTLE() { var RawTLE = `ISS (ZARYA) 1 25544U 98067A 19229.39083552 .00000228 00000-0 11917-4 0 9993 2 25544 51.6447 57.6210 0007373 294.0868 138.8050 15.50381554184754` TLE, err := NewTLE(RawTLE) if err != nil { fmt.Println(err) } // convert the TLE to json b, err := json.MarshalIndent(TLE, "", " ") if err != nil { fmt.Println("error: ", err) } _, err = os.Stdout.Write(b) if err != nil { fmt.Println("error: ", err) } // Output: // { // "titleline": { // "satname": "ISS (ZARYA) " // }, // "lineone": { // "linenumber": 1, // "satellitenumber": 25544, // "classification": "U", // "internationaldesignator": { // "launchyear": 98, // "launchnumber": 67, // "launchpiece": "A" // }, // "epoch": { // "year": 19, // "dayfraction": 229.39083552 // }, // "firstderiv": 0.00000228, // "secondderiv": 0, // "BSTAR": 0.000011917, // "numberzero": 0, // "elementesetnumber": 999, // "checksum": 3 // }, // "linetwo": { // "linenumber": 2, // "satellitenumber": 25544, // "inclination": 51.6447, // "rightascensionoftheascendingnode": 57.621, // "eccentricity": 7373, // "argumentofperigee": 294.0868, // "meananomaly": 138.805, // "meanmotion": 15.50381554, // "revolutionnumberatepoch": 18475, // "checksum": 4 // } //} } func TestNewTLE(t *testing.T) { type args struct { RawTLE string } tests := []struct { name string args args want TLE wantErr bool }{ { name: "ISS (ZARYA) ", args: args{ RawTLE: `ISS (ZARYA) 1 25544U 98067A 19229.39083552 .00000228 00000-0 11917-4 0 9993 2 25544 51.6447 57.6210 0007373 294.0868 138.8050 15.50381554184754`, }, want: TLE{ TitleLine: TitleLine{ Satname: "ISS (ZARYA) ", }, LineOne: LineOne{ Linenumber: 1, SatelliteNumber: 25544, Classification: "U", InternationalDesignator: InternationalDesignator{ Launchyear: 98, Launchnumber: 67, Launchpiece: "A", }, Epoch: Epoch{ Year: 19, Dayfraction: 229.39083552, }, Firstderiv: 0.00000228, Secondderiv: 0, BSTAR: 0.000011917, Numberzero: 0, ElementSetNumber: 999, Checksum: 3, }, LineTwo: LineTwo{ Linenumber: 2, SatelliteNumber: 25544, Inclination: 51.6447, RightAscensionOfTheAscendingNode: 57.621, Eccentricity: 7373, ArgumentOfPerigee: 294.0868, MeanAnomaly: 138.805, MeanMotion: 15.50381554, RevolutionNumberAtEpoch: 18475, Checksum: 4, }, }, wantErr: false, }, { name: "ALTAIR PATHFINDER ", args: args{ RawTLE: `ALTAIR PATHFINDER 1 42711U 98067LS 19228.69980992 .00034716 00000-0 14927-3 0 9996 2 42711 51.6342 342.8763 0003425 355.3059 4.7912 15.84686251128432`, }, want: TLE{ TitleLine: TitleLine{ Satname: "ALTAIR PATHFINDER ", }, LineOne: LineOne{ Linenumber: 1, SatelliteNumber: 42711, Classification: "U", InternationalDesignator: InternationalDesignator{ Launchyear: 98, Launchnumber: 67, Launchpiece: "LS", }, Epoch: Epoch{ Year: 19, Dayfraction: 228.69980992, }, Firstderiv: 0.00034716, Secondderiv: 0, BSTAR: 0.00014927, Numberzero: 0, ElementSetNumber: 999, Checksum: 6, }, LineTwo: LineTwo{ Linenumber: 2, SatelliteNumber: 42711, Inclination: 51.6342, RightAscensionOfTheAscendingNode: 342.8763, Eccentricity: 3425, ArgumentOfPerigee: 355.3059, MeanAnomaly: 4.7912, MeanMotion: 15.84686251, RevolutionNumberAtEpoch: 12843, Checksum: 2, }, }, wantErr: false, }, { name: "CALSPHERE 1 ", args: args{ RawTLE: `CALSPHERE 1 1 00900U 64063C 19230.92310804 .00000183 00000-0 18763-3 0 9990 2 00900 90.1493 23.5442 0025413 246.1721 230.7950 13.73262737728795`, }, want: TLE{ TitleLine: TitleLine{ Satname: "CALSPHERE 1 ", }, LineOne: LineOne{ Linenumber: 1, SatelliteNumber: 900, Classification: "U", InternationalDesignator: InternationalDesignator{ Launchyear: 64, Launchnumber: 63, Launchpiece: "C", }, Epoch: Epoch{ Year: 19, Dayfraction: 230.92310804, }, Firstderiv: 0.00000183, Secondderiv: 0, BSTAR: 0.00018763, Numberzero: 0, ElementSetNumber: 999, Checksum: 0, }, LineTwo: LineTwo{ Linenumber: 2, SatelliteNumber: 900, Inclination: 90.1493, RightAscensionOfTheAscendingNode: 23.5442, Eccentricity: 25413, ArgumentOfPerigee: 246.1721, MeanAnomaly: 230.795, MeanMotion: 13.73262737, RevolutionNumberAtEpoch: 72879, Checksum: 5, }, }, wantErr: false, }, { name: "NewTLE parseLineOne err", args: args{ RawTLE: `NOAA 1 [-] a 04793U 70106A 19240.84692470 -.00000044 00000-0 47034-5 0 9995 2 04793 101.6989 308.4654 0032091 148.0366 326.6117 12.53991010229282`, }, want: TLE{}, wantErr: true, }, { name: "NewTLE parseLineOne satellite number error", args: args{ RawTLE: `NOAA 1 [-] 1 0aaa3U 70106A 19240.84692470 -.00000044 00000-0 47034-5 0 9995 a 04793 101.6989 308.4654 0032091 148.0366 326.6117 12.53991010229282`, }, want: TLE{}, wantErr: true, }, { name: "NewTLE parseLineOne LaunchYear", args: args{ RawTLE: `NOAA 1 [-] 1 04793U aa106A 19240.84692470 -.00000044 00000-0 47034-5 0 9995 2 04793 101.6989 308.4654 0032091 148.0366 326.6117 12.53991010229282`, }, want: TLE{}, wantErr: true, }, { name: "NewTLE parseLineOne LaunchNumber", args: args{ RawTLE: `NOAA 1 [-] 1 04793U 70aaaA 19240.84692470 -.00000044 00000-0 47034-5 0 9995 2 04793 101.6989 308.4654 0032091 148.0366 326.6117 12.53991010229282`, }, want: TLE{}, wantErr: true, }, { name: "NewTLE parseLineOne Epoch Year", args: args{ RawTLE: `NOAA 1 [-] 1 04793U 70106A aa240.84692470 -.00000044 00000-0 47034-5 0 9995 2 04793 101.6989 308.4654 0032091 148.0366 326.6117 12.53991010229282`, }, want: TLE{}, wantErr: true, }, { name: "NewTLE parseLineOne Epoch Day Fraction", args: args{ RawTLE: `NOAA 1 [-] 1 04793U 70106A 19aaaaaaaaa470 -.00000044 00000-0 47034-5 0 9995 2 04793 101.6989 308.4654 0032091 148.0366 326.6117 12.53991010229282`, }, want: TLE{}, wantErr: true, }, { name: "NewTLE parseLineOne Raw First Deriv", args: args{ RawTLE: `NOAA 1 [-] 1 04793U 70106A 19240.84692470 -.0aaaa044 00000-0 47034-5 0 9995 2 04793 101.6989 308.4654 0032091 148.0366 326.6117 12.53991010229282`, }, want: TLE{}, wantErr: true, }, { name: "NewTLE parseLineOne Second Deriv Base", args: args{ RawTLE: `NOAA 1 [-] 1 04793U 70106A 19240.84692470 -.00000044 00aaa-0 47034-5 0 9995 2 04793 101.6989 308.4654 0032091 148.0366 326.6117 12.53991010229282`, }, want: TLE{}, wantErr: true, }, { name: "NewTLE parseLineOne Second Deriv Power", args: args{ RawTLE: `NOAA 1 [-] 1 04793U 70106A 19240.84692470 -.00000044 00000-a 47034-5 0 9995 2 04793 101.6989 308.4654 0032091 148.0366 326.6117 12.53991010229282`, }, want: TLE{}, wantErr: true, }, { name: "NewTLE parseLineOne BSTARBase", args: args{ RawTLE: `NOAA 1 [-] 1 04793U 70106A 19240.84692470 -.00000044 00000-0 4aaa4-5 0 9995 2 04793 101.6989 308.4654 0032091 148.0366 326.6117 12.53991010229282`, }, want: TLE{}, wantErr: true, }, { name: "NewTLE parseLineOne BSTARPower", args: args{ RawTLE: `NOAA 1 [-] 1 04793U 70106A 19240.84692470 -.00000044 00000-0 47034-a 0 9995 2 04793 101.6989 308.4654 0032091 148.0366 326.6117 12.53991010229282`, }, want: TLE{}, wantErr: true, }, { name: "NewTLE parseLineOne ElementSetNumber", args: args{ RawTLE: `NOAA 1 [-] 1 04793U 70106A 19240.84692470 -.00000044 00000-0 47034-5 0 aa95 2 04793 101.6989 308.4654 0032091 148.0366 326.6117 12.53991010229282`, }, want: TLE{}, wantErr: true, }, { name: "NewTLE parseLineOne Number Zero", args: args{ RawTLE: `NOAA 1 [-] 1 04793U 70106A 19240.84692470 -.00000044 00000-0 47034-5 a 9995 2 04793 101.6989 308.4654 0032091 148.0366 326.6117 12.53991010229282`, }, want: TLE{}, wantErr: true, }, { name: "NewTLE parseLineOne Checksum", args: args{ RawTLE: `NOAA 1 [-] 1 04793U 70106A 19240.84692470 -.00000044 00000-0 47034-5 0 999a 2 04793 101.6989 308.4654 0032091 148.0366 326.6117 12.53991010229282`, }, want: TLE{}, wantErr: true, }, { name: "NewTLE parseLineTwo LineTwoNumber", args: args{ RawTLE: `NOAA 1 [-] 1 04793U 70106A 19240.84692470 -.00000044 00000-0 47034-5 0 9995 a 04793 101.6989 308.4654 0032091 148.0366 326.6117 12.53991010229282`, }, want: TLE{}, wantErr: true, }, { name: "NewTLE parseLineTwo SatelliteNumer", args: args{ RawTLE: `NOAA 1 [-] 1 04793U 70106A 19240.84692470 -.00000044 00000-0 47034-5 0 9995 2 aaaaa 101.6989 308.4654 0032091 148.0366 326.6117 12.53991010229282`, }, want: TLE{}, wantErr: true, }, { name: "NewTLE parseLineTwo RawInclination", args: args{ RawTLE: `NOAA 1 [-] 1 04793U 70106A 19240.84692470 -.00000044 00000-0 47034-5 0 9995 2 04793 10aaaa89 308.4654 0032091 148.0366 326.6117 12.53991010229282`, }, want: TLE{}, wantErr: true, }, { name: "NewTLE parseLineTwo RightascensionOfTheAscendingNode", args: args{ RawTLE: `NOAA 1 [-] 1 04793U 70106A 19240.84692470 -.00000044 00000-0 47034-5 0 9995 2 04793 101.6989 3aaaa654 0032091 148.0366 326.6117 12.53991010229282`, }, want: TLE{}, wantErr: true, }, { name: "NewTLE parseLineTwo Eccentricity", args: args{ RawTLE: `NOAA 1 [-] 1 04793U 70106A 19240.84692470 -.00000044 00000-0 47034-5 0 9995 2 04793 101.6989 308.4654 00aaaa1 148.0366 326.6117 12.53991010229282`, }, want: TLE{}, wantErr: true, }, { name: "NewTLE parseLineTwo ArgumentOfPerigee", args: args{ RawTLE: `NOAA 1 [-] 1 04793U 70106A 19240.84692470 -.00000044 00000-0 47034-5 0 9995 2 04793 101.6989 308.4654 0032091 14aaaa66 326.6117 12.53991010229282`, }, want: TLE{}, wantErr: true, }, { name: "NewTLE parseLineTwo MeanAnomaly", args: args{ RawTLE: `NOAA 1 [-] 1 04793U 70106A 19240.84692470 -.00000044 00000-0 47034-5 0 9995 2 04793 101.6989 308.4654 0032091 148.0366 32aaaa17 12.53991010229282`, }, want: TLE{}, wantErr: true, }, { name: "NewTLE parseLineTwo MeanMotion", args: args{ RawTLE: `NOAA 1 [-] 1 04793U 70106A 19240.84692470 -.00000044 00000-0 47034-5 0 9995 2 04793 101.6989 308.4654 0032091 148.0366 326.6117 1aaaaaaa010229282`, }, want: TLE{}, wantErr: true, }, { name: "NewTLE parseLineTwo RevolutionNumberAtEpoch", args: args{ RawTLE: `NOAA 1 [-] 1 04793U 70106A 19240.84692470 -.00000044 00000-0 47034-5 0 9995 2 04793 101.6989 308.4654 0032091 148.0366 326.6117 12.539910102aaaa2`, }, want: TLE{}, wantErr: true, }, { name: "NewTLE parseLineTwo ChecksumLineTwo", args: args{ RawTLE: `NOAA 1 [-] 1 04793U 70106A 19240.84692470 -.00000044 00000-0 47034-5 0 9995 2 04793 101.6989 308.4654 0032091 148.0366 326.6117 12.5399101022928a`, }, want: TLE{}, wantErr: true, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { got, err := NewTLE(tt.args.RawTLE) if (err != nil) != tt.wantErr { t.Errorf("NewTLE() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { t.Errorf("NewTLE() got = %v\n,......................... want %v", got, tt.want) } }) } } func BenchmarkNewTLE(b *testing.B) { RawTLE := `CALSPHERE 1 1 00900U 64063C 19230.92310804 .00000183 00000-0 18763-3 0 9990 2 00900 90.1493 23.5442 0025413 246.1721 230.7950 13.73262737728795` for i := 0; i < b.N; i++ { _, _ = NewTLE(RawTLE) } }