private static IReadOnlyCollection <ContextWithCastByPower> BuildContexts()
        {
            var builder = new ContextWithCastByPowerBuilder(10);

            var namespaces = new UnitNamespaces(Resource.NamespaceByte1000);

            builder.Add(24, namespaces + new UnitDefinition("yottabyte", "YB", "Represents a Yottabyte (symbol YB).\nIt is a multiple of the unit <c>Byte</c>, where:\n- 1 Yottabyte = 1,000 Zettabytes\n- 1 Yottabyte = 10^24 Bytes"));
            builder.Add(21, namespaces + new UnitDefinition("zettabyte", "ZB", "Represents a Zettabyte (symbol ZB).\nIt is a multiple of the unit <c>Byte</c>, where:\n- 1 Zettabyte = 1,000 Exabytes\n- 1 Zettabyte = 10^21 Bytes"));
            builder.Add(18, namespaces + new UnitDefinition("exabyte", "EB", "Represents a Exabyte (symbol EB).\nIt is a multiple of the unit <c>Byte</c>, where:\n- 1 Exabyte = 1,000 Petabytes\n- 1 Exabyte = 10^18 Bytes"));
            builder.Add(15, namespaces + new UnitDefinition("petabyte", "PB", "Represents a Petabyte (symbol PB).\n It is a multiple of the unit <c>Byte</c>, where:\n- 1 Petabyte = 1,000 Terabytes\n- 1 Petabyte = 10^15 Bytes"));
            builder.Add(12, namespaces + new UnitDefinition("terabyte", "TB", "Represents a Terabyte (symbol TB).\n It is a multiple of the unit <c>Byte</c>, where:\n- 1 Terabyte = 1,000 Gigabytes\n- 1 Terabyte = 10^12 Bytes"));
            builder.Add(09, namespaces + new UnitDefinition("gigabyte", "GB", "Represents a Gigabyte (symbol GB).\n It is a multiple of the unit <c>Byte</c>, where:\n- 1 Gigabyte = 1,000 Megabytes\n- 1 Gigabyte = 10^9 Bytes"));
            builder.Add(06, namespaces + new UnitDefinition("megabyte", "MB", "Represents a Megabyte (symbol MB).\n It is a multiple of the unit <c>Byte</c>, where:\n- 1 Megabyte = 1,000 Kilobytes\n- 1 Megabyte = 10^6 Bytes"));
            builder.Add(03, namespaces + new UnitDefinition("kilobyte", "kB", "Represents a Kilobyte (symbol kB).\n It is a multiple of the unit <c>Byte</c>, where:\n- 1 Kilobyte = 1,000 Bytes\n-  1 Kilobyte = 10^3 Bytes"));
            builder.Add(00, namespaces + new UnitDefinition("byte", "B", "Represents a Byte (symbol B).\nWhere:\n- 1 Byte = 8 Bits"));

            builder.TestCases = new[]
            {
                //           Ym,      Zm,      Em,      Pm,      Tm,     Gm,     Mm,     km,      m
                //       10e+24,  10e+21,  10e+18,  10e+15,  10e+12,  10e+9,  10e+6,  10e+3,   10e0
                new[] { 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d },
                new[] { 13.7e24, 13.7e21, 13.7e18, 13.7e15, 13.7e12, 13.7e9, 13.7e6, 13.7e3, 13.7e0 },
                new[] { -5e24, -5e21, -5e18, -5e15, -5e12, -5e9, -5e6, -5e3, -5e0 },
                new[] { 1e0, 1e-3, 1e-6, 1e-9, 1e-12, 1e-15, 1e-18, 1e-21, 1e-24 },
            };

            return(builder.Build());
        }
        private static IReadOnlyCollection <ContextWithCastByPower> BuildContexts()
        {
            var builder = new ContextWithCastByPowerBuilder(2);

            var namespaces = new UnitNamespaces(Resource.NamespaceByte1024);

            builder.Add(80, namespaces + new UnitDefinition("yobibyte", "YiB", "Represents a Yobibyte (symbol YiB).\nIt is a multiple of the unit <c>Byte</c>, where:\n- 1 Yobibyte = 1,024 Zebibytes\n- 1 Yobibyte = 1024^8 or 2^80 Bytes"));
            builder.Add(70, namespaces + new UnitDefinition("zebibyte", "ZiB", "Represents a Zebibyte (symbol ZiB).\nIt is a multiple of the unit <c>Byte</c>, where:\n- 1 Zebibyte = 1,024 Exbibytes\n- 1 Zebibyte = 1024^7 or 2^70 Bytes"));
            builder.Add(60, namespaces + new UnitDefinition("exbibyte", "EiB", "Represents a Exbibyte (symbol EiB).\nIt is a multiple of the unit <c>Byte</c>, where:\n- 1 Exbibyte = 1,024 Pebibytes\n- 1 Exbibyte = 1024^6 or 2^60 Bytes"));
            builder.Add(50, namespaces + new UnitDefinition("pebibyte", "PiB", "Represents a Pebibyte (symbol PiB).\nIt is a multiple of the unit <c>Byte</c>, where:\n- 1 Pebibyte = 1,024 Tebibytes\n- 1 Pebibyte = 1024^5 or 2^50 Bytes"));
            builder.Add(40, namespaces + new UnitDefinition("tebibyte", "TiB", "Represents a Tebibyte (symbol TiB).\nIt is a multiple of the unit <c>Byte</c>, where:\n- 1 Tebibyte = 1,024 Gibibytes\n- 1 Tebibyte = 1024^4 or 2^40 Bytes"));
            builder.Add(30, namespaces + new UnitDefinition("gibibyte", "GiB", "Represents a Gibibyte (symbol GiB).\nIt is a multiple of the unit <c>Byte</c>, where:\n- 1 Gibibyte = 1,024 Mebibytes\n- 1 Gibibyte = 1024^3 or 2^30 Bytes"));
            builder.Add(20, namespaces + new UnitDefinition("mebibyte", "MiB", "Represents a Mebibyte (symbol MiB).\nIt is a multiple of the unit <c>Byte</c>, where:\n- 1 Mebibyte = 1,024 Kibibytes\n- 1 Mebibyte = 1024^2 or 2^20 Bytes"));
            builder.Add(10, namespaces + new UnitDefinition("kibibyte", "KiB", "Represents a Kibibyte (symbol KiB).\nIt is a multiple of the unit <c>Byte</c>, where:\n- 1 Kibibyte = 1,024 bytes    \n- 1 Kibibyte = 1024^1 or 2^10 Bytes"));
            builder.Add(00, namespaces + new UnitDefinition("byte", "B", "Represents a Byte (symbol B).\nWhere:\n- 1 Byte = 8 Bits"));

            builder.TestCases = new[] {
                //                   yottabyte,              zettabyte,                exabyte,               petabyte,               terabyte,               gigabyte,               megabyte,               kilobyte,                  byte
                //                       2e+80,                  2e+70,                  2e+60,                  2e+50,                  2e+40,                  2e+30,                  2e+20,                  2e+10,                  2e+0
                new[] { 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d },
                new[] { Math.Pow(2, 80), Math.Pow(2, 70), Math.Pow(2, 60), Math.Pow(2, 50), Math.Pow(2, 40), Math.Pow(2, 30), Math.Pow(2, 20), Math.Pow(2, 10), Math.Pow(2, 00) },
                new[] { -5 * Math.Pow(2, 80), -5 * Math.Pow(2, 70), -5 * Math.Pow(2, 60), -5 * Math.Pow(2, 50), -5 * Math.Pow(2, 40), -5 * Math.Pow(2, 30), -5 * Math.Pow(2, 20), -5 * Math.Pow(2, 10), -5 * Math.Pow(2, 00) },
                new[] { 3 * Math.Pow(2, 00), 3 * Math.Pow(2, -10), 3 * Math.Pow(2, -20), 3 * Math.Pow(2, -30), 3 * Math.Pow(2, -40), 3 * Math.Pow(2, -50), 3 * Math.Pow(2, -60), 3 * Math.Pow(2, -70), 3 * Math.Pow(2, -80) },
                new[] { 13.7 * Math.Pow(2, 80), 13.7 * Math.Pow(2, 70), 13.7 * Math.Pow(2, 60), 13.7 * Math.Pow(2, 50), 13.7 * Math.Pow(2, 40), 13.7 * Math.Pow(2, 30), 13.7 * Math.Pow(2, 20), 13.7 * Math.Pow(2, 10), 13.7 * Math.Pow(2, 00) },
            };

            return(builder.Build());
        }
Esempio n. 3
0
        protected IReadOnlyCollection <ContextWithCastByPower> BuildContexts()
        {
            var builder = new ContextWithCastByPowerBuilder(10);

            var baseUnit   = GetBaseUnit();
            var baseSymbol = GetBaseSymbol();
            var namespaces = new UnitNamespaces(GetNamespace());

            builder.Add(+3, namespaces + new UnitDefinition($"kilo{baseUnit}", $"k{baseSymbol}"));
            builder.Add(+2, namespaces + new UnitDefinition($"hecto{baseUnit}", $"h{baseSymbol}"));
            builder.Add(+1, namespaces + new UnitDefinition($"deca{baseUnit}", $"da{baseSymbol}"));
            builder.Add(00, namespaces + new UnitDefinition($"{baseUnit}", $"{baseSymbol}"));
            builder.Add(-1, namespaces + new UnitDefinition($"deci{baseUnit}", $"d{baseSymbol}"));
            builder.Add(-2, namespaces + new UnitDefinition($"centi{baseUnit}", $"c{baseSymbol}"));
            builder.Add(-3, namespaces + new UnitDefinition($"milli{baseUnit}", $"m{baseSymbol}"));

            builder.TestCases = new[]
            {
                //          kX,     hX,    daX,      X,      dX,      cX,      mX
                //       10e+3,  10e+2,  10e+1,   10e0,   10e-1,   10e-2,   10e-3
                new[] { 0d, 0d, 0d, 0d, 0d, 0d, 0d },
                new[] { 13.7e3, 13.7e2, 13.7e1, 13.7e0, 13.7e-1, 13.7e-2, 13.7e-3 },
                new[] { -5e3, -5e2, -5e1, -5e0, -5e-1, -5e-2, -5e-3 },
                new[] { 1e0, 1e-1, 1e-2, 1e-3, 1e-4, 1e-5, 1e-6 },
                new[] { 2e6, 2e5, 2e4, 2e3, 2e2, 2e1, 2e0 },
            };

            return(builder.Build());
        }
        public IReadOnlyCollection <ContextWithCastByPower> BuildContexts()
        {
            var builder = new ContextWithCastByPowerBuilder(10);

            var namespaces = new UnitNamespaces(Resource.NamespaceCubicMetre);

            builder.Add(+9, namespaces + new UnitDefinition("cubic kilometre", "km³", "Represents a Cubic Kilometre (symbol km³).\nIt is a multiple of the unit <c>Cubic Metre</c>, where:\n- 1 Cubic Kilometre = 1,000 Cubic Hectometre\n- 1 Cubic Kilometre = 10^9 Cubic Metre"));
            builder.Add(+6, namespaces + new UnitDefinition("cubic hectometre", "hm³", "Represents a Cubic Hectometre (symbol hm³).\nIt is a multiple of the unit <c>Cubic Metre</c>, where:\n- 1 Cubic Hectometre = 1,000 Cubic Decametre\n- 1 Cubic Hectometre = 10^6 Cubic Metre"));
            builder.Add(+3, namespaces + new UnitDefinition("cubic decametre", "dam³", "Represents a Cubic Decametre (symbol dam³).\nIt is a multiple of the unit <c>Cubic Metre</c>, where:\n- 1 Cubic Decametre = 1,000 Cubic Metre\n- 1 Cubic Decametre = 10^3 Cubic Metre"));
            builder.Add(00, namespaces + new UnitDefinition("cubic metre", "m³"));
            builder.Add(-3, namespaces + new UnitDefinition("cubic decimetre", "dm³", "Represents a Cubic Decimetre (symbol dm³).\nIt is a multiple of the unit <c>Cubic Metre</c>, where:\n- 1,000 Cubic Decimetre = 1 Cubic Metre\n- 1 Cubic Decimetre = 10^-3 Cubic Metre"));
            builder.Add(-6, namespaces + new UnitDefinition("cubic centimetre", "cm³", "Represents a Cubic Centimetre (symbol cm³).\nIt is a multiple of the unit <c>Cubic Metre</c>, where:\n- 1,000 Cubic Centimetre = 1 Cubic Decimetre\n- 1 Cubic Centimetre = 10^-6 Cubic Metre"));
            builder.Add(-9, namespaces + new UnitDefinition("cubic millimetre", "mm³", "Represents a Cubic Millimetre (symbol mm³).\nIt is a multiple of the unit <c>Cubic Metre</c>, where:\n- 1,000 Cubic Millimetre = 1 Cubic Centimetre\n- 1 Cubic Millimetre = 10^-9 Cubic Metre"));

            builder.TestCases = new[]
            {
                //          km,     hm,    dam,      m,      dm,      cm,      mm
                //       10e+9,  10e+6,  10e+3,   10e0,   10e-3,   10e-6,   10e-9
                new[] { 0d, 0d, 0d, 0d, 0d, 0d, 0d },
                new[] { -5e9, -5e6, -5e3, -5e0, -5e-3, -5e-6, -5e-9 },
                new[] { 13.7e9, 13.7e6, 13.7e3, 13.7e0, 13.7e-3, 13.7e-6, 13.7e-9 },
                new[] { 1e0, 1e-3, 1e-6, 1e-9, 1e-12, 1e-15, 1e-18 },
                new[] { 1e18, 1e15, 1e12, 1e9, 1e6, 1e3, 1e0 }
            };

            return(builder.Build());
        }
Esempio n. 5
0
        public IContentFileBuilderCollection Generate()
        {
            var namespaces = new UnitNamespaces(Resource.NamespaceTemperature);

            var contexts = new[] {
                namespaces + new UnitDefinition("Kelvin", "K"),
                namespaces + new UnitDefinition("Celsius", "°C"),
                namespaces + new UnitDefinition("Fahrenheit", "°F")
            };

            return(new ClassesBuilder(contexts));
        }
Esempio n. 6
0
        private static IEnumerable <ContextWithCastByRatio> BuildContexts()
        {
            var namespaces = new UnitNamespaces(Resource.NamespaceAngle);

            var zeroTestCase = new CastRatioTestCase(0d, 0d, 0d);

            yield return(new ContextWithCastByRatio(
                             context: namespaces + new UnitDefinition("Radian", "rad"),
                             ratio: new CastRatio(1, "1", "RadianRatio"),
                             testCases: new[] {
                zeroTestCase,
                new CastRatioTestCase(Math.PI / 6, 1e3 * Math.PI / 6, 30d),
                new CastRatioTestCase(Math.PI / 4, 1e3 * Math.PI / 4, 45d),
                new CastRatioTestCase(Math.PI / 3, 1e3 * Math.PI / 3, 60d),
                new CastRatioTestCase(Math.PI / 2, 1e3 * Math.PI / 2, 90d),
                new CastRatioTestCase(Math.PI, 1e3 * Math.PI, 180d),
                new CastRatioTestCase(Math.PI * 3 / 2d, 1e3 * Math.PI * 3 / 2, 270d),
                new CastRatioTestCase(Math.PI * 2, 1e3 * Math.PI * 2, 360d),
                new CastRatioTestCase(-Math.PI, 1e3 * -Math.PI, -180d),
            }));

            yield return(new ContextWithCastByRatio(
                             context: namespaces + new UnitDefinition("Milliradian", "mrad"),
                             ratio: new CastRatio(1e-3, "0.001d", "RadianRatio"),
                             testCases: new[] {
                zeroTestCase,
                new CastRatioTestCase(1e3 * Math.PI / 6, Math.PI / 6, 30d),
                new CastRatioTestCase(1e3 * Math.PI / 4, Math.PI / 4, 45d),
                new CastRatioTestCase(1e3 * Math.PI / 3, Math.PI / 3, 60d),
                new CastRatioTestCase(1e3 * Math.PI / 2, Math.PI / 2, 90d),
                new CastRatioTestCase(1e3 * Math.PI, Math.PI, 180d),
                new CastRatioTestCase(1e3 * Math.PI * 3 / 2d, Math.PI * 3 / 2, 270d),
                new CastRatioTestCase(1e3 * Math.PI * 2, Math.PI * 2, 360d),
                new CastRatioTestCase(1e3 * -Math.PI, -Math.PI, -180d),
            }));

            yield return(new ContextWithCastByRatio(
                             context: namespaces + new UnitDefinition("Degree", "°"),
                             ratio: new CastRatio(Math.PI / 180d, "System.Math.PI / 180d", "RadianRatio"),
                             testCases: new[] {
                zeroTestCase,
                new CastRatioTestCase(30d, Math.PI / 6, 1e3 * Math.PI / 6),
                new CastRatioTestCase(45d, Math.PI / 4, 1e3 * Math.PI / 4),
                new CastRatioTestCase(60d, Math.PI / 3, 1e3 * Math.PI / 3),
                new CastRatioTestCase(90d, Math.PI / 2, 1e3 * Math.PI / 2),
                new CastRatioTestCase(180d, Math.PI, 1e3 * Math.PI),
                new CastRatioTestCase(270d, Math.PI * 3 / 2, 1e3 * Math.PI * 3 / 2),
                new CastRatioTestCase(360d, Math.PI * 2, 1e3 * Math.PI * 2),
                new CastRatioTestCase(-180d, -Math.PI, 1e3 * -Math.PI),
            }));
        }
        private static IEnumerable <ContextWithCastByRatio> BuildContexts()
        {
            var namespaces = new UnitNamespaces(Resource.NamespaceImperialLength);

            var zeroTestCase = new CastRatioTestCase(0d, 0d, 0d, 0d);

            yield return(new ContextWithCastByRatio(
                             context: namespaces + new UnitDefinition("inch", "in"),
                             ratio: new CastRatio(1d / 12, "1d / 12d", "FootRatio"),
                             testCases: new[]
            {
                zeroTestCase,
                new CastRatioTestCase(1d, 0.0833333d, 0.0277778d, 1.5783e-5d),
                new CastRatioTestCase(10d, 0.833333d, 0.277778d, 1.5783e-4d),
                new CastRatioTestCase(-0.5d, -0.0416667d, -0.0138889d, -7.8914204545e-6d),
            }));

            yield return(new ContextWithCastByRatio(
                             context: namespaces + new UnitDefinition("foot", "ft"),
                             ratio: new CastRatio(1, "1", "FootRatio"),
                             testCases: new[]
            {
                zeroTestCase,
                new CastRatioTestCase(1d, 12d, 0.333333d, 0.000189394d),
                new CastRatioTestCase(10d, 120d, 3.33333d, 0.00189394d),
                new CastRatioTestCase(-0.5d, -6d, -0.166667d, -9.4697e-5d),
            }));

            yield return(new ContextWithCastByRatio(
                             context: namespaces + new UnitDefinition("yard", "yd"),
                             ratio: new CastRatio(3, "3", "FootRatio"),
                             testCases: new[]
            {
                zeroTestCase,
                new CastRatioTestCase(1d, 36d, 3d, 0.000568182d),
                new CastRatioTestCase(10d, 360d, 30d, 0.00568182d),
                new CastRatioTestCase(-0.5d, -18d, -1.5d, -0.000284091d),
            }));

            yield return(new ContextWithCastByRatio(
                             context: namespaces + new UnitDefinition("mile", "mi"),
                             ratio: new CastRatio(5_280, "5_280", "FootRatio"),
                             testCases: new[]
            {
                zeroTestCase,
                new CastRatioTestCase(1d, 63360d, 5280d, 1760d),
                new CastRatioTestCase(10d, 633600d, 52800d, 17600d),
                new CastRatioTestCase(-0.5d, -31680d, -2640d, -880d),
            }));
        }
        private static IReadOnlyCollection <ContextWithCastByPower> BuildContexts()
        {
            var builder = new ContextWithCastByPowerBuilder(10);

            var namespaces = new UnitNamespaces(Resource.NamespacePixel);

            builder.Add(06, namespaces + new UnitDefinition("megapixel", "MP", "Represents a Megapixel (symbol MP).\nIt is a multiple of the unit <c>Pixel</c>, where:\n- 1 Megapixel = 1,000,000 Pixels"));
            builder.Add(00, namespaces + new UnitDefinition("pixel", "px"));

            builder.TestCases = new[] {
                //     megapixel,  pixel
                //         10e+6,   10e0
                new[] { 0d, 0d },
                new[] { 13.7e6, 13.7e0 },
                new[] { -5e0, -5e-6 },
                new[] { 1e-6, 1e-12 }
            };

            return(builder.Build());
        }
Esempio n. 9
0
        private static IReadOnlyCollection <ContextWithCastByPower> BuildContexts()
        {
            var builder = new ContextWithCastByPowerBuilder(10);

            var namespaces = new UnitNamespaces(Resource.NamespaceBit);

            builder.Add(12, namespaces + new UnitDefinition("terabit", "Tb", "Represents a Terabit (symbol Tb).\nIt is a multiple of the unit <c>Bit</c>, where:\n- 1 Terabit = 1,000 Gigabit\n- 1 Terabit = 10^12 Bits"));
            builder.Add(09, namespaces + new UnitDefinition("gigabit", "Gb", "Represents a Gigabit (symbol Gb).\nIt is a multiple of the unit <c>Bit</c>, where:\n- 1 Gigabit = 1,000 Megabit\n- 1 Gigabit = 10^9 Bits"));
            builder.Add(06, namespaces + new UnitDefinition("megabit", "Mb", "Represents a Megabit (symbol Mb).\nIt is a multiple of the unit <c>Bit</c>, where:\n- 1 Megabit = 1,000 Kilobit\n- 1 Megabit = 10^6 Bits"));
            builder.Add(03, namespaces + new UnitDefinition("kilobit", "Kb", "Represents a Kilobit (symbol Kb).\nIt is a multiple of the unit <c>Bit</c>, where:\n- 1 Kilobit = 1,000 Bits\n- 1 Kilobit = 10^3 Bits"));
            builder.Add(00, namespaces + new UnitDefinition("bit", "b", "Represents a Bit (symbol b).\nWhere:\n- 8 bits = 1 byte"));

            builder.TestCases = new[] {
                //      terabit, gigabit, megabit, kilobit,    bit
                //       10e+12,   10e+9,   10e+6,   10e+3,   10e0
                new[] { 0d, 0d, 0d, 0d, 0d },
                new[] { 13.7e12, 13.7e9, 13.7e6, 13.7e3, 13.7e0 },
                new[] { -5e6, -5e3, -5e0, -5e-3, -5e-6 },
                new[] { 1e0, 1e-3, 1e-6, 1e-9, 1e-12 }
            };

            return(builder.Build());
        }
        public IReadOnlyCollection <ContextWithCastByPower> BuildContexts()
        {
            var builder = new ContextWithCastByPowerBuilder(10);

            var namespaces = new UnitNamespaces(Resource.NamespaceSquareMetre);

            builder.Add(+36, namespaces + new UnitDefinition("square exametre", "Em²"));
            builder.Add(+30, namespaces + new UnitDefinition("square petametre", "Pm²"));
            builder.Add(+24, namespaces + new UnitDefinition("square terametre", "Tm²"));
            builder.Add(+18, namespaces + new UnitDefinition("square gigametre", "Gm²"));
            builder.Add(+12, namespaces + new UnitDefinition("square megametre", "Mm²"));
            builder.Add(+06, namespaces + new UnitDefinition("square kilometre", "km²"));
            builder.Add(+04, namespaces + new UnitDefinition("square hectometre", "hm²"));
            builder.Add(+02, namespaces + new UnitDefinition("square decametre", "dam²"));
            builder.Add(000, namespaces + new UnitDefinition("square metre", "m²"));
            builder.Add(-02, namespaces + new UnitDefinition("square decimetre", "dm²"));
            builder.Add(-04, namespaces + new UnitDefinition("square centimetre", "cm²"));
            builder.Add(-06, namespaces + new UnitDefinition("square millimetre", "mm²"));
            builder.Add(-12, namespaces + new UnitDefinition("square micrometre", "μm²"));
            builder.Add(-18, namespaces + new UnitDefinition("square nanometre", "nm²"));
            builder.Add(-24, namespaces + new UnitDefinition("square picometre", "pm²"));
            builder.Add(-30, namespaces + new UnitDefinition("square femtometre", "fm²"));
            builder.Add(-36, namespaces + new UnitDefinition("square attometre", "am²"));

            builder.TestCases = new[] {
                //           Em,      Pm,      Tm,      Gm,      Mm,     km,     hm,    dam,      m,      dm,      cm,      mm,       um,       nm,       pm,       fm,       am
                //       10e+36,  10e+30,  10e+24,  10e+18,  10e+12,  10e+6,  10e+4,  10e+2,   10e0,   10e-2,   10e-4,   10e-6,   10e-12,   10e-18,   10e-24,   10e-30,   10e-36
                new[] { 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d },
                new[] { -5e36, -5e30, -5e24, -5e18, -5e12, -5e6, -5e4, -5e2, -5e0, -5e-2, -5e-4, -5e-6, -5e-12, -5e-18, -5e-24, -5e-30, -5e-36 },
                new[] { 13.7e36, 13.7e30, 13.7e24, 13.7e18, 13.7e12, 13.7e6, 13.7e4, 13.7e2, 13.7e0, 13.7e-2, 13.7e-4, 13.7e-6, 13.7e-12, 13.7e-18, 13.7e-24, 13.7e-30, 13.7e-36 },
                new[] { 1e0, 1e-6, 1e-12, 1e-18, 1e-24, 1e-30, 1e-32, 1e-34, 1e-36, 1e-38, 1e-40, 1e-42, 1e-48, 1e-54, 1e-60, 1e-66, 1e-72 },
                new[] { 1e72, 1e66, 1e60, 1e54, 1e48, 1e42, 1e40, 1e38, 1e36, 1e34, 1e32, 1e30, 1e24, 1e18, 1e12, 1e6, 1e0 }
            };

            return(builder.Build());
        }
Esempio n. 11
0
        private static IReadOnlyCollection <ContextWithCastByPower> BuildContexts()
        {
            var builder = new ContextWithCastByPowerBuilder(10);

            var namespaces = new UnitNamespaces(Resource.NamespaceMetre);

            builder.Add(+18, namespaces + new UnitDefinition("exametre", "Em"));
            builder.Add(+15, namespaces + new UnitDefinition("petametre", "Pm"));
            builder.Add(+12, namespaces + new UnitDefinition("terametre", "Tm"));
            builder.Add(+09, namespaces + new UnitDefinition("gigametre", "Gm"));
            builder.Add(+06, namespaces + new UnitDefinition("megametre", "Mm"));
            builder.Add(+03, namespaces + new UnitDefinition("kilometre", "km"));
            builder.Add(+02, namespaces + new UnitDefinition("hectometre", "hm"));
            builder.Add(+01, namespaces + new UnitDefinition("decametre", "dam"));
            builder.Add(000, namespaces + new UnitDefinition("metre", "m"));
            builder.Add(-01, namespaces + new UnitDefinition("decimetre", "dm"));
            builder.Add(-02, namespaces + new UnitDefinition("centimetre", "cm"));
            builder.Add(-03, namespaces + new UnitDefinition("millimetre", "mm"));
            builder.Add(-06, namespaces + new UnitDefinition("micrometre", "μm"));
            builder.Add(-09, namespaces + new UnitDefinition("nanometre", "nm"));
            builder.Add(-12, namespaces + new UnitDefinition("picometre", "pm"));
            builder.Add(-15, namespaces + new UnitDefinition("femtometre", "fm"));
            builder.Add(-18, namespaces + new UnitDefinition("attometre", "am"));

            builder.TestCases = new[] {
                //           Em,      Pm,      Tm,     Gm,     Mm,     km,     hm,    dam,      m,      dm,      cm,      mm,      um,      nm,       pm,       fm,       am
                //       10e+18,  10e+15,  10e+12,  10e+9,  10e+6,  10e+3,  10e+2,  10e+1,   10e0,   10e-1,   10e-2,   10e-3,   10e-6,   10e-9,   10e-12,   10e-15,   10e-18
                new[] { 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d },
                new[] { 13.7e18, 13.7e15, 13.7e12, 13.7e9, 13.7e6, 13.7e3, 13.7e2, 13.7e1, 13.7e0, 13.7e-1, 13.7e-2, 13.7e-3, 13.7e-6, 13.7e-9, 13.7e-12, 13.7e-15, 13.7e-18 },
                new[] { -5e18, -5e15, -5e12, -5e9, -5e6, -5e3, -5e2, -5e1, -5e0, -5e-1, -5e-2, -5e-3, -5e-6, -5e-9, -5e-12, -5e-15, -5e-18 },
                new[] { 1e0, 1e-3, 1e-6, 1e-9, 1e-12, 1e-15, 1e-16, 1e-17, 1e-18, 1e-19, 1e-20, 1e-21, 1e-24, 1e-27, 1e-30, 1e-33, 1e-36 },
                new[] { 1e36, 1e33, 1e30, 1e27, 1e24, 1e21, 1e20, 1e19, 1e18, 1e17, 1e16, 1e15, 1e12, 1e9, 1e6, 1e3, 1e0 }
            };

            return(builder.Build());
        }
        private static IEnumerable <ContextWithCastByRatio> BuildContexts()
        {
            var zeroTestCase = new CastRatioTestCase(0, 0, 0, 0, 0, 0, 0, 0);
            var namespaces   = new UnitNamespaces(Resource.NamespaceTime);

            yield return(new ContextWithCastByRatio(
                             context: namespaces + new UnitDefinition("year", "years"),
                             ratio: new CastRatio(146_097d / 400d, "/* ~365.2425 */ 146_097d / 400d", "DayPortion"),
                             testCases: new[] {
                zeroTestCase,
                new CastRatioTestCase(1, MonthsPerYear, WeeksPerYear, DaysPerYear, HoursPerYear, MinutesPerYear, SecondsPerYear, MillisecondsPerYear),
                new CastRatioTestCase(4, 4 * MonthsPerYear, 4 * WeeksPerYear, 4 * 365.25, 1461 * HoursPerDay, 1461 * MinutesPerDay, 1461 * SecondsPerDay, 1461 * MillisecondsPerDay),
            }
                             ));

            yield return(new ContextWithCastByRatio(
                             context: namespaces + new UnitDefinition("month", "months"),
                             ratio: new CastRatio(48_699d / 1_600d, "/* ~30.436875 */ 48_699d / 1_600d", "DayPortion"),
                             testCases: new[] {
                zeroTestCase,
                new CastRatioTestCase(1, 1 / MonthsPerYear, WeeksPerMonth, DaysPerMonth, HoursPerMonth, MinutesPerMonth, SecondsPerMonth, MillisecondsPerMonth),
                new CastRatioTestCase(MonthsPerYear, 1d, WeeksPerYear, DaysPerYear, HoursPerYear, MinutesPerYear, SecondsPerYear, MillisecondsPerYear),
            }
                             ));

            yield return(new ContextWithCastByRatio(
                             context: namespaces + new UnitDefinition("week", "weeks"),
                             ratio: new CastRatio(7, "7", "DayPortion"),
                             testCases: new[] {
                zeroTestCase,
                new CastRatioTestCase(1, DaysPerWeek / DaysPerYear, DaysPerWeek / DaysPerMonth, DaysPerWeek, HoursPerWeek, MinutesPerWeek, SecondsPerWeek, MillisecondsPerWeek),
                new CastRatioTestCase(WeeksPerYear, 1, MonthsPerYear, DaysPerYear, HoursPerYear, MinutesPerYear, SecondsPerYear, MillisecondsPerYear),
            }
                             ));

            yield return(new ContextWithCastByRatio(
                             context: namespaces + new UnitDefinition("day", "days"),
                             ratio: new CastRatio(1, "1", "DayPortion"),
                             testCases: new[] {
                zeroTestCase,
                new CastRatioTestCase(1, 1 / DaysPerYear, 1 / DaysPerMonth, 1 / DaysPerWeek, HoursPerDay, MinutesPerDay, SecondsPerDay, MillisecondsPerDay),
                new CastRatioTestCase(DaysPerMonth, 1 / MonthsPerYear, 1, WeeksPerMonth, HoursPerMonth, MinutesPerMonth, SecondsPerMonth, MillisecondsPerMonth),
                new CastRatioTestCase(DaysPerYear, 1, MonthsPerYear, WeeksPerYear, HoursPerYear, MinutesPerYear, SecondsPerYear, MillisecondsPerYear),
            }
                             ));

            yield return(new ContextWithCastByRatio(
                             context: namespaces + new UnitDefinition("hour", "hours"),
                             ratio: new CastRatio(1d / 24d, "1d / 24d", "DayPortion"),
                             testCases: new[] {
                zeroTestCase,
                new CastRatioTestCase(1, 1 / HoursPerYear, 1 / HoursPerMonth, 1 / HoursPerWeek, 1 / HoursPerDay, MinutesPerHour, SecondsPerHour, MillisecondsPerHour),
                new CastRatioTestCase(HoursPerDay, 1 / DaysPerYear, 1 / DaysPerMonth, 1 / DaysPerWeek, 1, MinutesPerDay, SecondsPerDay, MillisecondsPerDay),
            }
                             ));

            yield return(new ContextWithCastByRatio(
                             context: namespaces + new UnitDefinition("minute", "minutes"),
                             ratio: new CastRatio(1d / (24d * 60d), "1d / (24d * 60d)", "DayPortion"),
                             testCases: new[] {
                zeroTestCase,
                new CastRatioTestCase(1, 1 / MinutesPerYear, 1 / MinutesPerMonth, 1 / MinutesPerWeek, 1 / MinutesPerDay, 1 / MinutesPerHour, SecondsPerMinute, MillisecondsPerMinute),
                new CastRatioTestCase(MinutesPerHour, 1 / HoursPerYear, 1 / HoursPerMonth, 1 / HoursPerWeek, 1 / HoursPerDay, 1, SecondsPerHour, MillisecondsPerHour),
            }
                             ));

            yield return(new ContextWithCastByRatio(
                             context: namespaces + new UnitDefinition("second", "seconds"),
                             ratio: new CastRatio(1d / (24d * 60d * 60d), "1d / (24d * 60d * 60d)", "DayPortion"),
                             testCases: new[] {
                zeroTestCase,
                new CastRatioTestCase(1, 1 / SecondsPerYear, 1 / SecondsPerMonth, 1 / SecondsPerWeek, 1 / SecondsPerDay, 1 / SecondsPerHour, 1 / SecondsPerMinute, MillisecondsPerSecond),
                new CastRatioTestCase(SecondsPerDay, 1 / DaysPerYear, 1 / DaysPerMonth, 1 / DaysPerWeek, 1, HoursPerDay, MinutesPerDay, MillisecondsPerDay),
            }
                             ));

            yield return(new ContextWithCastByRatio(
                             context: namespaces + new UnitDefinition("millisecond", "milliseconds"),
                             ratio: new CastRatio(1d / (24d * 60d * 60d * 1_000d), "1d / (24d * 60d * 60d * 1_000d)", "DayPortion"),
                             testCases: new[] {
                zeroTestCase,
                new CastRatioTestCase(1, 1 / MillisecondsPerYear, 1 / MillisecondsPerMonth, 1 / MillisecondsPerWeek, 1 / MillisecondsPerDay, 1 / MillisecondsPerHour, 1 / MillisecondsPerMinute, 1 / MillisecondsPerSecond),
                new CastRatioTestCase(MillisecondsPerHour, 1 / HoursPerYear, 1 / HoursPerMonth, 1 / HoursPerWeek, 1 / HoursPerDay, 1, MinutesPerHour, SecondsPerHour),
            }
                             ));
        }