Beispiel #1
0
        public void ToResultExpression_When_UnitHasExponent_Then_ResultShouldBeExpected()
        {
            var testee = new FlatUnit("s", exponent: 2).GetFlatIdentifierRepresentation();

            var result = testee.ToResultingExpression();

            result.ToString().Should().Be("s²");
        }
Beispiel #2
0
        public void ToResultExpression_When_SingleUnitRaisedInMinusOne_Then_ResultShouldBeSingleUnit()
        {
            var testee = new FlatUnit("s", -1).GetFlatIdentifierRepresentation();

            var result = testee.ToResultingExpression();

            result.ToString().Should().Be("s");
        }
        public void GetResultingExpression_When_UnitReducedByBaseUnitAndDerivedUnitIsAddedFirst_Then_ResultShouldBeBaseUnitExpression()
        {
            var flatRepresentation = FlatUnit.CreateFlatRepresentation(new FlatUnit("min", "s"));
            var testee = flatRepresentation.GetConsumer();

            var result = testee.GetResultingExpression(new UnitExpression(new Unit("s")), true);

            result.Should().BeOfType<UnitExpression>().Which.Unit.Notation.Should().Be("min");
        }
        public void GetResultingExpression_When_UnitIsNotFound_Then_ResultShouldBeNull()
        {
            var flatRepresentation = FlatUnit.CreateFlatRepresentation(new FlatUnit("s"));
            var testee = flatRepresentation.GetConsumer();

            var result = testee.GetResultingExpression(new UnitExpression(new Unit("m")), false);

            result.Should().BeNull();
        }
Beispiel #5
0
        public void Build_When_MultipleVariablesHavesBeenBeenAdded_Then_ExponentShouldBeAccumulated()
        {
            var expected = FlatUnit.CreateFlatRepresentation(new FlatVariable("var", 3));

            this.testee.Add(new VariableExpression("var"), 2);
            this.testee.Add(new VariableExpression("var"), 1);

            var result = this.testee.Build();

            result.Should().ContainInOrder(expected);
        }
Beispiel #6
0
        public void Build_When_MultipleConstantsHaveBeenBeenAdded_Then_ExponentShouldBeMultipled()
        {
            var expected = FlatUnit.CreateFlatRepresentation(new FlatConstant(16, 1));

            this.testee.Add(new ConstantExpression(2), 2);
            this.testee.Add(new ConstantExpression(4), 1);

            var result = this.testee.Build();

            result.Should().ContainInOrder(expected);
        }
        public void GetResultingExpression_When_BaseUnitIsAddedFirst_Then_ResultShouldBeNull()
        {
            var flatRepresentation = FlatUnit.CreateFlatRepresentation(new FlatUnit("s"));
            var testee = flatRepresentation.GetConsumer();

            var result =
                testee.GetResultingExpression(
                    new UnitExpression(new FactoredUnit(60, "min", new UnitExpression(new Unit("s")))),
                    false);

            result.Should().BeNull();
        }
        public void GetResultingExpression_When_ExponentIsLargerThanOne_Then_ResultShouldContainMagnitudeExpression(
            double exponent)
        {
            var flatRepresentation = FlatUnit.CreateFlatRepresentation(new FlatUnit("s", exponent: exponent));
            var testee = flatRepresentation.GetConsumer();

            var result = testee.GetResultingExpression(new UnitExpression(new Unit("s")), false);

            var magnitudeAssertion = result.Should().BeOfType<MagnitudeExpression>();
            magnitudeAssertion.Which.Rhs.Constant.Should().Be(exponent);
            magnitudeAssertion.Which.Lhs.ToString().Should().Be("s");
        }
        public void ToString_Then_ResultShouldBeExpectedNotation()
        {
            const string ExpectedNotation = "m¹*h⁻¹*s⁻¹";
            var          testee           = FlatUnit.CreateFlatRepresentation(
                new FlatUnit("m"),
                new FlatUnit("h", -1),
                new FlatUnit("s", -1));

            var result = testee.ToString();

            result.Should().Be(ExpectedNotation);
        }
Beispiel #10
0
        public void Build_When_ConstantHasBeAdded_Then_ResultShouldContainVariableWithExponent(
            double constant,
            double exponent)
        {
            var expected = FlatUnit.CreateFlatRepresentation(new FlatConstant(constant, exponent));

            this.testee.Add(new ConstantExpression(constant), exponent);

            var result = this.testee.Build();

            result.Should().ContainInOrder(expected);
        }
Beispiel #11
0
        public void Build_When_VariableHasBeAdded_Then_ResultShouldContainVariableWithExponent(
            string variable,
            double exponent)
        {
            var expected = FlatUnit.CreateFlatRepresentation(new FlatVariable(variable, exponent));

            this.testee.Add(new VariableExpression(variable), exponent);

            var result = this.testee.Build();

            result.Should().ContainInOrder(expected);
        }
        public void Equals_Then_ResultShouldBeExpected(
            string unit,
            double unitExponent,
            string other,
            double otherExponent,
            bool expected)
        {
            var testee = FlatUnit.CreateFlatRepresentation(new FlatUnit(unit, unitExponent));
            var rhs    = FlatUnit.CreateFlatRepresentation(new FlatUnit(other, otherExponent));

            var result = testee.Equals(rhs);

            result.Should().Be(expected);
        }
        public void GetHashcode_Then_ResultShouldBeSameAsOtherResult(
            string unit,
            double unitExponent,
            string other,
            double otherExponent,
            bool expected)
        {
            var testee = FlatUnit.CreateFlatRepresentation(new FlatUnit(unit, unitExponent));
            var rhs    = FlatUnit.CreateFlatRepresentation(new FlatUnit(other, otherExponent));

            var result      = testee.GetHashCode();
            var otherResult = rhs.GetHashCode();

            result.Equals(otherResult).Should().Be(expected);
        }