github.com/la5nta/wl2k-go@v0.11.8/catalog/position_report_test.go (about)

     1  // Copyright 2015 Martin Hebnes Pedersen (LA5NTA). All rights reserved.
     2  // Use of this source code is governed by the MIT-license that can be
     3  // found in the LICENSE file.
     4  
     5  package catalog
     6  
     7  import (
     8  	"os"
     9  	"testing"
    10  	"time"
    11  )
    12  
    13  func TestDecToDM(t *testing.T) {
    14  	latTests := map[float64]string{
    15  		-4.974: "04-58.4400S",
    16  		-0.5:   "00-30.0000S",
    17  		0.0:    "00-00.0000 ",
    18  		0.5:    "00-30.0000N",
    19  		60.132: "60-07.9200N",
    20  	}
    21  	lonTests := map[float64]string{
    22  		-180.0: "180-00.0000W",
    23  		-60.50: "060-30.0000W",
    24  		-0.5:   "000-30.0000W",
    25  		0.0:    "000-00.0000 ",
    26  		0.5:    "000-30.0000E",
    27  		003.50: "003-30.0000E",
    28  		153.50: "153-30.0000E",
    29  		180.0:  "180-00.0000E",
    30  	}
    31  
    32  	for deg, expect := range latTests {
    33  		if got := decToMinDec(deg, true); got != expect {
    34  			t.Errorf("On input %f, expected %s got %s", deg, expect, got)
    35  		}
    36  	}
    37  	for deg, expect := range lonTests {
    38  		if got := decToMinDec(deg, false); got != expect {
    39  			t.Errorf("On input %f, expected %s got %s", deg, expect, got)
    40  		}
    41  	}
    42  }
    43  
    44  func omitErr(v *Course, _ error) *Course { return v }
    45  
    46  func TestCourseStringer2(t *testing.T) {
    47  	// omitErr := func(c *Course, err error) *Course { return c }
    48  	tests := map[string]*Course{
    49  		"123T": omitErr(NewCourse(123, false)),
    50  		"123M": omitErr(NewCourse(123, true)),
    51  	}
    52  	for expect, in := range tests {
    53  		t.Run(expect, func(t *testing.T) {
    54  			if in == nil && expect != "" {
    55  				t.Fatal("got unexpected nil")
    56  			}
    57  			if got := in.String(); got != expect {
    58  				t.Errorf("Got %q, expected %q", got, expect)
    59  			}
    60  		})
    61  	}
    62  }
    63  
    64  func TestCourseStringer(t *testing.T) {
    65  	tests := map[string]Course{
    66  		"123T": {Digits: [3]byte{'1', '2', '3'}, Magnetic: false},
    67  		"123M": {Digits: [3]byte{'1', '2', '3'}, Magnetic: true},
    68  	}
    69  	for expect, in := range tests {
    70  		t.Run(expect, func(t *testing.T) {
    71  			if got := in.String(); got != expect {
    72  				t.Errorf("Got %q, expected %q", got, expect)
    73  			}
    74  		})
    75  	}
    76  }
    77  
    78  func ExamplePosReport_Message() {
    79  	lat := 60.18
    80  	lon := 5.3972
    81  
    82  	posRe := PosReport{
    83  		Date:    time.Now(),
    84  		Lat:     &lat,
    85  		Lon:     &lon,
    86  		Comment: "Hjemme QTH",
    87  	}
    88  	msg := posRe.Message("N0CALL")
    89  	msg.Write(os.Stdout)
    90  }