...
1 package exif
2
3 import (
4 "math"
5 "reflect"
6 "testing"
7
8 "github.com/dsoprea/go-logging"
9
10 "github.com/dsoprea/go-exif/v3/common"
11 )
12
13 func TestNewGpsDegreesFromRationals(t *testing.T) {
14 latitudeRaw := []exifcommon.Rational{
15 {Numerator: 22, Denominator: 2},
16 {Numerator: 66, Denominator: 3},
17 {Numerator: 132, Denominator: 4},
18 }
19
20 gd, err := NewGpsDegreesFromRationals("W", latitudeRaw)
21 log.PanicIf(err)
22
23 if gd.Orientation != 'W' {
24 t.Fatalf("Orientation was not set correctly: [%s]", string([]byte{gd.Orientation}))
25 }
26
27 degreesRightBound := math.Nextafter(11.0, 12.0)
28 minutesRightBound := math.Nextafter(22.0, 23.0)
29 secondsRightBound := math.Nextafter(33.0, 34.0)
30
31 if gd.Degrees < 11.0 || gd.Degrees >= degreesRightBound {
32 t.Fatalf("Degrees is not correct: (%.2f)", gd.Degrees)
33 } else if gd.Minutes < 22.0 || gd.Minutes >= minutesRightBound {
34 t.Fatalf("Minutes is not correct: (%.2f)", gd.Minutes)
35 } else if gd.Seconds < 33.0 || gd.Seconds >= secondsRightBound {
36 t.Fatalf("Seconds is not correct: (%.2f)", gd.Seconds)
37 }
38 }
39
40 func TestGpsDegrees_Raw(t *testing.T) {
41 latitudeRaw := []exifcommon.Rational{
42 {Numerator: 22, Denominator: 2},
43 {Numerator: 66, Denominator: 3},
44 {Numerator: 132, Denominator: 4},
45 }
46
47 gd, err := NewGpsDegreesFromRationals("W", latitudeRaw)
48 log.PanicIf(err)
49
50 actual := gd.Raw()
51
52 expected := []exifcommon.Rational{
53 {Numerator: 11, Denominator: 1},
54 {Numerator: 22, Denominator: 1},
55 {Numerator: 33, Denominator: 1},
56 }
57
58 if reflect.DeepEqual(actual, expected) != true {
59 t.Fatalf("GpsInfo not correctly encoded down to raw: %v\n", actual)
60 }
61 }
62
View as plain text