Beispiel #1
0
        public void EmptyStringResultsInUnitlessValue()
        {
            var actual = CompoundUnitParser.Parse(1d, string.Empty);

            Assert.That(actual.Unit, Is.EqualTo(new CompoundUnit()));
            Assert.That(actual.Value, Is.EqualTo(1));
        }
Beispiel #2
0
        public void CompoundUnitIsCorrectlyParsed(string unitString, IUnitDefinition expectedUnit)
        {
            var expected = expectedUnit.CorrespondingCompoundUnit;
            var actual   = CompoundUnitParser.Parse(1d, unitString);

            Assert.That(actual.Unit, Is.EqualTo(expected));
        }
Beispiel #3
0
        public void CanParseComplexUnit2()
        {
            var unitString = "mg mM/(L ms^2)";
            var actual     = CompoundUnitParser.Parse(1d, unitString);
            var expected   = 1e-3.To(Unit.Gram) * 1e-3.To(Unit.Molar) / (1.To(Unit.Liter) * 1e-6.To(Unit.Second) * 1.To(Unit.Second));

            Assert.That(actual.Unit, Is.EqualTo(expected.Unit));
            Assert.That(actual.Value, Is.EqualTo(expected.Value).Within(1e-3 * expected.Value));
        }
Beispiel #4
0
        public void CanParseComplexUnit1()
        {
            var unitString = "mm^3/us";
            var actual     = CompoundUnitParser.Parse(1d, unitString);
            var expected   = 1e-9.To(Unit.CubicMeters) / 1e-6.To(Unit.Second);

            Assert.That(actual.Unit, Is.EqualTo(expected.Unit));
            Assert.That(actual.Value, Is.EqualTo(expected.Value).Within(1e-3 * expected.Value));
        }
Beispiel #5
0
        public void CanParseSimpleUnits()
        {
            var units = Unit.Effective.AllUnits;

            foreach (var unit in units)
            {
                var unitString = unit.StringRepresentation;
                var actual     = CompoundUnitParser.Parse(1d, unitString);
                Assert.That(actual.Unit, Is.EqualTo(unit.CorrespondingCompoundUnit));
            }
        }
Beispiel #6
0
        public void PrefixResultsInExpectedMultiplier(string str, double expectedMultiplier)
        {
            var actual = CompoundUnitParser.Parse(1d, str);

            Assert.That(actual.Value, Is.EqualTo(expectedMultiplier).Within(1e-3 * expectedMultiplier));
        }
Beispiel #7
0
        public void UnitWithNumbersIsRejected()
        {
            var unitString = "µL/200mL";

            Assert.That(() => CompoundUnitParser.Parse(1d, unitString), Throws.TypeOf <FormatException>());
        }