コード例 #1
0
 public void FromValueAndUnit()
 {
     Assert.AreEqual(1, ElectricCurrent.From(1, ElectricCurrentUnit.Ampere).Amperes, AmperesTolerance);
     Assert.AreEqual(1, ElectricCurrent.From(1, ElectricCurrentUnit.Kiloampere).Kiloamperes, KiloamperesTolerance);
     Assert.AreEqual(1, ElectricCurrent.From(1, ElectricCurrentUnit.Megaampere).Megaamperes, MegaamperesTolerance);
     Assert.AreEqual(1, ElectricCurrent.From(1, ElectricCurrentUnit.Microampere).Microamperes, MicroamperesTolerance);
     Assert.AreEqual(1, ElectricCurrent.From(1, ElectricCurrentUnit.Milliampere).Milliamperes, MilliamperesTolerance);
     Assert.AreEqual(1, ElectricCurrent.From(1, ElectricCurrentUnit.Nanoampere).Nanoamperes, NanoamperesTolerance);
 }
コード例 #2
0
 public void FromValueAndUnit()
 {
     AssertEx.EqualTolerance(1, ElectricCurrent.From(1, ElectricCurrentUnit.Ampere).Amperes, AmperesTolerance);
     AssertEx.EqualTolerance(1, ElectricCurrent.From(1, ElectricCurrentUnit.Centiampere).Centiamperes, CentiamperesTolerance);
     AssertEx.EqualTolerance(1, ElectricCurrent.From(1, ElectricCurrentUnit.Kiloampere).Kiloamperes, KiloamperesTolerance);
     AssertEx.EqualTolerance(1, ElectricCurrent.From(1, ElectricCurrentUnit.Megaampere).Megaamperes, MegaamperesTolerance);
     AssertEx.EqualTolerance(1, ElectricCurrent.From(1, ElectricCurrentUnit.Microampere).Microamperes, MicroamperesTolerance);
     AssertEx.EqualTolerance(1, ElectricCurrent.From(1, ElectricCurrentUnit.Milliampere).Milliamperes, MilliamperesTolerance);
     AssertEx.EqualTolerance(1, ElectricCurrent.From(1, ElectricCurrentUnit.Nanoampere).Nanoamperes, NanoamperesTolerance);
     AssertEx.EqualTolerance(1, ElectricCurrent.From(1, ElectricCurrentUnit.Picoampere).Picoamperes, PicoamperesTolerance);
 }
コード例 #3
0
        private ElectricCurrent ReadCurrent()
        {
            float f_current = 0;
            int   currentADCCode;

            byte[] result = this.ReadRegisterByte(LTC2943_Constants.CURRENT_MSB, 2, true);

            if (result == null)
            {
                Console.WriteLine("Read from current register failed.");
                return(ElectricCurrent.MinValue);
            }

            currentADCCode = result[0] * 256 + result[1];
            Console.WriteLine(string.Format("Read from current register: {0}-{1}", result[0], result[1]));
            f_current = CalculateCurrentFromADCCode(currentADCCode);

            return(ElectricCurrent.From(f_current, UnitsNet.Units.ElectricCurrentUnit.Ampere));
        }
コード例 #4
0
        public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit()
        {
            var quantity00 = ElectricCurrent.From(1, ElectricCurrentUnit.Ampere);

            AssertEx.EqualTolerance(1, quantity00.Amperes, AmperesTolerance);
            Assert.Equal(ElectricCurrentUnit.Ampere, quantity00.Unit);

            var quantity01 = ElectricCurrent.From(1, ElectricCurrentUnit.Centiampere);

            AssertEx.EqualTolerance(1, quantity01.Centiamperes, CentiamperesTolerance);
            Assert.Equal(ElectricCurrentUnit.Centiampere, quantity01.Unit);

            var quantity02 = ElectricCurrent.From(1, ElectricCurrentUnit.Kiloampere);

            AssertEx.EqualTolerance(1, quantity02.Kiloamperes, KiloamperesTolerance);
            Assert.Equal(ElectricCurrentUnit.Kiloampere, quantity02.Unit);

            var quantity03 = ElectricCurrent.From(1, ElectricCurrentUnit.Megaampere);

            AssertEx.EqualTolerance(1, quantity03.Megaamperes, MegaamperesTolerance);
            Assert.Equal(ElectricCurrentUnit.Megaampere, quantity03.Unit);

            var quantity04 = ElectricCurrent.From(1, ElectricCurrentUnit.Microampere);

            AssertEx.EqualTolerance(1, quantity04.Microamperes, MicroamperesTolerance);
            Assert.Equal(ElectricCurrentUnit.Microampere, quantity04.Unit);

            var quantity05 = ElectricCurrent.From(1, ElectricCurrentUnit.Milliampere);

            AssertEx.EqualTolerance(1, quantity05.Milliamperes, MilliamperesTolerance);
            Assert.Equal(ElectricCurrentUnit.Milliampere, quantity05.Unit);

            var quantity06 = ElectricCurrent.From(1, ElectricCurrentUnit.Nanoampere);

            AssertEx.EqualTolerance(1, quantity06.Nanoamperes, NanoamperesTolerance);
            Assert.Equal(ElectricCurrentUnit.Nanoampere, quantity06.Unit);

            var quantity07 = ElectricCurrent.From(1, ElectricCurrentUnit.Picoampere);

            AssertEx.EqualTolerance(1, quantity07.Picoamperes, PicoamperesTolerance);
            Assert.Equal(ElectricCurrentUnit.Picoampere, quantity07.Unit);
        }