1919// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2020// THE SOFTWARE.
2121
22+ using System ;
2223using UnitsNet . Units ;
2324using Xunit ;
2425
@@ -27,14 +28,119 @@ namespace UnitsNet.Tests
2728 public class UnitSystemTests
2829 {
2930 [ Fact ]
30- public void Constructor ( )
31+ public void ConstructorImplementedProperly ( )
3132 {
32- var siBaseUnits = new BaseUnits ( LengthUnit . Meter , MassUnit . Kilogram , DurationUnit . Second ,
33+ var baseUnits = new BaseUnits ( LengthUnit . Meter , MassUnit . Kilogram , DurationUnit . Second ,
3334 ElectricCurrentUnit . Ampere , TemperatureUnit . Kelvin , AmountOfSubstanceUnit . Mole , LuminousIntensityUnit . Candela ) ;
3435
35- var unitSystem = new UnitSystem ( siBaseUnits ) ;
36+ var unitSystem = new UnitSystem ( baseUnits ) ;
37+
38+ Assert . Equal ( unitSystem . BaseUnits , baseUnits ) ;
39+ }
40+
41+ [ Fact ]
42+ public void ConstructorThrowsArgumentNullExceptionForNullBaseUnits ( )
43+ {
44+ Assert . Throws < ArgumentNullException > ( ( ) => new UnitSystem ( null ) ) ;
45+ }
46+
47+ [ Theory ]
48+ [ InlineData ( LengthUnit . Undefined , MassUnit . Kilogram , DurationUnit . Second , ElectricCurrentUnit . Ampere , TemperatureUnit . Kelvin , AmountOfSubstanceUnit . Mole , LuminousIntensityUnit . Candela ) ]
49+ [ InlineData ( LengthUnit . Meter , MassUnit . Undefined , DurationUnit . Second , ElectricCurrentUnit . Ampere , TemperatureUnit . Kelvin , AmountOfSubstanceUnit . Mole , LuminousIntensityUnit . Candela ) ]
50+ [ InlineData ( LengthUnit . Meter , MassUnit . Kilogram , DurationUnit . Undefined , ElectricCurrentUnit . Ampere , TemperatureUnit . Kelvin , AmountOfSubstanceUnit . Mole , LuminousIntensityUnit . Candela ) ]
51+ [ InlineData ( LengthUnit . Meter , MassUnit . Kilogram , DurationUnit . Second , ElectricCurrentUnit . Undefined , TemperatureUnit . Kelvin , AmountOfSubstanceUnit . Mole , LuminousIntensityUnit . Candela ) ]
52+ [ InlineData ( LengthUnit . Meter , MassUnit . Kilogram , DurationUnit . Second , ElectricCurrentUnit . Ampere , TemperatureUnit . Undefined , AmountOfSubstanceUnit . Mole , LuminousIntensityUnit . Candela ) ]
53+ [ InlineData ( LengthUnit . Meter , MassUnit . Kilogram , DurationUnit . Second , ElectricCurrentUnit . Ampere , TemperatureUnit . Kelvin , AmountOfSubstanceUnit . Undefined , LuminousIntensityUnit . Candela ) ]
54+ [ InlineData ( LengthUnit . Meter , MassUnit . Kilogram , DurationUnit . Second , ElectricCurrentUnit . Ampere , TemperatureUnit . Kelvin , AmountOfSubstanceUnit . Mole , LuminousIntensityUnit . Undefined ) ]
55+ public void ConstructorThrowsArgumentExceptionWithUndefinedUnits ( LengthUnit length , MassUnit mass , DurationUnit time , ElectricCurrentUnit current ,
56+ TemperatureUnit temperature , AmountOfSubstanceUnit amount , LuminousIntensityUnit luminousIntensity )
57+ {
58+ var baseUnits = new BaseUnits ( length , mass , time , current , temperature , amount , luminousIntensity ) ;
59+ Assert . Throws < ArgumentException > ( ( ) => new UnitSystem ( baseUnits ) ) ;
60+ }
61+
62+ [ Fact ]
63+ public void EqualsObjectIsImplementedCorrectly ( )
64+ {
65+ var unitSystem1 = new UnitSystem ( new BaseUnits ( LengthUnit . Meter , MassUnit . Kilogram , DurationUnit . Second ,
66+ ElectricCurrentUnit . Ampere , TemperatureUnit . Kelvin , AmountOfSubstanceUnit . Mole , LuminousIntensityUnit . Candela ) ) ;
67+
68+ var unitSystem2 = new UnitSystem ( new BaseUnits ( LengthUnit . Meter , MassUnit . Kilogram , DurationUnit . Second ,
69+ ElectricCurrentUnit . Ampere , TemperatureUnit . Kelvin , AmountOfSubstanceUnit . Mole , LuminousIntensityUnit . Candela ) ) ;
70+
71+ var unitSystem3 = new UnitSystem ( new BaseUnits ( LengthUnit . Foot , MassUnit . Pound , DurationUnit . Second ,
72+ ElectricCurrentUnit . Ampere , TemperatureUnit . DegreeFahrenheit , AmountOfSubstanceUnit . Mole , LuminousIntensityUnit . Candela ) ) ;
73+
74+ Assert . True ( unitSystem1 . Equals ( ( object ) unitSystem2 ) ) ;
75+ Assert . False ( unitSystem1 . Equals ( ( object ) unitSystem3 ) ) ;
76+
77+ Assert . False ( unitSystem1 . Equals ( "Some object." ) ) ;
78+ Assert . False ( unitSystem1 . Equals ( ( IFormatProvider ) null ) ) ;
79+ }
80+
81+ [ Fact ]
82+ public void EqualsUnitSystemIsImplementedCorrectly ( )
83+ {
84+ var unitSystem1 = new UnitSystem ( new BaseUnits ( LengthUnit . Meter , MassUnit . Kilogram , DurationUnit . Second ,
85+ ElectricCurrentUnit . Ampere , TemperatureUnit . Kelvin , AmountOfSubstanceUnit . Mole , LuminousIntensityUnit . Candela ) ) ;
86+
87+ var unitSystem2 = new UnitSystem ( new BaseUnits ( LengthUnit . Meter , MassUnit . Kilogram , DurationUnit . Second ,
88+ ElectricCurrentUnit . Ampere , TemperatureUnit . Kelvin , AmountOfSubstanceUnit . Mole , LuminousIntensityUnit . Candela ) ) ;
89+
90+ var unitSystem3 = new UnitSystem ( new BaseUnits ( LengthUnit . Foot , MassUnit . Pound , DurationUnit . Second ,
91+ ElectricCurrentUnit . Ampere , TemperatureUnit . DegreeFahrenheit , AmountOfSubstanceUnit . Mole , LuminousIntensityUnit . Candela ) ) ;
92+
93+ Assert . True ( unitSystem1 . Equals ( unitSystem2 ) ) ;
94+ Assert . True ( unitSystem2 . Equals ( unitSystem1 ) ) ;
95+
96+ Assert . False ( unitSystem1 . Equals ( unitSystem3 ) ) ;
97+ Assert . False ( unitSystem3 . Equals ( unitSystem1 ) ) ;
98+
99+ Assert . False ( unitSystem1 . Equals ( null ) ) ;
100+ }
101+
102+ [ Fact ]
103+ public void EqualityOperatorIsImplementedCorrectly ( )
104+ {
105+ var unitSystem1 = new UnitSystem ( new BaseUnits ( LengthUnit . Meter , MassUnit . Kilogram , DurationUnit . Second ,
106+ ElectricCurrentUnit . Ampere , TemperatureUnit . Kelvin , AmountOfSubstanceUnit . Mole , LuminousIntensityUnit . Candela ) ) ;
107+
108+ var unitSystem2 = new UnitSystem ( new BaseUnits ( LengthUnit . Meter , MassUnit . Kilogram , DurationUnit . Second ,
109+ ElectricCurrentUnit . Ampere , TemperatureUnit . Kelvin , AmountOfSubstanceUnit . Mole , LuminousIntensityUnit . Candela ) ) ;
110+
111+ var unitSystem3 = new UnitSystem ( new BaseUnits ( LengthUnit . Foot , MassUnit . Pound , DurationUnit . Second ,
112+ ElectricCurrentUnit . Ampere , TemperatureUnit . DegreeFahrenheit , AmountOfSubstanceUnit . Mole , LuminousIntensityUnit . Candela ) ) ;
113+
114+ Assert . True ( unitSystem1 == unitSystem2 ) ;
115+ Assert . True ( unitSystem2 == unitSystem1 ) ;
116+
117+ Assert . False ( unitSystem1 == unitSystem3 ) ;
118+ Assert . False ( unitSystem3 == unitSystem1 ) ;
119+
120+ Assert . False ( unitSystem1 == null ) ;
121+ Assert . False ( null == unitSystem1 ) ;
122+ }
123+
124+ [ Fact ]
125+ public void InequalityOperatorIsImplementedCorrectly ( )
126+ {
127+ var unitSystem1 = new UnitSystem ( new BaseUnits ( LengthUnit . Meter , MassUnit . Kilogram , DurationUnit . Second ,
128+ ElectricCurrentUnit . Ampere , TemperatureUnit . Kelvin , AmountOfSubstanceUnit . Mole , LuminousIntensityUnit . Candela ) ) ;
129+
130+ var unitSystem2 = new UnitSystem ( new BaseUnits ( LengthUnit . Meter , MassUnit . Kilogram , DurationUnit . Second ,
131+ ElectricCurrentUnit . Ampere , TemperatureUnit . Kelvin , AmountOfSubstanceUnit . Mole , LuminousIntensityUnit . Candela ) ) ;
132+
133+ var unitSystem3 = new UnitSystem ( new BaseUnits ( LengthUnit . Foot , MassUnit . Pound , DurationUnit . Second ,
134+ ElectricCurrentUnit . Ampere , TemperatureUnit . DegreeFahrenheit , AmountOfSubstanceUnit . Mole , LuminousIntensityUnit . Candela ) ) ;
135+
136+ Assert . False ( unitSystem1 != unitSystem2 ) ;
137+ Assert . False ( unitSystem2 != unitSystem1 ) ;
138+
139+ Assert . True ( unitSystem1 != unitSystem3 ) ;
140+ Assert . True ( unitSystem3 != unitSystem1 ) ;
36141
37- Assert . Equal ( unitSystem . BaseUnits , siBaseUnits ) ;
142+ Assert . True ( unitSystem1 != null ) ;
143+ Assert . True ( null != unitSystem1 ) ;
38144 }
39145
40146 [ Fact ]
0 commit comments