Пример #1
0
        public void GetNotationWithoutPrefix_Then_ResultShouldBeExpected(string notation, string expected)
        {
            var testee = new DerivedUnit(notation, CentiMeterUnitExpression * CentiMeterUnitExpression);

            var result = testee.GetNotationWithoutPrefix();

            result.Should().Be(expected);
        }
Пример #2
0
 /// <summary>
 /// Registers the unit.
 /// </summary>
 /// <param name="derivedUnit">
 /// The unit to be registered.
 /// </param>
 public void Register(DerivedUnit derivedUnit)
 {
     var derivedNotation = derivedUnit.Notation;
     this.unitDefinitions.Add(derivedNotation, derivedUnit);
     var expression = derivedUnit.GetBaseExpression();
     var flatRepresentation = this.expressionToFlatRepresentationConverter.Convert(
         expression,
         false,
         new FlatRepresentationBuilder());
     this.derivedUnits.Add(flatRepresentation, derivedUnit);
 }
Пример #3
0
 /// <summary>
 /// Tries to get the unit.
 /// </summary>
 /// <param name="flatRepresentation">The flat representation.</param>
 /// <param name="derivedUnit">The found derived unit.</param>
 /// <returns>
 ///   <c>true</c> if the flat representation is found, otherwise <c>false</c>
 /// </returns>
 public bool TryGetUnit(FlatRepresentation flatRepresentation, out DerivedUnit derivedUnit)
 {
     return this.derivedUnits.TryGetValue(flatRepresentation, out derivedUnit);
 }
Пример #4
0
        /// <summary>
        /// Unregisters the unit.
        /// </summary>
        /// <param name="derivedUnit">
        /// The unit to be unregistered.
        /// </param>
        public void Unregister(DerivedUnit derivedUnit)
        {
            this.unitDefinitions.Remove(derivedUnit.Notation);

            var baseExpression = derivedUnit.GetBaseExpression();
            var flatRepresentation = this.expressionToFlatRepresentationConverter.Convert(
                baseExpression,
                false,
                new FlatRepresentationBuilder());
            this.derivedUnits.Remove(flatRepresentation);
        }
Пример #5
0
        public void CompositeUnitMultiplication_When_PrefixesAreDifferent_Then_NotationShouldBeLhsPrefixTimesRhsPrefix()
        {
            var testee = new DerivedUnit(null, MeterUnit * CentiMeterUnitExpression);

            testee.ToString().Should().Be("m*cm");
        }
Пример #6
0
        public void CompositeUnitDivision_When_PrefixesAreDifferent_Then_NotationShouldBeRhsPrefixSquared()
        {
            var testee = new DerivedUnit(null, MeterUnit / CentiMeterUnitExpression);

            testee.ToString().Should().Be("m/cm");
        }