tstUtil.cc 18.6 KB
Newer Older
1
2
3
4
5
6
#include <iostream>

#include "gtest/gtest.h"
#include "radixmath/util.hh"

using namespace radix;
7

8
9
TEST(radix, hpaToAltitude)
{
10
  Real altitude = hpaToAltitude(835);
LEFEBVREJP email's avatar
LEFEBVREJP email committed
11
  EXPECT_NEAR(1601.9551358843219, altitude, 1e-1);
12
  altitude = hpaToAltitude(67.7);
LEFEBVREJP email's avatar
LEFEBVREJP email committed
13
  EXPECT_NEAR(17835.433862090933, altitude, 1e-1);
14
15
}

16
17
TEST(radix, cspanf)
{
18
19
  Real lon = -190;
  Real v   = cspanf(lon, -180, 180);
Jordan P. Lefebvre's avatar
Jordan P. Lefebvre committed
20
  EXPECT_NEAR(170, v, 1e-1);
21
22
  lon = 190;
  v   = cspanf(lon, -180, 180);
Jordan P. Lefebvre's avatar
Jordan P. Lefebvre committed
23
  EXPECT_NEAR(v, -170, 1e-1);
24
25
  lon = 360;
  v   = cspanf(lon, -180, 180);
Jordan P. Lefebvre's avatar
Jordan P. Lefebvre committed
26
  EXPECT_NEAR(v, 0, 1e-1);
27
28
  lon = -360;
  v   = cspanf(lon, -180, 180);
Jordan P. Lefebvre's avatar
Jordan P. Lefebvre committed
29
  EXPECT_NEAR(v, 0, 1e-1);
30
31
  Real lat = -100;
  v        = cspanf(lat, -90, 90);
Jordan P. Lefebvre's avatar
Jordan P. Lefebvre committed
32
  EXPECT_NEAR(80, v, 1e-1);
33
34
  lat = 100;
  v   = cspanf(lat, -90, 90);
Jordan P. Lefebvre's avatar
Jordan P. Lefebvre committed
35
  EXPECT_NEAR(-80, v, 1e-1);
36
37
  lat = 180;
  v   = cspanf(lat, -90, 90);
Jordan P. Lefebvre's avatar
Jordan P. Lefebvre committed
38
  EXPECT_NEAR(v, 0, 1e-1);
39
40
  lat = -180;
  v   = cspanf(lat, -90, 90);
Jordan P. Lefebvre's avatar
Jordan P. Lefebvre committed
41
  EXPECT_NEAR(v, 0, 1e-1);
42
43
  lat = -180.5;
  v   = cspanf(lat, -90, 90);
Jordan P. Lefebvre's avatar
Jordan P. Lefebvre committed
44
  EXPECT_NEAR(v, -0.5, 1e-1);
45
46
  lat = 5.5;
  v   = cspanf(lat, -90, 90);
Jordan P. Lefebvre's avatar
Jordan P. Lefebvre committed
47
  EXPECT_NEAR(v, 5.5, 1e-1);
48
49
  lat = -5.5;
  v   = cspanf(lat, -90, 90);
Jordan P. Lefebvre's avatar
Jordan P. Lefebvre committed
50
  EXPECT_NEAR(v, -5.5, 1e-1);
51
52
  lat = -90;
  v   = cspanf(lat, -90, 90);
Jordan P. Lefebvre's avatar
Jordan P. Lefebvre committed
53
  EXPECT_NEAR(v, 90, 1e-1);
54
55
  lat = 90;
  v   = cspanf(lat, -90, 90);
Jordan P. Lefebvre's avatar
Jordan P. Lefebvre committed
56
  EXPECT_NEAR(v, 90, 1e-1);
57
58
}

59
60
TEST(radix, greatCircleDistance)
{
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
  {
    // check distances
    double delta = .01;
    double lat1  = 38.1;
    double lon1  = -115.2;
    double lat2  = lat1 + delta;
    double lon2  = lon1 + delta;

    // east (should equal west)
    double distance =
        greatCircleDistance(lat1, lon1, lat1, lon2, EARTH_RADIUS_MEAN);
    std::cout << "Horizontal Distance: " << distance << std::endl;
    //        EXPECT_TRUE(10. > distance);
    // north
    distance = greatCircleDistance(lat1, lon1, lat2, lon1, EARTH_RADIUS_MEAN);
    std::cout << "Vertical Distance: " << distance << std::endl;
    //        EXPECT_TRUE(13. > distance);
  }
  {
    // Quadrant 2 north west hemisphere
    double delta = 0.05;
    double lat1  = 37.1665;
    double lon1  = -116.15;
    double lat2  = lat1 + delta;
    double lon2  = lon1 + delta;

    //
    // south
    double distance =
        greatCircleDistance(lat1, lon1, lat1, lon2, EARTH_RADIUS_MEAN);
Jordan P. Lefebvre's avatar
Jordan P. Lefebvre committed
91
    EXPECT_NEAR(4430.6079, distance, 1e-1);
92
93
94

    // north
    distance = greatCircleDistance(lat2, lon1, lat2, lon2, EARTH_RADIUS_MEAN);
Jordan P. Lefebvre's avatar
Jordan P. Lefebvre committed
95
    EXPECT_NEAR(4427.6748, distance, 1e-1);
96
97
98
99

    // west
    double west =
        greatCircleDistance(lat1, lon1, lat2, lon1, EARTH_RADIUS_MEAN);
Jordan P. Lefebvre's avatar
Jordan P. Lefebvre committed
100
    EXPECT_NEAR(5559.9209, west, 1e-1);
101
102
103

    // east (should equal west)
    distance = greatCircleDistance(lat1, lon2, lat2, lon2, EARTH_RADIUS_MEAN);
Jordan P. Lefebvre's avatar
Jordan P. Lefebvre committed
104
    EXPECT_NEAR(west, distance, 1e-1);
105
106
107
108
109
110
111
112
113
114
115
116
117
  }
  {
    // Quadrant 3 south west hemisphere
    double delta = -0.05;
    double lat1  = -37.1665;
    double lon1  = -116.15;
    double lat2  = lat1 + delta;
    double lon2  = lon1 + delta;

    //
    // south
    double distance =
        greatCircleDistance(lat1, lon1, lat1, lon2, EARTH_RADIUS_MEAN);
Jordan P. Lefebvre's avatar
Jordan P. Lefebvre committed
118
    EXPECT_NEAR(4430.6079, distance, 1e-1);
119
120
121

    // north
    distance = greatCircleDistance(lat2, lon1, lat2, lon2, EARTH_RADIUS_MEAN);
Jordan P. Lefebvre's avatar
Jordan P. Lefebvre committed
122
    EXPECT_NEAR(4427.6748, distance, 1e-1);
123
124
125
126

    // west
    double west =
        greatCircleDistance(lat1, lon1, lat2, lon1, EARTH_RADIUS_MEAN);
Jordan P. Lefebvre's avatar
Jordan P. Lefebvre committed
127
    EXPECT_NEAR(5559.9209, west, 1e-1);
128
129
130

    // east (should equal west)
    distance = greatCircleDistance(lat1, lon2, lat2, lon2, EARTH_RADIUS_MEAN);
Jordan P. Lefebvre's avatar
Jordan P. Lefebvre committed
131
    EXPECT_NEAR(west, distance, 1e-1);
132
133
134
135
136
137
138
139
140
141
142
143
144
  }
  {
    // Quadrant 1 north east hemisphere
    double delta = 0.05;
    double lat1  = 37.1665;
    double lon1  = 116.15;
    double lat2  = lat1 + delta;
    double lon2  = lon1 + delta;

    //
    // south
    double distance =
        greatCircleDistance(lat1, lon1, lat1, lon2, EARTH_RADIUS_MEAN);
Jordan P. Lefebvre's avatar
Jordan P. Lefebvre committed
145
    EXPECT_NEAR(4430.6079, distance, 1e-1);
146
147
148

    // north
    distance = greatCircleDistance(lat2, lon1, lat2, lon2, EARTH_RADIUS_MEAN);
Jordan P. Lefebvre's avatar
Jordan P. Lefebvre committed
149
    EXPECT_NEAR(4427.6748, distance, 1e-1);
150
151
152
153

    // west
    double west =
        greatCircleDistance(lat1, lon1, lat2, lon1, EARTH_RADIUS_MEAN);
Jordan P. Lefebvre's avatar
Jordan P. Lefebvre committed
154
    EXPECT_NEAR(5559.9209, west, 1e-1);
155
156
157

    // east (should equal west)
    distance = greatCircleDistance(lat1, lon2, lat2, lon2, EARTH_RADIUS_MEAN);
Jordan P. Lefebvre's avatar
Jordan P. Lefebvre committed
158
    EXPECT_NEAR(west, distance, 1e-1);
159
160
161
162
163
164
165
166
167
168
169
170
171
  }
  {
    // Quadrant 4 south east hemisphere
    double delta = -0.05;
    double lat1  = -37.1665;
    double lon1  = 116.15;
    double lat2  = lat1 + delta;
    double lon2  = lon1 + delta;

    //
    // south
    double distance =
        greatCircleDistance(lat1, lon1, lat1, lon2, EARTH_RADIUS_MEAN);
Jordan P. Lefebvre's avatar
Jordan P. Lefebvre committed
172
    EXPECT_NEAR(4430.6079, distance, 1e-1);
173
174
175

    // north
    distance = greatCircleDistance(lat2, lon1, lat2, lon2, EARTH_RADIUS_MEAN);
Jordan P. Lefebvre's avatar
Jordan P. Lefebvre committed
176
    EXPECT_NEAR(4427.6748, distance, 1e-1);
177
178
179
180

    // west
    double west =
        greatCircleDistance(lat1, lon1, lat2, lon1, EARTH_RADIUS_MEAN);
Jordan P. Lefebvre's avatar
Jordan P. Lefebvre committed
181
    EXPECT_NEAR(5559.9209, west, 1e-1);
182
183
184

    // east (should equal west)
    distance = greatCircleDistance(lat1, lon2, lat2, lon2, EARTH_RADIUS_MEAN);
Jordan P. Lefebvre's avatar
Jordan P. Lefebvre committed
185
    EXPECT_NEAR(west, distance, 1e-1);
186
  }
187
188
}

189
190
TEST(radix, greatCircleVolume)
{
191
192
193
194
195
  double delta = 0.05;
  double lat1  = 37.1665;
  double lon1  = -116.15;
  double lat2  = lat1 + delta;
  double lon2  = lon1 + delta;
196

197
198
  double volume = greatCircleVolume(lat1, lon1, lat2, lon2, EARTH_RADIUS_MEAN,
                                    EARTH_RADIUS_MEAN + 1);
Jordan P. Lefebvre's avatar
Jordan P. Lefebvre committed
199
  EXPECT_NEAR(24625680, volume, 1e-1);
200
}
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601

TEST(radix, Pressure1000)
{
  double tolerance = 0.001;

  double potentialTemp1 = 273.15, potentialTemp2 = 293.0,
         potentialTemp3 = 240.654, pressure = 1000;

  double temp = absoluteTemperature(potentialTemp1, pressure);
  ASSERT_NEAR(potentialTemp1, temp, potentialTemp1 * tolerance);

  temp = absoluteTemperature(potentialTemp2, pressure);
  ASSERT_NEAR(potentialTemp2, temp, potentialTemp2 * tolerance);

  temp = absoluteTemperature(potentialTemp3, pressure);
  ASSERT_NEAR(potentialTemp3, temp, potentialTemp3 * tolerance);
}

TEST(radix, Pressure900)
{
  double tolerance = 0.001;

  double potentialTemp1 = 273.15, potentialTemp2 = 293.0,
         potentialTemp3 = 240.654, pressure = 900;

  double expectTemp1 = 265.042, expectTemp2 = 284.303, expectTemp3 = 233.511;

  double temp = absoluteTemperature(potentialTemp1, pressure);
  ASSERT_NEAR(expectTemp1, temp, expectTemp1 * tolerance);

  temp = absoluteTemperature(potentialTemp2, pressure);
  ASSERT_NEAR(expectTemp2, temp, expectTemp2 * tolerance);

  temp = absoluteTemperature(potentialTemp3, pressure);
  ASSERT_NEAR(expectTemp3, temp, expectTemp3 * tolerance);
}

TEST(radix, Pressure800)
{
  double tolerance = 0.001;

  double potentialTemp1 = 273.15, potentialTemp2 = 293.0,
         potentialTemp3 = 240.654, pressure = 800;

  double expectTemp1 = 256.2624306593, expectTemp2 = 274.8851992794,
         expectTemp3 = 225.7755042573;

  double temp = absoluteTemperature(potentialTemp1, pressure);
  ASSERT_NEAR(expectTemp1, temp, expectTemp1 * tolerance);

  temp = absoluteTemperature(potentialTemp2, pressure);
  ASSERT_NEAR(expectTemp2, temp, expectTemp2 * tolerance);

  temp = absoluteTemperature(potentialTemp3, pressure);
  ASSERT_NEAR(expectTemp3, temp, expectTemp3 * tolerance);
}

TEST(radix, Pressure700)
{
  double tolerance = 0.001;

  double potentialTemp1 = 273.15, potentialTemp2 = 293.0,
         potentialTemp3 = 240.654, pressure = 700;

  double expectTemp1 = 246.6602937075, expectTemp2 = 264.5852683737,
         expectTemp3 = 217.3157104956;

  double temp = absoluteTemperature(potentialTemp1, pressure);
  ASSERT_NEAR(expectTemp1, temp, expectTemp1 * tolerance);

  temp = absoluteTemperature(potentialTemp2, pressure);
  ASSERT_NEAR(expectTemp2, temp, expectTemp2 * tolerance);

  temp = absoluteTemperature(potentialTemp3, pressure);
  ASSERT_NEAR(expectTemp3, temp, expectTemp3 * tolerance);
}

TEST(radix, Pressure600)
{
  double tolerance = 0.001;

  double potentialTemp1 = 273.15, potentialTemp2 = 293.0,
         potentialTemp3 = 240.654, pressure = 600;

  double expectTemp1 = 236.0219871191, expectTemp2 = 253.1738686651,
         expectTemp3 = 207.9430177124;

  double temp = absoluteTemperature(potentialTemp1, pressure);
  ASSERT_NEAR(expectTemp1, temp, expectTemp1 * tolerance);

  temp = absoluteTemperature(potentialTemp2, pressure);
  ASSERT_NEAR(expectTemp2, temp, expectTemp2 * tolerance);

  temp = absoluteTemperature(potentialTemp3, pressure);
  ASSERT_NEAR(expectTemp3, temp, expectTemp3 * tolerance);
}

TEST(radix, Pressure500)
{
  double tolerance = 0.001;

  double potentialTemp1 = 273.15, potentialTemp2 = 293.0,
         potentialTemp3 = 240.654, pressure = 500;

  double expectTemp1 = 224.0302306934, expectTemp2 = 240.3106629806,
         expectTemp3 = 197.3778917711;

  double temp = absoluteTemperature(potentialTemp1, pressure);
  ASSERT_NEAR(expectTemp1, temp, expectTemp1 * tolerance);

  temp = absoluteTemperature(potentialTemp2, pressure);
  ASSERT_NEAR(expectTemp2, temp, expectTemp2 * tolerance);

  temp = absoluteTemperature(potentialTemp3, pressure);
  ASSERT_NEAR(expectTemp3, temp, expectTemp3 * tolerance);
}

TEST(radix, Pressure400)
{
  double tolerance = 0.001;

  double potentialTemp1 = 273.15, potentialTemp2 = 293.0,
         potentialTemp3 = 240.654, pressure = 400;

  double expectTemp1 = 210.1795037842, expectTemp2 = 225.4533941379,
         expectTemp3 = 185.1749526036;

  double temp = absoluteTemperature(potentialTemp1, pressure);
  ASSERT_NEAR(expectTemp1, temp, expectTemp1 * tolerance);

  temp = absoluteTemperature(potentialTemp2, pressure);
  ASSERT_NEAR(expectTemp2, temp, expectTemp2 * tolerance);

  temp = absoluteTemperature(potentialTemp3, pressure);
  ASSERT_NEAR(expectTemp3, temp, expectTemp3 * tolerance);
}

TEST(radix, Pressure300)
{
  double tolerance = 0.001;

  double potentialTemp1 = 273.15, potentialTemp2 = 293.0,
         potentialTemp3 = 240.654, pressure = 300;

  double expectTemp1 = 193.5788402819, expectTemp2 = 207.646348902,
         expectTemp3 = 170.5492302002;

  double temp = absoluteTemperature(potentialTemp1, pressure);
  ASSERT_NEAR(expectTemp1, temp, expectTemp1 * tolerance);

  temp = absoluteTemperature(potentialTemp2, pressure);
  ASSERT_NEAR(expectTemp2, temp, expectTemp2 * tolerance);

  temp = absoluteTemperature(potentialTemp3, pressure);
  ASSERT_NEAR(expectTemp3, temp, expectTemp3 * tolerance);
}

TEST(radix, Pressure200)
{
  double tolerance = 0.001;

  double potentialTemp1 = 273.15, potentialTemp2 = 293.0,
         potentialTemp3 = 240.654, pressure = 200;

  double expectTemp1 = 172.3835354925, expectTemp2 = 184.9107666092,
         expectTemp3 = 151.8754799576;

  double temp = absoluteTemperature(potentialTemp1, pressure);
  ASSERT_NEAR(expectTemp1, temp, expectTemp1 * tolerance);

  temp = absoluteTemperature(potentialTemp2, pressure);
  ASSERT_NEAR(expectTemp2, temp, expectTemp2 * tolerance);

  temp = absoluteTemperature(potentialTemp3, pressure);
  ASSERT_NEAR(expectTemp3, temp, expectTemp3 * tolerance);
}

TEST(radix, MixingRatio10)
{
  double tolerance = 0.01;

  double temp1 = 25 - ABS_ZERO_CELSIUS, pressure1 = 900.0,
         temp2 = 10 - ABS_ZERO_CELSIUS, pressure2 = 650.0,
         temp3 = 40 - ABS_ZERO_CELSIUS, pressure3 = 800.0,
         mixingRatio = 10.0 * 1.0E-3;

  double expectRelHum1 = 44.967, expectRelHum2 = 83.818, expectRelHum3 = 17.158;

  double relHum = mixingRatioToRelativeHumidity(mixingRatio, temp1, pressure1);
  ASSERT_NEAR(expectRelHum1, relHum, expectRelHum1 * tolerance);

  relHum = mixingRatioToRelativeHumidity(mixingRatio, temp2, pressure2);
  ASSERT_NEAR(expectRelHum2, relHum, expectRelHum2 * tolerance);

  relHum = mixingRatioToRelativeHumidity(mixingRatio, temp3, pressure3);
  ASSERT_NEAR(expectRelHum3, relHum, expectRelHum3 * tolerance);
}

TEST(radix, MixingRatio5)
{
  double tolerance = 0.01;

  double temp1 = 5.3 - ABS_ZERO_CELSIUS, pressure1 = 1010.0,
         temp2 = -3.2 - ABS_ZERO_CELSIUS, pressure2 = 740.0,
         temp3 = 0.0 - ABS_ZERO_CELSIUS, pressure3 = 300.0,
         mixingRatio = 5.0 * 1.0E-3;

  double expectRelHum1 = 90.474, expectRelHum2 = 100.0, expectRelHum3 = 39.17;

  double relHum = mixingRatioToRelativeHumidity(mixingRatio, temp1, pressure1);
  ASSERT_NEAR(expectRelHum1, relHum, expectRelHum1 * tolerance);

  relHum = mixingRatioToRelativeHumidity(mixingRatio, temp2, pressure2);
  ASSERT_NEAR(expectRelHum2, relHum, expectRelHum2 * tolerance);

  relHum = mixingRatioToRelativeHumidity(mixingRatio, temp3, pressure3);
  ASSERT_NEAR(expectRelHum3, relHum, expectRelHum3 * tolerance);
}

TEST(radix, MixingRatio3)
{
  double tolerance = 0.01;

  double temp1 = -2.0 - ABS_ZERO_CELSIUS, pressure1 = 890.0,
         temp2 = -3.2 - ABS_ZERO_CELSIUS, pressure2 = 550.0,
         temp3 = -15.0 - ABS_ZERO_CELSIUS, pressure3 = 300.0,
         mixingRatio = 3.0 * 1.0E-3;

  double expectRelHum1 = 81.01, expectRelHum2 = 54.73, expectRelHum3 = 75.34;

  double relHum = mixingRatioToRelativeHumidity(mixingRatio, temp1, pressure1);
  ASSERT_NEAR(expectRelHum1, relHum, expectRelHum1 * tolerance);

  relHum = mixingRatioToRelativeHumidity(mixingRatio, temp2, pressure2);
  ASSERT_NEAR(expectRelHum2, relHum, expectRelHum2 * tolerance);

  relHum = mixingRatioToRelativeHumidity(mixingRatio, temp3, pressure3);
  ASSERT_NEAR(expectRelHum3, relHum, expectRelHum3 * tolerance);
}

TEST(radix, MixingRatio1)
{
  double tolerance = 0.01;

  double temp1 = 6.0 - ABS_ZERO_CELSIUS, pressure1 = 890.0,
         temp2 = 1.5 - ABS_ZERO_CELSIUS, pressure2 = 550.0,
         temp3 = -25.0 - ABS_ZERO_CELSIUS, pressure3 = 300.0,
         mixingRatio = 1.0 * 1.0E-3;

  double expectRelHum1 = 15.29, expectRelHum2 = 12.971, expectRelHum3 = 59.66;

  double relHum = mixingRatioToRelativeHumidity(mixingRatio, temp1, pressure1);
  ASSERT_NEAR(expectRelHum1, relHum, expectRelHum1 * tolerance);

  relHum = mixingRatioToRelativeHumidity(mixingRatio, temp2, pressure2);
  ASSERT_NEAR(expectRelHum2, relHum, expectRelHum2 * tolerance);

  relHum = mixingRatioToRelativeHumidity(mixingRatio, temp3, pressure3);
  ASSERT_NEAR(expectRelHum3, relHum, expectRelHum3 * tolerance);
}

TEST(radix, MixingRatioPoint25)
{
  double tolerance = 0.01;

  double temp1 = 32.0 - ABS_ZERO_CELSIUS, pressure1 = 1050.0,
         temp2 = 6.5 - ABS_ZERO_CELSIUS, pressure2 = 650.0,
         temp3 = -25.0 - ABS_ZERO_CELSIUS, pressure3 = 250.0,
         mixingRatio = 0.25 * 1.0E-3;

  double expectRelHum1 = 0.88722, expectRelHum2 = 2.6997, expectRelHum3 = 12.44;

  double relHum = mixingRatioToRelativeHumidity(mixingRatio, temp1, pressure1);
  ASSERT_NEAR(expectRelHum1, relHum, expectRelHum1 * tolerance);

  relHum = mixingRatioToRelativeHumidity(mixingRatio, temp2, pressure2);
  ASSERT_NEAR(expectRelHum2, relHum, expectRelHum2 * tolerance);

  relHum = mixingRatioToRelativeHumidity(mixingRatio, temp3, pressure3);
  ASSERT_NEAR(expectRelHum3, relHum, expectRelHum3 * tolerance);
}

TEST(radix, SpecificHumidity10)
{
  double tolerance = 0.01;

  double temp1 = 25 - ABS_ZERO_CELSIUS, pressure1 = 900.0,
         temp2 = 10 - ABS_ZERO_CELSIUS, pressure2 = 650.0,
         temp3 = 40 - ABS_ZERO_CELSIUS, pressure3 = 800.0,
         specificHumidity = 10.0;

  double expectRelHum1 = 44.967, expectRelHum2 = 83.818, expectRelHum3 = 17.158;

  double relHum =
      specificHumidityToRelativeHumidity(specificHumidity, temp1, pressure1);
  ASSERT_NEAR(expectRelHum1, relHum, expectRelHum1 * tolerance);

  relHum =
      specificHumidityToRelativeHumidity(specificHumidity, temp2, pressure2);
  ASSERT_NEAR(expectRelHum2, relHum, expectRelHum2 * tolerance);

  relHum =
      specificHumidityToRelativeHumidity(specificHumidity, temp3, pressure3);
  ASSERT_NEAR(expectRelHum3, relHum, expectRelHum3 * tolerance);
}

TEST(radix, SpecificHumidity5)
{
  double tolerance = 0.01;

  double temp1 = 5.3 - ABS_ZERO_CELSIUS, pressure1 = 1010.0,
         temp2 = -3.2 - ABS_ZERO_CELSIUS, pressure2 = 740.0,
         temp3 = 0.0 - ABS_ZERO_CELSIUS, pressure3 = 300.0,
         specificHumidity = 5.0;

  double expectRelHum1 = 90.474, expectRelHum2 = 100.0, expectRelHum3 = 39.17;

  double relHum =
      specificHumidityToRelativeHumidity(specificHumidity, temp1, pressure1);
  ASSERT_NEAR(expectRelHum1, relHum, expectRelHum1 * tolerance);

  relHum =
      specificHumidityToRelativeHumidity(specificHumidity, temp2, pressure2);
  ASSERT_NEAR(expectRelHum2, relHum, expectRelHum2 * tolerance);

  relHum =
      specificHumidityToRelativeHumidity(specificHumidity, temp3, pressure3);
  ASSERT_NEAR(expectRelHum3, relHum, expectRelHum3 * tolerance);
}

TEST(radix, SpecificHumidity3)
{
  double tolerance = 0.01;

  double temp1 = -2.0 - ABS_ZERO_CELSIUS, pressure1 = 890.0,
         temp2 = -3.2 - ABS_ZERO_CELSIUS, pressure2 = 550.0,
         temp3 = -15.0 - ABS_ZERO_CELSIUS, pressure3 = 300.0,
         specificHumidity = 3.0;

  double expectRelHum1 = 81.01, expectRelHum2 = 54.73, expectRelHum3 = 75.34;

  double relHum =
      specificHumidityToRelativeHumidity(specificHumidity, temp1, pressure1);
  ASSERT_NEAR(expectRelHum1, relHum, expectRelHum1 * tolerance);

  relHum =
      specificHumidityToRelativeHumidity(specificHumidity, temp2, pressure2);
  ASSERT_NEAR(expectRelHum2, relHum, expectRelHum2 * tolerance);

  relHum =
      specificHumidityToRelativeHumidity(specificHumidity, temp3, pressure3);
  ASSERT_NEAR(expectRelHum3, relHum, expectRelHum3 * tolerance);
}

TEST(radix, SpecificHumidity1)
{
  double tolerance = 0.01;

  double temp1 = 6.0 - ABS_ZERO_CELSIUS, pressure1 = 890.0,
         temp2 = 1.5 - ABS_ZERO_CELSIUS, pressure2 = 550.0,
         temp3 = -25.0 - ABS_ZERO_CELSIUS, pressure3 = 300.0,
         specificHumidity = 1.0;

  double expectRelHum1 = 15.29, expectRelHum2 = 12.971, expectRelHum3 = 59.66;

  double relHum =
      specificHumidityToRelativeHumidity(specificHumidity, temp1, pressure1);
  ASSERT_NEAR(expectRelHum1, relHum, expectRelHum1 * tolerance);

  relHum =
      specificHumidityToRelativeHumidity(specificHumidity, temp2, pressure2);
  ASSERT_NEAR(expectRelHum2, relHum, expectRelHum2 * tolerance);

  relHum =
      specificHumidityToRelativeHumidity(specificHumidity, temp3, pressure3);
  ASSERT_NEAR(expectRelHum3, relHum, expectRelHum3 * tolerance);
}

TEST(radix, SpecificHumidityPoint25)
{
  double tolerance = 0.01;

  double temp1 = 32.0 - ABS_ZERO_CELSIUS, pressure1 = 1050.0,
         temp2 = 6.5 - ABS_ZERO_CELSIUS, pressure2 = 650.0,
         temp3 = -25.0 - ABS_ZERO_CELSIUS, pressure3 = 250.0,
         specificHumidity = 0.25;

  double expectRelHum1 = 0.88722, expectRelHum2 = 2.6997, expectRelHum3 = 12.44;

  double relHum =
      specificHumidityToRelativeHumidity(specificHumidity, temp1, pressure1);
  ASSERT_NEAR(expectRelHum1, relHum, expectRelHum1 * tolerance);

  relHum =
      specificHumidityToRelativeHumidity(specificHumidity, temp2, pressure2);
  ASSERT_NEAR(expectRelHum2, relHum, expectRelHum2 * tolerance);

  relHum =
      specificHumidityToRelativeHumidity(specificHumidity, temp3, pressure3);
  ASSERT_NEAR(expectRelHum3, relHum, expectRelHum3 * tolerance);
}