Isis 3 Programmer Reference
LongitudeTests.cpp
1 
6 /* SPDX-License-Identifier: CC0-1.0 */
7 #include <gtest/gtest.h>
8 
9 #include "Longitude.h"
10 #include "SpecialPixel.h"
11 
12 using namespace Isis;
13 
14 // ----- Testing Constructors -----
15 // Default constructor
16 TEST(Longitude, DefaultConstructor) {
17  Longitude lon;
18  EXPECT_EQ(Isis::Null, lon.degrees());
19 }
20 
21 // Constructor given a value in degrees
22 TEST(Longitude, DegreesConstructor) {
23  Longitude lon(180.0, Angle::Degrees);
24  EXPECT_EQ(180, lon.degrees());
25 }
26 
27 
28 // Constructor given a positive west value in degrees
29 TEST(Longitude, PositiveWest) {
31  EXPECT_EQ(180, lon.degrees());
32 }
33 
34 // Constructor given a positive west, -90 value in degrees
35 TEST(Longitude, PWNegative90) {
38  EXPECT_EQ(90, lon.degrees());
39 }
40 
41 // Constructor given -90 degrees PW & 360 domain
42 TEST(Longitude, PW360Domain) {
45  EXPECT_EQ(450, lon.degrees());
46 }
47 
48 // Copy constructor
49 TEST(Longitude, CopyConstructor) {
50  Longitude lon(90.0, Angle::Degrees);
51  EXPECT_EQ(lon.degrees(), Longitude(lon).degrees());
52 
53  Longitude lonCopy(lon);
54  lonCopy = lon;
55  EXPECT_EQ(90, lonCopy.degrees());
56 }
57 
58 // ----- Testing Set Methods -----
59 // Set to 90 degrees
60 TEST(Longitude, Set90Degrees) {
61  Longitude lon(270.0, Angle::Degrees);
62  lon.setPositiveEast(90, Angle::Degrees);
63  EXPECT_EQ(90, lon.degrees());
64 }
65 
66 // Set to 90 degrees PW
67 TEST(Longitude, Set90DegreesPW) {
68  Longitude lon(270.0, Angle::Degrees);
69  lon.setPositiveWest(90, Angle::Degrees);
70  EXPECT_EQ(270, lon.degrees());
71 }
72 
73 // ----- Testing Get Methods -----
74 TEST(Longitude, Get90Degrees) {
75  Longitude lon(90.0, Angle::Degrees);
76 
77  // degrees universal
78  EXPECT_EQ(90, lon.degrees());
79 
80  // degrees positive east
81  EXPECT_EQ(90, lon.positiveEast(Angle::Degrees));
82 
83  // radians positive east
84  EXPECT_EQ(0.5, lon.positiveEast(Angle::Radians) / PI);
85 
86  // degrees positive west
87  EXPECT_EQ(270, lon.positiveWest(Angle::Degrees));
88 
89  // radians positive west
90  EXPECT_EQ(1.5, lon.positiveWest(Angle::Radians) / PI);
91 }
92 
93 TEST(Longitude, Get450Degrees) {
94  Longitude lon(450.0, Angle::Degrees);
95 
96  // degrees universal
97  EXPECT_EQ(450, lon.degrees());
98 
99  // degrees positive east
100  EXPECT_EQ(450, lon.positiveEast(Angle::Degrees));
101 
102  // radians positive east
103  EXPECT_EQ(2.5, lon.positiveEast(Angle::Radians) / PI);
104 
105  // degrees positive west
106  EXPECT_EQ(-90, lon.positiveWest(Angle::Degrees));
107 
108  // radians positive west
109  EXPECT_EQ(-0.5, lon.positiveWest(Angle::Radians) / PI);
110 }
111 
112 TEST(Longitude, GetNegative450Degrees) {
113  Longitude lon(-450.0, Angle::Degrees);
114 
115  // degrees universal
116  EXPECT_EQ(-450, lon.degrees());
117 
118  // degrees positive east
119  EXPECT_EQ(-450, lon.positiveEast(Angle::Degrees));
120 
121  // radians positive east
122  EXPECT_EQ(-2.5, lon.positiveEast(Angle::Radians) / PI);
123 
124  // degrees positive west
125  EXPECT_EQ(810, lon.positiveWest(Angle::Degrees));
126 
127  // radians positive west
128  EXPECT_EQ(4.5, lon.positiveWest(Angle::Radians) / PI);
129 }
130 
131 TEST(Longitude, GetNegative450DegreesPW) {
133 
134  // degrees universal
135  EXPECT_EQ(810, lon.degrees());
136 
137  // degrees positive east
138  EXPECT_EQ(810, lon.positiveEast(Angle::Degrees));
139 
140  // radians positive east
141  EXPECT_EQ(4.5, lon.positiveEast(Angle::Radians) / PI);
142 
143  // degrees positive west
144  EXPECT_EQ(-450, lon.positiveWest(Angle::Degrees));
145 
146  // radians positive west
147  EXPECT_EQ(-2.5, lon.positiveWest(Angle::Radians) / PI);
148 }
149 
150 // ----- Testing Domain Methods -----
151 TEST(Longitude, ForceDomain) {
152  Longitude lon(270.0, Angle::Degrees);
153 
154  // Test force180Domain
155  EXPECT_EQ(-90, lon.force180Domain().degrees());
156 
157  // Test force360Domain
158  EXPECT_EQ(270, lon.force360Domain().degrees());
159 
160  // Force 360 to the 360 domain
161  lon.setPositiveEast(360.0, Angle::Degrees);
162  EXPECT_EQ(360, lon.force360Domain().degrees());
163 
164 }
165 
166 // ----- Testing Range Methods -----
167 
168 TEST(Longitude, InRange) {
169 
170  Longitude lon(45.0, Angle::Degrees);
171 
172  EXPECT_TRUE(lon.inRange(Longitude(0, Angle::Degrees), Longitude(360, Angle::Degrees)));
173  EXPECT_FALSE(lon.inRange(Longitude(360, Angle::Degrees), Longitude(0, Angle::Degrees)));
174  EXPECT_FALSE(lon.inRange(Longitude(350, Angle::Degrees), Longitude(355, Angle::Degrees)));
175  EXPECT_TRUE(lon.inRange(Longitude(0, Angle::Degrees), Longitude(160, Angle::Degrees)));
176  EXPECT_FALSE(lon.inRange(Longitude(0, Angle::Degrees), Longitude(44, Angle::Degrees)));
177  EXPECT_FALSE(lon.inRange(Longitude(46, Angle::Degrees), Longitude(90, Angle::Degrees)));
178  EXPECT_TRUE(lon.inRange(Longitude(0, Angle::Degrees), Longitude(45, Angle::Degrees)));
179  EXPECT_TRUE(lon.inRange(Longitude(45, Angle::Degrees), Longitude(90, Angle::Degrees)));
180 }
Isis::Angle::Degrees
@ Degrees
Degrees are generally considered more human readable, 0-360 is one circle, however most math does not...
Definition: Angle.h:56
Isis::PI
const double PI
The mathematical constant PI.
Definition: Constants.h:40
Isis::Longitude::Domain180
@ Domain180
As the longitude increases the actual position is more west.
Definition: Longitude.h:66
Isis::Longitude::Domain360
@ Domain360
As the longitude increases the actual position is more east.
Definition: Longitude.h:64
Isis::Longitude
This class is designed to encapsulate the concept of a Longitude.
Definition: Longitude.h:40
Isis::Null
const double Null
Value for an Isis Null pixel.
Definition: SpecialPixel.h:95
Isis::Angle::degrees
double degrees() const
Get the angle in units of Degrees.
Definition: Angle.h:232
Isis::Longitude::PositiveWest
@ PositiveWest
As the longitude increases the actual position is more west.
Definition: Longitude.h:50
Isis::Angle::Radians
@ Radians
Radians are generally used in mathematical equations, 0-2*PI is one circle, however these are more di...
Definition: Angle.h:63
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16