1
- using System ;
2
- using NUnit . Framework ;
3
-
4
- namespace UnitsNet . Tests . net35
5
- {
6
- [ TestFixture ]
7
- public class UnitConverterTests
8
- {
9
- private const double Delta = 1E-5 ;
10
-
1
+ using System ;
2
+ using NUnit . Framework ;
3
+
4
+ namespace UnitsNet . Tests . net35
5
+ {
6
+ [ TestFixture ]
7
+ public class UnitConverterTests
8
+ {
9
+ private const double Delta = 1E-5 ;
10
+
11
11
// TODO Test Force, Length2d, Mass, Pressure units.
12
-
13
- [ Test ]
14
- public void MeterToLengthUnits ( )
15
- {
16
- Assert . AreEqual ( 1E-3 , UnitConverter . Convert ( 1 , Unit . Meter , Unit . Kilometer ) ) ;
17
- Assert . AreEqual ( 1 , UnitConverter . Convert ( 1 , Unit . Meter , Unit . Meter ) ) ;
18
- Assert . AreEqual ( 1E1 , UnitConverter . Convert ( 1 , Unit . Meter , Unit . Decimeter ) ) ;
19
- Assert . AreEqual ( 1E2 , UnitConverter . Convert ( 1 , Unit . Meter , Unit . Centimeter ) ) ;
20
- Assert . AreEqual ( 1E3 , UnitConverter . Convert ( 1 , Unit . Meter , Unit . Millimeter ) ) ;
21
- Assert . AreEqual ( 1E6 , UnitConverter . Convert ( 1 , Unit . Meter , Unit . Micrometer ) ) ;
22
- Assert . AreEqual ( 1E9 , UnitConverter . Convert ( 1 , Unit . Meter , Unit . Nanometer ) ) ;
23
-
24
- Assert . AreEqual ( 0.000621371 , UnitConverter . Convert ( 1 , Unit . Meter , Unit . Mile ) , Delta ) ;
25
- Assert . AreEqual ( 1.09361 , UnitConverter . Convert ( 1 , Unit . Meter , Unit . Yard ) , Delta ) ;
26
- Assert . AreEqual ( 3.28084 , UnitConverter . Convert ( 1 , Unit . Meter , Unit . Foot ) , Delta ) ;
27
- Assert . AreEqual ( 39.3701 , UnitConverter . Convert ( 1 , Unit . Meter , Unit . Inch ) , Delta ) ;
12
+
13
+ [ Test ]
14
+ public void MeterToLengthUnits ( )
15
+ {
16
+ Assert . AreEqual ( 1E-3 , UnitConverter . Convert ( 1 , Unit . Meter , Unit . Kilometer ) ) ;
17
+ Assert . AreEqual ( 1 , UnitConverter . Convert ( 1 , Unit . Meter , Unit . Meter ) ) ;
18
+ Assert . AreEqual ( 1E1 , UnitConverter . Convert ( 1 , Unit . Meter , Unit . Decimeter ) ) ;
19
+ Assert . AreEqual ( 1E2 , UnitConverter . Convert ( 1 , Unit . Meter , Unit . Centimeter ) ) ;
20
+ Assert . AreEqual ( 1E3 , UnitConverter . Convert ( 1 , Unit . Meter , Unit . Millimeter ) ) ;
21
+ Assert . AreEqual ( 1E6 , UnitConverter . Convert ( 1 , Unit . Meter , Unit . Micrometer ) ) ;
22
+ Assert . AreEqual ( 1E9 , UnitConverter . Convert ( 1 , Unit . Meter , Unit . Nanometer ) ) ;
23
+
24
+ Assert . AreEqual ( 0.000621371 , UnitConverter . Convert ( 1 , Unit . Meter , Unit . Mile ) , Delta ) ;
25
+ Assert . AreEqual ( 1.09361 , UnitConverter . Convert ( 1 , Unit . Meter , Unit . Yard ) , Delta ) ;
26
+ Assert . AreEqual ( 3.28084 , UnitConverter . Convert ( 1 , Unit . Meter , Unit . Foot ) , Delta ) ;
27
+ Assert . AreEqual ( 39.3701 , UnitConverter . Convert ( 1 , Unit . Meter , Unit . Inch ) , Delta ) ;
28
28
}
29
29
30
30
[ Test ]
@@ -42,7 +42,7 @@ public void SquareMeterToAreaUnits()
42
42
Assert . AreEqual ( 1550.003100 , UnitConverter . Convert ( 1 , Unit . SquareMeter , Unit . SquareInch ) , Delta ) ;
43
43
}
44
44
45
- [ Test ]
45
+ [ Test ]
46
46
public void CubicMeterToVolumeUnits ( )
47
47
{
48
48
Assert . AreEqual ( 1E-9 , UnitConverter . Convert ( 1 , Unit . CubicMeter , Unit . CubicKilometer ) , Delta ) ;
@@ -114,72 +114,72 @@ public void CubicMeterPerSecondToFlowUnits()
114
114
}
115
115
116
116
[ Test ]
117
- public void ThrowsOnIncompatibleUnits ( )
118
- {
119
- Assert . Throws < Exception > ( ( ) => UnitConverter . Convert ( 1 , Unit . Meter , Unit . Second ) ) ;
120
- Assert . Throws < Exception > ( ( ) => UnitConverter . Convert ( 1 , Unit . SquareMeter , Unit . Second ) ) ;
121
- Assert . Throws < Exception > ( ( ) => UnitConverter . Convert ( 1 , Unit . CubicMeter , Unit . Second ) ) ;
122
- Assert . Throws < Exception > ( ( ) => UnitConverter . Convert ( 1 , Unit . Newton , Unit . Second ) ) ;
123
- Assert . Throws < Exception > ( ( ) => UnitConverter . Convert ( 1 , Unit . Pascal , Unit . Second ) ) ;
124
- Assert . Throws < Exception > ( ( ) => UnitConverter . Convert ( 1 , Unit . Kilogram , Unit . Second ) ) ;
117
+ public void ThrowsOnIncompatibleUnits ( )
118
+ {
119
+ Assert . Throws < Exception > ( ( ) => UnitConverter . Convert ( 1 , Unit . Meter , Unit . Second ) ) ;
120
+ Assert . Throws < Exception > ( ( ) => UnitConverter . Convert ( 1 , Unit . SquareMeter , Unit . Second ) ) ;
121
+ Assert . Throws < Exception > ( ( ) => UnitConverter . Convert ( 1 , Unit . CubicMeter , Unit . Second ) ) ;
122
+ Assert . Throws < Exception > ( ( ) => UnitConverter . Convert ( 1 , Unit . Newton , Unit . Second ) ) ;
123
+ Assert . Throws < Exception > ( ( ) => UnitConverter . Convert ( 1 , Unit . Pascal , Unit . Second ) ) ;
124
+ Assert . Throws < Exception > ( ( ) => UnitConverter . Convert ( 1 , Unit . Kilogram , Unit . Second ) ) ;
125
125
Assert . Throws < Exception > ( ( ) => UnitConverter . Convert ( 1 , Unit . Degree , Unit . Second ) ) ;
126
126
Assert . Throws < Exception > ( ( ) => UnitConverter . Convert ( 1 , Unit . CubicMeterPerSecond , Unit . Second ) ) ;
127
- Assert . Throws < Exception > ( ( ) => UnitConverter . Convert ( 1 , Unit . RevolutionsPerSecond , Unit . Second ) ) ;
128
- }
129
-
130
- [ Test ]
131
- public void TryConvertReturnsFalseOnIncompatibleUnits ( )
132
- {
133
- double newValue ;
134
-
135
- // Assert from-unit cases. One for each class of unit.
136
- Assert . False ( UnitConverter . TryConvert ( 1 , Unit . Meter , Unit . Second , out newValue ) ) ;
137
- Assert . False ( UnitConverter . TryConvert ( 1 , Unit . SquareMeter , Unit . Second , out newValue ) ) ;
138
- Assert . False ( UnitConverter . TryConvert ( 1 , Unit . CubicMeter , Unit . Second , out newValue ) ) ;
139
- Assert . False ( UnitConverter . TryConvert ( 1 , Unit . Newton , Unit . Second , out newValue ) ) ;
140
- Assert . False ( UnitConverter . TryConvert ( 1 , Unit . Pascal , Unit . Second , out newValue ) ) ;
141
- Assert . False ( UnitConverter . TryConvert ( 1 , Unit . Kilogram , Unit . Second , out newValue ) ) ;
127
+ Assert . Throws < Exception > ( ( ) => UnitConverter . Convert ( 1 , Unit . RevolutionsPerSecond , Unit . Second ) ) ;
128
+ }
129
+
130
+ [ Test ]
131
+ public void TryConvertReturnsFalseOnIncompatibleUnits ( )
132
+ {
133
+ double newValue ;
134
+
135
+ // Assert from-unit cases. One for each class of unit.
136
+ Assert . False ( UnitConverter . TryConvert ( 1 , Unit . Meter , Unit . Second , out newValue ) ) ;
137
+ Assert . False ( UnitConverter . TryConvert ( 1 , Unit . SquareMeter , Unit . Second , out newValue ) ) ;
138
+ Assert . False ( UnitConverter . TryConvert ( 1 , Unit . CubicMeter , Unit . Second , out newValue ) ) ;
139
+ Assert . False ( UnitConverter . TryConvert ( 1 , Unit . Newton , Unit . Second , out newValue ) ) ;
140
+ Assert . False ( UnitConverter . TryConvert ( 1 , Unit . Pascal , Unit . Second , out newValue ) ) ;
141
+ Assert . False ( UnitConverter . TryConvert ( 1 , Unit . Kilogram , Unit . Second , out newValue ) ) ;
142
142
Assert . False ( UnitConverter . TryConvert ( 1 , Unit . Degree , Unit . Second , out newValue ) ) ;
143
143
Assert . False ( UnitConverter . TryConvert ( 1 , Unit . CubicMeterPerSecond , Unit . Second , out newValue ) ) ;
144
- Assert . False ( UnitConverter . TryConvert ( 1 , Unit . RevolutionsPerSecond , Unit . Second , out newValue ) ) ;
145
-
146
- // Assert to-unit cases. One for each class of unit.
147
- Assert . False ( UnitConverter . TryConvert ( 1 , Unit . Second , Unit . Meter , out newValue ) ) ;
148
- Assert . False ( UnitConverter . TryConvert ( 1 , Unit . Second , Unit . SquareMeter , out newValue ) ) ;
149
- Assert . False ( UnitConverter . TryConvert ( 1 , Unit . Second , Unit . CubicMeter , out newValue ) ) ;
150
- Assert . False ( UnitConverter . TryConvert ( 1 , Unit . Second , Unit . Newton , out newValue ) ) ;
151
- Assert . False ( UnitConverter . TryConvert ( 1 , Unit . Second , Unit . Pascal , out newValue ) ) ;
152
- Assert . False ( UnitConverter . TryConvert ( 1 , Unit . Second , Unit . Kilogram , out newValue ) ) ;
144
+ Assert . False ( UnitConverter . TryConvert ( 1 , Unit . RevolutionsPerSecond , Unit . Second , out newValue ) ) ;
145
+
146
+ // Assert to-unit cases. One for each class of unit.
147
+ Assert . False ( UnitConverter . TryConvert ( 1 , Unit . Second , Unit . Meter , out newValue ) ) ;
148
+ Assert . False ( UnitConverter . TryConvert ( 1 , Unit . Second , Unit . SquareMeter , out newValue ) ) ;
149
+ Assert . False ( UnitConverter . TryConvert ( 1 , Unit . Second , Unit . CubicMeter , out newValue ) ) ;
150
+ Assert . False ( UnitConverter . TryConvert ( 1 , Unit . Second , Unit . Newton , out newValue ) ) ;
151
+ Assert . False ( UnitConverter . TryConvert ( 1 , Unit . Second , Unit . Pascal , out newValue ) ) ;
152
+ Assert . False ( UnitConverter . TryConvert ( 1 , Unit . Second , Unit . Kilogram , out newValue ) ) ;
153
153
Assert . False ( UnitConverter . TryConvert ( 1 , Unit . Second , Unit . Degree , out newValue ) ) ;
154
154
Assert . False ( UnitConverter . TryConvert ( 1 , Unit . Second , Unit . CubicMeterPerSecond , out newValue ) ) ;
155
- Assert . False ( UnitConverter . TryConvert ( 1 , Unit . Second , Unit . RevolutionsPerSecond , out newValue ) ) ;
156
- }
157
-
158
- [ Test ]
159
- public void TryConvertReturnsTrueOnCompatibleUnits ( )
160
- {
161
- double newValue ;
162
-
163
- // Assert from-unit cases. One for each class of unit.
164
- Assert . True ( UnitConverter . TryConvert ( 1 , Unit . Meter , Unit . Centimeter , out newValue ) ) ;
165
- Assert . True ( UnitConverter . TryConvert ( 1 , Unit . SquareMeter , Unit . SquareCentimeter , out newValue ) ) ;
166
- Assert . True ( UnitConverter . TryConvert ( 1 , Unit . CubicMeter , Unit . Liter , out newValue ) ) ;
167
- Assert . True ( UnitConverter . TryConvert ( 1 , Unit . Newton , Unit . KilogramForce , out newValue ) ) ;
168
- Assert . True ( UnitConverter . TryConvert ( 1 , Unit . Pascal , Unit . KiloPascal , out newValue ) ) ;
169
- Assert . True ( UnitConverter . TryConvert ( 1 , Unit . Kilogram , Unit . Gram , out newValue ) ) ;
155
+ Assert . False ( UnitConverter . TryConvert ( 1 , Unit . Second , Unit . RevolutionsPerSecond , out newValue ) ) ;
156
+ }
157
+
158
+ [ Test ]
159
+ public void TryConvertReturnsTrueOnCompatibleUnits ( )
160
+ {
161
+ double newValue ;
162
+
163
+ // Assert from-unit cases. One for each class of unit.
164
+ Assert . True ( UnitConverter . TryConvert ( 1 , Unit . Meter , Unit . Centimeter , out newValue ) ) ;
165
+ Assert . True ( UnitConverter . TryConvert ( 1 , Unit . SquareMeter , Unit . SquareCentimeter , out newValue ) ) ;
166
+ Assert . True ( UnitConverter . TryConvert ( 1 , Unit . CubicMeter , Unit . Liter , out newValue ) ) ;
167
+ Assert . True ( UnitConverter . TryConvert ( 1 , Unit . Newton , Unit . KilogramForce , out newValue ) ) ;
168
+ Assert . True ( UnitConverter . TryConvert ( 1 , Unit . Pascal , Unit . KiloPascal , out newValue ) ) ;
169
+ Assert . True ( UnitConverter . TryConvert ( 1 , Unit . Kilogram , Unit . Gram , out newValue ) ) ;
170
170
Assert . True ( UnitConverter . TryConvert ( 1 , Unit . Degree , Unit . Radian , out newValue ) ) ;
171
171
Assert . True ( UnitConverter . TryConvert ( 1 , Unit . CubicMeterPerSecond , Unit . CubicMeterPerHour , out newValue ) ) ;
172
- Assert . True ( UnitConverter . TryConvert ( 1 , Unit . RevolutionsPerSecond , Unit . RevolutionsPerMinute , out newValue ) ) ;
173
-
174
- // Assert to-unit cases. One for each class of unit.
175
- Assert . True ( UnitConverter . TryConvert ( 1 , Unit . Centimeter , Unit . Meter , out newValue ) ) ;
176
- Assert . True ( UnitConverter . TryConvert ( 1 , Unit . SquareCentimeter , Unit . SquareMeter , out newValue ) ) ;
177
- Assert . True ( UnitConverter . TryConvert ( 1 , Unit . Liter , Unit . CubicMeter , out newValue ) ) ;
178
- Assert . True ( UnitConverter . TryConvert ( 1 , Unit . KilogramForce , Unit . Newton , out newValue ) ) ;
179
- Assert . True ( UnitConverter . TryConvert ( 1 , Unit . KiloPascal , Unit . Pascal , out newValue ) ) ;
180
- Assert . True ( UnitConverter . TryConvert ( 1 , Unit . Gram , Unit . Kilogram , out newValue ) ) ;
172
+ Assert . True ( UnitConverter . TryConvert ( 1 , Unit . RevolutionsPerSecond , Unit . RevolutionsPerMinute , out newValue ) ) ;
173
+
174
+ // Assert to-unit cases. One for each class of unit.
175
+ Assert . True ( UnitConverter . TryConvert ( 1 , Unit . Centimeter , Unit . Meter , out newValue ) ) ;
176
+ Assert . True ( UnitConverter . TryConvert ( 1 , Unit . SquareCentimeter , Unit . SquareMeter , out newValue ) ) ;
177
+ Assert . True ( UnitConverter . TryConvert ( 1 , Unit . Liter , Unit . CubicMeter , out newValue ) ) ;
178
+ Assert . True ( UnitConverter . TryConvert ( 1 , Unit . KilogramForce , Unit . Newton , out newValue ) ) ;
179
+ Assert . True ( UnitConverter . TryConvert ( 1 , Unit . KiloPascal , Unit . Pascal , out newValue ) ) ;
180
+ Assert . True ( UnitConverter . TryConvert ( 1 , Unit . Gram , Unit . Kilogram , out newValue ) ) ;
181
181
Assert . True ( UnitConverter . TryConvert ( 1 , Unit . CubicMeterPerHour , Unit . CubicMeterPerSecond , out newValue ) ) ;
182
- Assert . True ( UnitConverter . TryConvert ( 1 , Unit . RevolutionsPerMinute , Unit . RevolutionsPerSecond , out newValue ) ) ;
183
- }
184
- }
185
- }
182
+ Assert . True ( UnitConverter . TryConvert ( 1 , Unit . RevolutionsPerMinute , Unit . RevolutionsPerSecond , out newValue ) ) ;
183
+ }
184
+ }
185
+ }
0 commit comments