cloudy  trunk
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TestEnergy.cpp
Go to the documentation of this file.
1 /* This file is part of Cloudy and is copyright (C)1978-2022 by Gary J. Ferland and
2  * others. For conditions of distribution and use see copyright notice in license.txt */
3 #include "cdstd.h"
4 #include <UnitTest++.h>
5 #include "cddefines.h"
6 #include "energy.h"
7 
8 namespace {
9 
10  TEST(TestEnergyCTor)
11  {
12  Energy Ezero;
13  CHECK( fp_equal( Ezero.Ryd(), 0. ) );
14  Energy Eryd0(1.);
15  CHECK( fp_equal( Eryd0.Ryd(), 1. ) );
16  Energy Eryd1(1.,"Ryd");
17  CHECK( fp_equal( Eryd1.Ryd(), 1. ) );
18  Energy Eerg(1.,"erg");
19  CHECK( fp_equal( Eerg.Ryd(), 1./EN1RYD ) );
20  Energy EeV(1.,"eV");
21  CHECK( fp_equal( EeV.Ryd(), 1./EVRYD ) );
22  Energy EkeV(1.,"keV");
23  CHECK( fp_equal( EkeV.Ryd(), 1.e3/EVRYD ) );
24  Energy EMeV(1.,"MeV");
25  CHECK( fp_equal( EMeV.Ryd(), 1.e6/EVRYD ) );
26  Energy Ewavn(1.,"cm^-1");
27  CHECK( fp_equal( Ewavn.Ryd(), 1./RYD_INF ) );
28  Energy Ecm(1.,"cm");
29  CHECK( fp_equal( Ecm.Ryd(), RYDLAM/1.e8 ) );
30  Energy Emm(1.,"mm");
31  CHECK( fp_equal( Emm.Ryd(), RYDLAM/1.e7 ) );
32  Energy Eum(1.,"um");
33  CHECK( fp_equal( Eum.Ryd(), RYDLAM/1.e4 ) );
34  Energy Enm(1.,"nm");
35  CHECK( fp_equal( Enm.Ryd(), RYDLAM/1.e1 ) );
36  Energy EA(1.,"A");
37  CHECK( fp_equal( EA.Ryd(), RYDLAM ) );
38  Energy EHz(1.,"Hz");
39  CHECK( fp_equal( EHz.Ryd(), 1./FR1RYD ) );
40  Energy EkHz(1.,"kHz");
41  CHECK( fp_equal( EkHz.Ryd(), 1.e3/FR1RYD ) );
42  Energy EMHz(1.,"MHz");
43  CHECK( fp_equal( EMHz.Ryd(), 1.e6/FR1RYD ) );
44  Energy EGHz(1.,"GHz");
45  CHECK( fp_equal( EGHz.Ryd(), 1.e9/FR1RYD ) );
46  Energy EK(1.,"K");
47  CHECK( fp_equal( EK.Ryd(), 1./TE1RYD ) );
48  }
49 
50  TEST(TestEnergySet)
51  {
52  Energy E;
53  E.set(10.);
54  CHECK( fp_equal( E.Ryd(), 10. ) );
55  E.set(10.,"Ryd");
56  CHECK( fp_equal( E.Ryd(), 10. ) );
57  E.set(10.,"erg");
58  CHECK( fp_equal( E.Ryd(), 10./EN1RYD ) );
59  E.set(10.,"eV");
60  CHECK( fp_equal( E.Ryd(), 10./EVRYD ) );
61  E.set(10.,"keV");
62  CHECK( fp_equal( E.Ryd(), 1.e4/EVRYD ) );
63  E.set(10.,"MeV");
64  CHECK( fp_equal( E.Ryd(), 1.e7/EVRYD ) );
65  E.set(10.,"cm^-1");
66  CHECK( fp_equal( E.Ryd(), 10./RYD_INF ) );
67  E.set(10.,"cm");
68  CHECK( fp_equal( E.Ryd(), RYDLAM/1.e9 ) );
69  E.set(10.,"mm");
70  CHECK( fp_equal( E.Ryd(), RYDLAM/1.e8 ) );
71  E.set(10.,"um");
72  CHECK( fp_equal( E.Ryd(), RYDLAM/1.e5 ) );
73  E.set(10.,"nm");
74  CHECK( fp_equal( E.Ryd(), RYDLAM/1.e2 ) );
75  E.set(10.,"A");
76  CHECK( fp_equal( E.Ryd(), RYDLAM/10. ) );
77  E.set(10.,"Hz");
78  CHECK( fp_equal( E.Ryd(), 10./FR1RYD ) );
79  E.set(10.,"kHz");
80  CHECK( fp_equal( E.Ryd(), 1.e4/FR1RYD ) );
81  E.set(10.,"MHz");
82  CHECK( fp_equal( E.Ryd(), 1.e7/FR1RYD ) );
83  E.set(10.,"GHz");
84  CHECK( fp_equal( E.Ryd(), 1.e10/FR1RYD ) );
85  E.set(10.,"K");
86  CHECK( fp_equal( E.Ryd(), 10./TE1RYD ) );
87  }
88 
89  TEST(TestEnergyGet)
90  {
91  Energy E( 1. );
92  CHECK( fp_equal( E.get("Ryd"), 1. ) );
93  CHECK( fp_equal( E.get("erg"), EN1RYD ) );
94  CHECK( fp_equal( E.get("eV"), EVRYD ) );
95  CHECK( fp_equal( E.get("keV"), EVRYD/1.e3 ) );
96  CHECK( fp_equal( E.get("MeV"), EVRYD/1.e6 ) );
97  CHECK( fp_equal( E.get("cm^-1"), RYD_INF ) );
98  CHECK( fp_equal( E.get("cm"), RYDLAM/1.e8 ) );
99  CHECK( fp_equal( E.get("mm"), RYDLAM/1.e7 ) );
100  CHECK( fp_equal( E.get("um"), RYDLAM/1.e4 ) );
101  CHECK( fp_equal( E.get("nm"), RYDLAM/1.e1 ) );
102  CHECK( fp_equal( E.get("A"), RYDLAM ) );
103  CHECK( fp_equal( E.get("Hz"), FR1RYD ) );
104  CHECK( fp_equal( E.get("kHz"), FR1RYD/1.e3 ) );
105  CHECK( fp_equal( E.get("MHz"), FR1RYD/1.e6 ) );
106  CHECK( fp_equal( E.get("GHz"), FR1RYD/1.e9 ) );
107  CHECK( fp_equal( E.get("K"), TE1RYD ) );
108  }
109 
110  TEST(TestEnergyGet2)
111  {
112  Energy E( 1. );
113  CHECK( fp_equal( E.Ryd(), 1. ) );
114  CHECK( fp_equal( E.Erg(), EN1RYD ) );
115  CHECK( fp_equal( E.eV(), EVRYD ) );
116  CHECK( fp_equal( E.keV(), EVRYD/1.e3 ) );
117  CHECK( fp_equal( E.MeV(), EVRYD/1.e6 ) );
118  CHECK( fp_equal( E.WN(), RYD_INF ) );
119  CHECK( fp_equal( E.cm(), RYDLAM/1.e8 ) );
120  CHECK( fp_equal( E.mm(), RYDLAM/1.e7 ) );
121  CHECK( fp_equal( E.micron(), RYDLAM/1.e4 ) );
122  CHECK( fp_equal( E.nm(), RYDLAM/1.e1 ) );
123  CHECK( fp_equal( E.Angstrom(), RYDLAM ) );
124  CHECK( fp_equal( E.Hz(), FR1RYD ) );
125  CHECK( fp_equal( E.kHz(), FR1RYD/1.e3 ) );
126  CHECK( fp_equal( E.MHz(), FR1RYD/1.e6 ) );
127  CHECK( fp_equal( E.GHz(), FR1RYD/1.e9 ) );
128  CHECK( fp_equal( E.K(), TE1RYD ) );
129  }
130 
131  TEST(TestEnergyUnitConversion)
132  {
133  Energy E( 10. );
134  CHECK( fp_equal( E.get( StandardEnergyUnit(" RYDBERG ") ), 10. ) );
135  CHECK( fp_equal( E.get( StandardEnergyUnit(" ERG ")), 10.*EN1RYD ) );
136  CHECK( fp_equal( E.get( StandardEnergyUnit(" EV ") ), 10.*EVRYD ) );
137  CHECK( fp_equal( E.get( StandardEnergyUnit(" KEV ") ), EVRYD/1.e2 ) );
138  CHECK( fp_equal( E.get( StandardEnergyUnit(" MEV ") ), EVRYD/1.e5 ) );
139  CHECK( fp_equal( E.get( StandardEnergyUnit(" WAVENUMBERS ") ), 10.*RYD_INF ) );
140  CHECK( fp_equal( E.get( StandardEnergyUnit(" CM ") ), RYDLAM/1.e9 ) );
141  CHECK( fp_equal( E.get( StandardEnergyUnit(" CENTIMETER ") ), RYDLAM/1.e9 ) );
142  CHECK( fp_equal( E.get( StandardEnergyUnit(" MM ") ), RYDLAM/1.e8 ) );
143  CHECK( fp_equal( E.get( StandardEnergyUnit(" MICRON ") ), RYDLAM/1.e5 ) );
144  CHECK( fp_equal( E.get( StandardEnergyUnit(" NM ") ), RYDLAM/1.e2 ) );
145  CHECK( fp_equal( E.get( StandardEnergyUnit(" ANGSTROM ") ), RYDLAM/10. ) );
146  CHECK( fp_equal( E.get( StandardEnergyUnit(" HZ ") ), 10.*FR1RYD ) );
147  CHECK( fp_equal( E.get( StandardEnergyUnit(" KHZ ") ), FR1RYD/1.e2 ) );
148  CHECK( fp_equal( E.get( StandardEnergyUnit(" MHZ ") ), FR1RYD/1.e5 ) );
149  CHECK( fp_equal( E.get( StandardEnergyUnit(" GHZ ") ), FR1RYD/1.e8 ) );
150  CHECK( fp_equal( E.get( StandardEnergyUnit(" K ") ), 10.*TE1RYD ) );
151  CHECK( fp_equal( E.get( StandardEnergyUnit(" KELVIN ") ), 10.*TE1RYD ) );
152  }
153 
154  TEST(TestEnergyOperator)
155  {
156  Energy E10( 10. );
157  Energy E11( 11. );
158  CHECK( E10 < E11 );
159  CHECK( !( E11 < E11 ) );
160  CHECK( !( E11 < E10 ) );
161  }
162 
163 }
double Hz() const
Definition: energy.h:61
double Angstrom() const
Definition: energy.h:77
double GHz() const
Definition: energy.h:73
void set(double energy)
Definition: energy.h:26
double keV() const
Definition: energy.h:53
double cm() const
Definition: energy.h:93
double WN() const
Definition: energy.h:45
bool fp_equal(sys_float x, sys_float y, int n=3)
Definition: cddefines.h:854
double Erg() const
Definition: energy.h:41
double MeV() const
Definition: energy.h:57
double nm() const
Definition: energy.h:81
double K() const
Definition: energy.h:37
double eV() const
Definition: energy.h:49
double kHz() const
Definition: energy.h:65
const char * StandardEnergyUnit(const char *chCard)
Definition: energy.cpp:44
double Ryd() const
Definition: energy.h:33
Definition: energy.h:9
double mm() const
Definition: energy.h:89
double micron() const
Definition: energy.h:85
double MHz() const
Definition: energy.h:69
double get(const char *unit) const
Definition: energy.cpp:138