Пример #1
0
        public void EqualsBaseUnitSystem_ConstructedFromDefaultSIUnits_ReturnsTrue()
        {
            var derivedSystem = new BaseUnitSystem(SI.GetDefaultSystemUnits());

            Assert.Equal(UnitSystem.SI.BaseUnits, derivedSystem.BaseUnits);
            Assert.Equal(UnitSystem.SI, derivedSystem);
        }
Пример #2
0
        public void WithDefaultUnit_GivenBaseUnitsAssociationsNotFullyDefined_ThrowsArgumentException(QuantityType baseType)
        {
            BaseUnitSystem unitSystem = UnitSystem.SI;

            // exception thrown from the BaseUnitSystem constructor
            Assert.Throws <ArgumentException>(() => unitSystem.WithDefaultUnit(baseType, null));
        }
Пример #3
0
        public void InequalityOperatorIsImplementedCorrectly()
        {
            var unitSystem1 = new BaseUnitSystem(new BaseUnits(LengthUnit.Meter, MassUnit.Kilogram, DurationUnit.Second,
                                                               ElectricCurrentUnit.Ampere, TemperatureUnit.Kelvin, AmountOfSubstanceUnit.Mole, LuminousIntensityUnit.Candela));

            var unitSystem2 = new BaseUnitSystem(new BaseUnits(LengthUnit.Meter, MassUnit.Kilogram, DurationUnit.Second,
                                                               ElectricCurrentUnit.Ampere, TemperatureUnit.Kelvin, AmountOfSubstanceUnit.Mole, LuminousIntensityUnit.Candela));

            var unitSystem3 = new BaseUnitSystem(new BaseUnits(LengthUnit.Foot, MassUnit.Pound, DurationUnit.Second,
                                                               ElectricCurrentUnit.Ampere, TemperatureUnit.DegreeFahrenheit, AmountOfSubstanceUnit.Mole, LuminousIntensityUnit.Candela));

            Assert.False(unitSystem1 != unitSystem2);
            Assert.False(unitSystem2 != unitSystem1);

            Assert.True(unitSystem1 != unitSystem3);
            Assert.True(unitSystem3 != unitSystem1);

            Assert.True(unitSystem1 != null);
            Assert.True(null != unitSystem1);

            BaseUnitSystem nullUnitSystem1 = null;
            BaseUnitSystem nullUnitSystem2 = null;

            Assert.False(nullUnitSystem1 != nullUnitSystem2);
        }
Пример #4
0
        public void ConstructorImplementedProperly()
        {
            var baseUnits = new BaseUnits(LengthUnit.Meter, MassUnit.Kilogram, DurationUnit.Second,
                                          ElectricCurrentUnit.Ampere, TemperatureUnit.Kelvin, AmountOfSubstanceUnit.Mole, LuminousIntensityUnit.Candela);

            var unitSystem = new BaseUnitSystem(baseUnits);

            Assert.Equal(unitSystem.BaseUnits, baseUnits);
        }
Пример #5
0
        public void GetDefaultUnitInfo_FromBaseUnitSystem_ReturnsBaseUnitSystem()
        {
            var            anyUnitInfo = Length.Info.UnitInfos.First();
            BaseUnitSystem unitSystem  = UnitSystem.SI;

            // default overload: same as SI.WithDefaultUnit(..)
            var derivedSystem = unitSystem.WithDefaultUnit(QuantityType.Length, anyUnitInfo);

            Assert.IsType <BaseUnitSystem>(derivedSystem);
        }
Пример #6
0
        public void EqualsObjectIsImplementedCorrectly()
        {
            var unitSystem1 = new BaseUnitSystem(new BaseUnits(LengthUnit.Meter, MassUnit.Kilogram, DurationUnit.Second,
                                                               ElectricCurrentUnit.Ampere, TemperatureUnit.Kelvin, AmountOfSubstanceUnit.Mole, LuminousIntensityUnit.Candela));

            var unitSystem2 = new BaseUnitSystem(new BaseUnits(LengthUnit.Meter, MassUnit.Kilogram, DurationUnit.Second,
                                                               ElectricCurrentUnit.Ampere, TemperatureUnit.Kelvin, AmountOfSubstanceUnit.Mole, LuminousIntensityUnit.Candela));

            var unitSystem3 = new BaseUnitSystem(new BaseUnits(LengthUnit.Foot, MassUnit.Pound, DurationUnit.Second,
                                                               ElectricCurrentUnit.Ampere, TemperatureUnit.DegreeFahrenheit, AmountOfSubstanceUnit.Mole, LuminousIntensityUnit.Candela));

            Assert.True(unitSystem1.Equals((object)unitSystem2));
            Assert.False(unitSystem1.Equals((object)unitSystem3));

            // ReSharper disable once SuspiciousTypeConversion.Global
            Assert.False(unitSystem1.Equals("Some object."));
            Assert.False(unitSystem1.Equals((IFormatProvider)null));
        }