|
| 1 | +// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). |
| 2 | +// https://github.com/angularsen/UnitsNet |
| 3 | +// |
| 4 | +// Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 | +// of this software and associated documentation files (the "Software"), to deal |
| 6 | +// in the Software without restriction, including without limitation the rights |
| 7 | +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 8 | +// copies of the Software, and to permit persons to whom the Software is |
| 9 | +// furnished to do so, subject to the following conditions: |
| 10 | +// |
| 11 | +// The above copyright notice and this permission notice shall be included in |
| 12 | +// all copies or substantial portions of the Software. |
| 13 | +// |
| 14 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 | +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 | +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 20 | +// THE SOFTWARE. |
| 21 | + |
| 22 | +using System; |
| 23 | +using UnitsNet.Units; |
| 24 | +using Xunit; |
| 25 | + |
| 26 | +namespace UnitsNet.Tests |
| 27 | +{ |
| 28 | + public class BaseUnitsTests |
| 29 | + { |
| 30 | + private static BaseUnits siBaseUnits = new BaseUnits(LengthUnit.Meter, MassUnit.Kilogram, DurationUnit.Second, |
| 31 | + ElectricCurrentUnit.Ampere, TemperatureUnit.Kelvin, AmountOfSubstanceUnit.Mole, LuminousIntensityUnit.Candela); |
| 32 | + |
| 33 | + private static BaseUnits siBaseUnitsCopy = new BaseUnits(LengthUnit.Meter, MassUnit.Kilogram, DurationUnit.Second, |
| 34 | + ElectricCurrentUnit.Ampere, TemperatureUnit.Kelvin, AmountOfSubstanceUnit.Mole, LuminousIntensityUnit.Candela); |
| 35 | + |
| 36 | + private static BaseUnits nonSiBaseUnits = new BaseUnits(LengthUnit.Foot, MassUnit.Pound, DurationUnit.Second, |
| 37 | + ElectricCurrentUnit.Ampere, TemperatureUnit.DegreeFahrenheit, AmountOfSubstanceUnit.Mole, LuminousIntensityUnit.Candela); |
| 38 | + |
| 39 | + [Fact] |
| 40 | + public void ConstructorSetsUnitsProperly() |
| 41 | + { |
| 42 | + var baseUnits = new BaseUnits(LengthUnit.Meter, MassUnit.Kilogram, DurationUnit.Second, |
| 43 | + ElectricCurrentUnit.Ampere, TemperatureUnit.Kelvin, AmountOfSubstanceUnit.Mole, LuminousIntensityUnit.Candela); |
| 44 | + |
| 45 | + Assert.Equal(LengthUnit.Meter, baseUnits.Length); |
| 46 | + Assert.Equal(MassUnit.Kilogram, baseUnits.Mass); |
| 47 | + Assert.Equal(DurationUnit.Second, baseUnits.Time); |
| 48 | + Assert.Equal(ElectricCurrentUnit.Ampere, baseUnits.Current); |
| 49 | + Assert.Equal(TemperatureUnit.Kelvin, baseUnits.Temperature); |
| 50 | + Assert.Equal(AmountOfSubstanceUnit.Mole, baseUnits.Amount); |
| 51 | + Assert.Equal(LuminousIntensityUnit.Candela, baseUnits.LuminousIntensity); |
| 52 | + } |
| 53 | + |
| 54 | + [Fact] |
| 55 | + public void EqualsObjectIsImplementedCorrectly() |
| 56 | + { |
| 57 | + Assert.True(siBaseUnits.Equals((object)siBaseUnitsCopy)); |
| 58 | + Assert.False(siBaseUnits.Equals((object)nonSiBaseUnits)); |
| 59 | + |
| 60 | + Assert.False(siBaseUnits.Equals("Some object.")); |
| 61 | + Assert.False(siBaseUnits.Equals((IFormatProvider)null)); |
| 62 | + } |
| 63 | + |
| 64 | + [Fact] |
| 65 | + public void EqualsBaseUnitsIsImplementedCorrectly() |
| 66 | + { |
| 67 | + Assert.True(siBaseUnits.Equals(siBaseUnitsCopy)); |
| 68 | + Assert.True(siBaseUnitsCopy.Equals(siBaseUnits)); |
| 69 | + |
| 70 | + Assert.False(siBaseUnits.Equals(nonSiBaseUnits)); |
| 71 | + Assert.False(nonSiBaseUnits.Equals(siBaseUnits)); |
| 72 | + |
| 73 | + Assert.False(siBaseUnits.Equals(null)); |
| 74 | + } |
| 75 | + |
| 76 | + [Fact] |
| 77 | + public void EqualityOperatorIsImplementedCorrectly() |
| 78 | + { |
| 79 | + Assert.True(siBaseUnits == siBaseUnitsCopy); |
| 80 | + Assert.True(siBaseUnitsCopy == siBaseUnits); |
| 81 | + |
| 82 | + Assert.False(siBaseUnits == nonSiBaseUnits); |
| 83 | + Assert.False(nonSiBaseUnits == siBaseUnits); |
| 84 | + |
| 85 | + Assert.False(siBaseUnits == null); |
| 86 | + Assert.False(null == siBaseUnits); |
| 87 | + |
| 88 | + BaseUnits nullBaseUnits1 = null; |
| 89 | + BaseUnits nullBaseUnits2 = null; |
| 90 | + |
| 91 | + Assert.True(nullBaseUnits1 == nullBaseUnits2); |
| 92 | + } |
| 93 | + |
| 94 | + [Fact] |
| 95 | + public void InequalityOperatorIsImplementedCorrectly() |
| 96 | + { |
| 97 | + Assert.False(siBaseUnits != siBaseUnitsCopy); |
| 98 | + Assert.False(siBaseUnitsCopy != siBaseUnits); |
| 99 | + |
| 100 | + Assert.True(siBaseUnits != nonSiBaseUnits); |
| 101 | + Assert.True(nonSiBaseUnits != siBaseUnits); |
| 102 | + |
| 103 | + Assert.True(siBaseUnits != null); |
| 104 | + Assert.True(null != siBaseUnits); |
| 105 | + |
| 106 | + BaseUnits nullBaseUnits1 = null; |
| 107 | + BaseUnits nullBaseUnits2 = null; |
| 108 | + |
| 109 | + Assert.False(nullBaseUnits1 != nullBaseUnits2); |
| 110 | + } |
| 111 | + |
| 112 | + [Fact] |
| 113 | + public void ToStringGivesExpectedResult() |
| 114 | + { |
| 115 | + var siBaseUnits = new BaseUnits(LengthUnit.Meter, MassUnit.Kilogram, DurationUnit.Second, |
| 116 | + ElectricCurrentUnit.Ampere, TemperatureUnit.Kelvin, AmountOfSubstanceUnit.Mole, LuminousIntensityUnit.Candela); |
| 117 | + |
| 118 | + Assert.Equal("[Length]: m, [Mass]: kg, [Time]: s, [Current]: A, [Temperature]: K, [Amount]: mol, [LuminousIntensity]: cd", siBaseUnits.ToString()); |
| 119 | + } |
| 120 | + } |
| 121 | +} |
0 commit comments