예제 #1
0
        public void GramsPerCubicMetre()
        {
            var settings   = MockSettings.Create();
            var gramPart   = PartConversion.CreatePart(1, settings.Grams);
            var volumePart = PartConversion.CreatePart(-1, settings.CubicMetres);
            var conversion = PartConversion.Create(settings.KilogramsPerCubicMetre, gramPart, volumePart);

            Assert.AreEqual("g/m³", conversion.Symbol);
            Assert.AreEqual("GramsPerCubicMetre", conversion.Name);
            Assert.AreEqual(1E-3, conversion.Factor);
        }
예제 #2
0
 public void PartConversionIdentity()
 {
     var settings = MockSettings.Create();
     var metresPart = PartConversion.CreatePart(1, settings.Metres);
     var secondsPart = PartConversion.CreatePart(-1, settings.Seconds);
     var conversion = PartConversion.Create(settings.MetresPerSecond, metresPart, secondsPart);
     settings.MetresPerSecond.PartConversions.Add(conversion);
     Assert.AreEqual("metresPerSecond", conversion.ToSi);
     Assert.AreEqual("metresPerSecond", conversion.FromSi);
     Assert.AreEqual("1 m/s = 1 m/s", conversion.SymbolConversion);
     Assert.AreEqual(true, conversion.CanRoundtrip);
 }
예제 #3
0
        public async Task MetresPerSecondCubed()
        {
            var settings   = MockSettings.Create();
            var metrePart  = PartConversion.CreatePart(1, settings.Metres);
            var secondPart = PartConversion.CreatePart(-2, settings.Seconds);
            var conversion = PartConversion.Create(settings.MetresPerSecondSquared, metrePart, secondPart);

            Assert.AreEqual("m/s²", conversion.Symbol);
            Assert.AreEqual("MetresPerSecondSquared", conversion.Name);
            Assert.AreEqual(1, conversion.Factor);
            Assert.AreEqual(true, await conversion.CanRoundtripAsync().ConfigureAwait(false));
        }
예제 #4
0
        public void MetresPerSecondCubed()
        {
            var settings   = MockSettings.Create();
            var metrePart  = PartConversion.CreatePart(1, settings.Metres);
            var secondPart = PartConversion.CreatePart(-2, settings.Seconds);
            var conversion = PartConversion.Create(settings.MetresPerSecondSquared, metrePart, secondPart);

            Assert.AreEqual("m/s²", conversion.Symbol);
            Assert.AreEqual("MetresPerSecondSquared", conversion.Name);
            Assert.AreEqual(1, conversion.Factor);
            Assert.AreEqual(true, conversion.CanRoundtrip);
        }
예제 #5
0
        public void SquareMillimetres()
        {
            var settings    = MockSettings.Create();
            var millimetres = PrefixConversion.Create(settings.Metres, settings.Milli);

            settings.Metres.PrefixConversions.Add(millimetres);
            var millimetrePart = PartConversion.CreatePart(2, millimetres);
            var conversion     = PartConversion.Create(settings.Metres, millimetrePart);

            Assert.AreEqual("mm²", conversion.Symbol);
            Assert.AreEqual("SquareMillimetres", conversion.Name);
            Assert.AreEqual(1E-6, conversion.Factor);
        }
예제 #6
0
        public async Task PartConversionIdentity()
        {
            var settings    = MockSettings.Create();
            var metresPart  = PartConversion.CreatePart(1, settings.Metres);
            var secondsPart = PartConversion.CreatePart(-1, settings.Seconds);
            var conversion  = PartConversion.Create(settings.MetresPerSecond, metresPart, secondsPart);

            settings.MetresPerSecond.PartConversions.Add(conversion);
            Assert.AreEqual("metresPerSecond", conversion.ToSi);
            Assert.AreEqual("metresPerSecond", conversion.FromSi);
            Assert.AreEqual("1 m/s = 1 m/s", await conversion.GetSymbolConversionAsync().ConfigureAwait(false));
            Assert.AreEqual(true, await conversion.CanRoundtripAsync().ConfigureAwait(false));
        }
예제 #7
0
 public void PartConversionPrefix()
 {
     var settings = MockSettings.Create();
     var millimetreConversion = PrefixConversion.Create(settings.Metres, settings.Milli);
     settings.Metres.PrefixConversions.Add(millimetreConversion);
     var milliMetresPart = PartConversion.CreatePart(1, millimetreConversion);
     var secondsPart = PartConversion.CreatePart(-1, settings.Seconds);
     var conversion = PartConversion.Create(settings.MetresPerSecond, milliMetresPart, secondsPart);
     settings.MetresPerSecond.PartConversions.Add(conversion);
     Assert.AreEqual("millimetresPerSecond/1000", conversion.ToSi);
     Assert.AreEqual("1000*metresPerSecond", conversion.FromSi);
     Assert.AreEqual("1 mm/s = 0.001 m/s", conversion.SymbolConversion);
     Assert.AreEqual(true, conversion.CanRoundtrip);
 }
예제 #8
0
        public void MilliGramsPerCubicMetre()
        {
            var settings  = MockSettings.Create();
            var milligram = PrefixConversion.Create(settings.Grams, settings.Milli);

            settings.Grams.PrefixConversions.Add(milligram);
            var milliGramPart = PartConversion.CreatePart(1, milligram);
            var volumePart    = PartConversion.CreatePart(-1, settings.CubicMetres);
            var conversion    = PartConversion.Create(settings.Kilograms, milliGramPart, volumePart);

            Assert.AreEqual("mg/m³", conversion.Symbol);
            Assert.AreEqual("MilligramsPerCubicMetre", conversion.Name);
            Assert.AreEqual(1E-6, conversion.Factor);
        }
예제 #9
0
        public static void SetUnitToCubicMetres()
        {
            using var settings = MockSettings.Create();
            using var vm       = new PartConversionsVm();
            vm.SetUnit(settings.CubicMetres);
            var metresPart       = new PowerPart(3, new IdentityConversion(settings.Metres));
            var metresConversion = PartConversion.Create(settings.CubicMetres, metresPart);
            var expected         = new[]
            {
                new PartConversionVm(settings.CubicMetres, metresConversion),
            };

            Assert.AreEqual(expected[0].Conversion.Name, vm.Conversions.Single().Single().Conversion.Name);
        }
예제 #10
0
        public void CubicMillimetres()
        {
            var settings    = MockSettings.Create();
            var millimetres = PrefixConversion.Create(settings.Metres, settings.Milli);

            settings.Metres.PrefixConversions.Add(millimetres);
            var conversion   = PartConversion.Create(settings.CubicMetres, new PartConversion.PowerPart(3, millimetres));
            var conversionVm = new PartConversionVm(settings.CubicMetres, conversion);

            Assert.AreEqual(1E-9, conversionVm.Conversion.Factor);
            Assert.AreEqual("cubicMillimetres/1000000000", conversionVm.Conversion.ToSi);
            Assert.AreEqual("1000000000*cubicMetres", conversionVm.Conversion.FromSi);
            Assert.AreEqual("1 mm³ = 1E-09 m³", conversionVm.Conversion.SymbolConversion);
            Assert.AreEqual(true, conversionVm.Conversion.CanRoundtrip);
        }
예제 #11
0
        public void IsUsed()
        {
            var settings    = MockSettings.Create();
            var millimetres = PrefixConversion.Create(settings.Metres, settings.Milli);

            settings.Metres.PrefixConversions.Add(millimetres);
            var conversion   = PartConversion.Create(settings.CubicMetres, new PartConversion.PowerPart(3, millimetres));
            var conversionVm = new PartConversionVm(settings.CubicMetres, conversion);

            conversionVm.IsUsed = true;
            CollectionAssert.Contains(settings.CubicMetres.PartConversions, conversion);

            conversionVm.IsUsed = false;
            CollectionAssert.DoesNotContain(settings.CubicMetres.PartConversions, conversion);
        }
예제 #12
0
        public static async Task CubicMillimetresAsync()
        {
            using var settings = MockSettings.Create();
            var millimetres = PrefixConversion.Create(settings.Metres, settings.Milli);

            settings.Metres.PrefixConversions.Add(millimetres);
            var conversion = PartConversion.Create(settings.CubicMetres, new PowerPart(3, millimetres));

            using var conversionVm = new PartConversionVm(settings.CubicMetres, conversion);
            Assert.AreEqual(1E-9, ((PartConversion)conversionVm.Conversion).Factor);
            Assert.AreEqual("cubicMillimetres / 1000000000", conversionVm.Conversion.ToSi);
            Assert.AreEqual("1000000000 * cubicMetres", conversionVm.Conversion.FromSi);
            Assert.AreEqual("1 mm³ = 1E-09 m³", await conversionVm.Conversion.GetSymbolConversionAsync().ConfigureAwait(false));
            Assert.AreEqual(true, await conversionVm.Conversion.CanRoundtripAsync().ConfigureAwait(false));
        }
예제 #13
0
        public static async Task MilliMetresPerSecondCubed()
        {
            using var settings = MockSettings.Create();
            var millimetres = PrefixConversion.Create(settings.Metres, settings.Milli);

            settings.Metres.PrefixConversions.Add(millimetres);
            var metrePart  = PartConversion.CreatePart(1, millimetres);
            var secondPart = PartConversion.CreatePart(-2, settings.Seconds);
            var conversion = PartConversion.Create(settings.MetresPerSecondSquared, metrePart, secondPart);

            Assert.AreEqual("mm/s²", conversion.Symbol);
            Assert.AreEqual("MillimetresPerSecondSquared", conversion.Name);
            Assert.AreEqual(0.001, conversion.Factor);
            Assert.AreEqual(true, await conversion.CanRoundtripAsync().ConfigureAwait(false));
        }
예제 #14
0
        public void MilliMetresPerSecondCubed()
        {
            var settings    = MockSettings.Create();
            var millimetres = PrefixConversion.Create(settings.Metres, settings.Milli);

            settings.Metres.PrefixConversions.Add(millimetres);
            var metrePart  = PartConversion.CreatePart(1, millimetres);
            var secondPart = PartConversion.CreatePart(-2, settings.Seconds);
            var conversion = PartConversion.Create(settings.MetresPerSecondSquared, metrePart, secondPart);

            Assert.AreEqual("mm/s²", conversion.Symbol);
            Assert.AreEqual("MillimetresPerSecondSquared", conversion.Name);
            Assert.AreEqual(0.001, conversion.Factor);
            Assert.AreEqual(true, conversion.CanRoundtrip);
        }
예제 #15
0
        public async Task PartConversionPrefix()
        {
            var settings             = MockSettings.Create();
            var millimetreConversion = PrefixConversion.Create(settings.Metres, settings.Milli);

            settings.Metres.PrefixConversions.Add(millimetreConversion);
            var milliMetresPart = PartConversion.CreatePart(1, millimetreConversion);
            var secondsPart     = PartConversion.CreatePart(-1, settings.Seconds);
            var conversion      = PartConversion.Create(settings.MetresPerSecond, milliMetresPart, secondsPart);

            settings.MetresPerSecond.PartConversions.Add(conversion);
            Assert.AreEqual("millimetresPerSecond / 1000", conversion.ToSi);
            Assert.AreEqual("1000 * metresPerSecond", conversion.FromSi);
            Assert.AreEqual("1 mm/s = 0.001 m/s", await conversion.GetSymbolConversionAsync().ConfigureAwait(false));
            Assert.AreEqual(true, await conversion.CanRoundtripAsync().ConfigureAwait(false));
        }
예제 #16
0
 public void CentimetresPerMinute()
 {
     var settings = MockSettings.Create();
     var centi = new Prefix("Centi", "c", -2);
     settings.Prefixes.Add(centi);
     var centimetresConversion = PrefixConversion.Create(settings.Metres, centi);
     var minuteConversion = new FactorConversion("Minute", "min", 60);
     settings.Seconds.FactorConversions.Add(minuteConversion);
     settings.Metres.PrefixConversions.Add(centimetresConversion);
     var centiMetresPart = PartConversion.CreatePart(1, centimetresConversion);
     var minutesPart = PartConversion.CreatePart(-1, minuteConversion);
     var conversion = PartConversion.Create(settings.MetresPerSecond, centiMetresPart, minutesPart);
     settings.MetresPerSecond.PartConversions.Add(conversion);
     Assert.AreEqual("centimetresPerMinute/6000", conversion.ToSi);
     Assert.AreEqual("6000*metresPerSecond", conversion.FromSi);
     Assert.AreEqual("1 cm/min = 0.000166666666666667 m/s", conversion.SymbolConversion);
     Assert.AreEqual(true, conversion.CanRoundtrip);
 }