@@ -152,27 +152,38 @@ public void SIUnitSystemHasCorrectBaseUnits()
152
152
}
153
153
154
154
[ Fact ]
155
- public void GetDefaultUnitInfoThrowsExceptionForUndefinedQuantity ( )
155
+ public void GetDefaultUnitInfo_GivenUndefinedQuantity_ThrowsArgumentException ( )
156
156
{
157
157
Assert . Throws < ArgumentException > ( ( ) => UnitSystem . SI . GetDefaultUnitInfo ( QuantityType . Undefined ) ) ;
158
158
}
159
159
160
160
[ Fact ]
161
- public void GetDefaultUnitInfoReturnsNullForQuantitiesWithNoDefaultUnits ( )
161
+ public void GetDefaultUnitInfo_GivenQuantityWithNoDefaultUnits_ReturnsNull ( )
162
162
{
163
- // TODO do we expect to preserve this behavior?
164
- // AmplitudeRatio might be unitless- but there are (more than one) ways to express ratios.
165
- Assert . Null ( UnitSystem . SI . GetDefaultUnitInfo ( AmplitudeRatio . QuantityType ) ) ;
163
+ // we cannot simply rely on something like AmplitudeRatio not having a default base unit definition (as this is expected to change soon)
164
+ var unitSystemWithNoDefaultLengthUnit = UnitSystem . SI . WithDefaultUnit ( QuantityType . Length , null ) ; // we can however force the dissociation
165
+
166
+ Assert . Null ( unitSystemWithNoDefaultLengthUnit . GetDefaultUnitInfo ( QuantityType . Length ) ) ;
166
167
}
167
168
168
169
[ Fact ]
169
- public void WithDefaultUnitThrowsIfQuantityTypeIsUndefined ( )
170
+ public void WithDefaultUnit_GivenUndefinedQuantityType_ThrowsArgumentException ( )
170
171
{
171
- Assert . Throws < ArgumentException > ( ( ) => UnitSystem . SI . WithDefaultUnit ( QuantityType . Undefined , null ) ) ;
172
+ var anyUnitInfo = Length . Info . UnitInfos . First ( ) ;
173
+
174
+ Assert . Throws < ArgumentException > ( ( ) => UnitSystem . SI . WithDefaultUnit ( QuantityType . Undefined , anyUnitInfo ) ) ;
175
+ }
176
+
177
+ [ Fact ]
178
+ public void WithDefaultUnit_GivenIncompatibleUnitAndQuantityType_ThrowsArgumentException ( )
179
+ {
180
+ var nonMassUnit = Length . Info . UnitInfos . First ( ) ;
181
+
182
+ Assert . Throws < ArgumentException > ( ( ) => UnitSystem . SI . WithDefaultUnit ( QuantityType . Mass , nonMassUnit ) ) ;
172
183
}
173
184
174
185
[ Fact ]
175
- public void WithDefaultUnitUsesOldBaseUnitsIfNotSpecified ( )
186
+ public void WithDefaultUnit_GivenNullForBaseUnits_ReturnsUnitSystemWithOldBaseUnits ( )
176
187
{
177
188
var myDefaultLengthUnit = Length . Info . UnitInfos . First ( x => x . Value == LengthUnit . Millimeter ) ;
178
189
@@ -189,14 +200,14 @@ public void WithDefaultUnitUsesOldBaseUnitsIfNotSpecified()
189
200
[ InlineData ( LengthUnit . Meter , MassUnit . Kilogram , DurationUnit . Second , ElectricCurrentUnit . Ampere , TemperatureUnit . Undefined , AmountOfSubstanceUnit . Mole , LuminousIntensityUnit . Candela ) ]
190
201
[ InlineData ( LengthUnit . Meter , MassUnit . Kilogram , DurationUnit . Second , ElectricCurrentUnit . Ampere , TemperatureUnit . Kelvin , AmountOfSubstanceUnit . Undefined , LuminousIntensityUnit . Candela ) ]
191
202
[ InlineData ( LengthUnit . Meter , MassUnit . Kilogram , DurationUnit . Second , ElectricCurrentUnit . Ampere , TemperatureUnit . Kelvin , AmountOfSubstanceUnit . Mole , LuminousIntensityUnit . Undefined ) ]
192
- public void WithDefaultUnitThrowsIfSpecifiedBaseUnitsNotFullyDefined ( LengthUnit length , MassUnit mass , DurationUnit time , ElectricCurrentUnit current ,
203
+ public void WithDefaultUnit_GivenBaseUnitsNotFullyDefined_ThrowsArgumentException ( LengthUnit length , MassUnit mass , DurationUnit time , ElectricCurrentUnit current ,
193
204
TemperatureUnit temperature , AmountOfSubstanceUnit amount , LuminousIntensityUnit luminousIntensity )
194
205
{
195
206
var myDefaultLengthUnit = Length . Info . UnitInfos . First ( x => x . Value == LengthUnit . Millimeter ) ;
196
207
197
208
var baseUnits = new BaseUnits ( length , mass , time , current , temperature , amount , luminousIntensity ) ;
198
209
199
- // TODO do we want to preserve this behavior?
210
+ // BaseUnits(obsolete) kept in order to avoid introducing a breaking change (just yet)
200
211
Assert . Throws < ArgumentException > ( ( ) => UnitSystem . SI . WithDefaultUnit ( QuantityType . Length , myDefaultLengthUnit , baseUnits ) ) ;
201
212
}
202
213
0 commit comments