public void GetNotationWithoutPrefix_Then_ResultShouldBeExpected(string notation, string expected) { var testee = new DerivedUnit(notation, CentiMeterUnitExpression * CentiMeterUnitExpression); var result = testee.GetNotationWithoutPrefix(); result.Should().Be(expected); }
/// <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); }
/// <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); }
/// <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); }
public void CompositeUnitMultiplication_When_PrefixesAreDifferent_Then_NotationShouldBeLhsPrefixTimesRhsPrefix() { var testee = new DerivedUnit(null, MeterUnit * CentiMeterUnitExpression); testee.ToString().Should().Be("m*cm"); }
public void CompositeUnitDivision_When_PrefixesAreDifferent_Then_NotationShouldBeRhsPrefixSquared() { var testee = new DerivedUnit(null, MeterUnit / CentiMeterUnitExpression); testee.ToString().Should().Be("m/cm"); }