about summary refs log tree commit diff
path: root/convert_test.go
diff options
context:
space:
mode:
authorEmile <hanemile@protonmail.com>2019-08-30 14:53:06 +0200
committerEmile <hanemile@protonmail.com>2019-08-30 14:53:06 +0200
commit26de707af673c99eafbe00584f1ac5a29757f6d3 (patch)
tree1c0fb78cf32fcfb4e5f6be2c7cbdff9e62c27bdc /convert_test.go
parent1e7b8f716261aee4105edadecc01acdb884c63a3 (diff)
fixed the git errors
Diffstat (limited to 'convert_test.go')
-rw-r--r--convert_test.go242
1 files changed, 242 insertions, 0 deletions
diff --git a/convert_test.go b/convert_test.go
new file mode 100644
index 0000000..96ee3c3
--- /dev/null
+++ b/convert_test.go
@@ -0,0 +1,242 @@
+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,
+		},
+	}
+	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)
+	}
+}