public void MassUnits()
            {
                Kilogram kilograms = (Kilogram)1.0;
                Gram     grams     = (Gram)kilograms;
                Tonne    tonnes    = (Tonne)grams;
                Pound    pounds    = (Pound)tonnes;
                Ounce    ounces    = (Ounce)pounds;

                kilograms = (Kilogram)ounces;

                Assert.AreEqual((Gram)1000.0, grams, "Kilogram-to-Gram conversion failed (1)");
                Assert.AreEqual((Tonne)0.001, tonnes, "Gram-to-Tonne conversion failed (1)");
                Assert.AreEqual((Pound)2.2046226218487757, pounds, "Tonne-to-Pound conversion failed (1)");
                Assert.AreEqual((Ounce)35.273961949580411, ounces, "Pound-to-Ounce conversion failed (1)");
                Assert.AreEqual((Kilogram)1.0, kilograms, "Ounce-to-Kilogram conversion failed (1)");

                Assert.AreEqual(16.0, ounces.Value / pounds.Value, "Incorrect Ounce-to-Pound conversion factor (1)");

                pounds    = (Pound)1.0;
                kilograms = (Kilogram)pounds;
                grams     = (Gram)kilograms;
                tonnes    = (Tonne)grams;
                ounces    = (Ounce)tonnes;

                pounds = (Pound)ounces;

                Assert.AreEqual((Kilogram)0.45359237, kilograms, "Pound-to-Kilogram conversion failed (2)");
                Assert.AreEqual((Gram)453.59237, grams, "Kilogram-to-Gram conversion failed (2)");
                Assert.AreEqual((Tonne)0.00045359237, tonnes, "Gram-to-Tonne conversion failed (2)");
                Assert.AreEqual((Ounce)15.999999999999996, ounces, "Tonne-to-Ounce conversion failed (2)");
                Assert.AreEqual((Pound)0.99999999999999978, pounds, "Ounce-to-Pound conversion failed (2)");

                Assert.AreEqual(16.0, ounces.Value / pounds.Value, "Incorrect Ounce-to-Pound conversion factor (2)");
            }
Example #2
0
        public void OverMaxAllowedRangePoundTest()
        {
            double value1 = 100;
            double value2 = 300;

            Kilogram kilogram1 = new Kilogram(value1, 100, 350);
            Kilogram kilogram2 = new Kilogram(value2);

            Pound pound = kilogram1 + kilogram2;

            Assert.AreEqual(expected: (value2 + value1) * 2.20462262, actual: pound.Value); // Should fail because of the range
        }
Example #3
0
    public void TestPound()
    {
        ICharacter characterA = Container.Resolve <ICharacter>();
        ICharacter characterB = Container.Resolve <ICharacter>();

        int hp = characterA.CurrentHP.Value;

        ISkill pound = new Pound();

        pound.Initialize(characterB, characterA);
        characterA.ApplySkill(pound);

        Assert.That(characterA.CurrentHP.Value == characterA.Stats_Total.MaxHp - characterB.Stats_Total.Strength);
    }
Example #4
0
    public void StartFight()
    {
        heroAttack = Observable.Interval(TimeSpan.FromSeconds(hero.Stats_Total.AttackRate))
                     .Subscribe(_ =>
        {
            ISkill pound = new Pound();
            pound.Initialize(hero, enemy);
            enemy.ApplySkill(pound);
        });

        enemyAttack = Observable.Interval(TimeSpan.FromSeconds(enemy.Stats_Total.AttackRate))
                      .Subscribe(_ =>
        {
            ISkill pound = new Pound();
            pound.Initialize(enemy, hero);
            hero.ApplySkill(pound);
        });
    }
 public void CompareQuantities()
 {
     {
         // 5.0 tonnes == 5000 kilograms
         Tonne    tonnes    = (Tonne)5.0;
         Kilogram kilograms = (Kilogram)5000.0;
         Assert.IsTrue((tonnes.Value != kilograms.Value) && (tonnes == (Tonne)kilograms));
     }
     {
         // 5 pounds < 5 kilograms
         Pound    pounds    = (Pound)5.0;
         Kilogram kilograms = (Kilogram)5.0;
         Assert.IsTrue((kilograms.Value == pounds.Value) && ((Kilogram)pounds != kilograms) && (pounds < (Pound)kilograms) && (kilograms >= (Kilogram)pounds));
     }
     {
         // 5 tonnes > 3000 kilograms
         Tonne    tonnes    = (Tonne)5.0;
         Kilogram kilograms = (Kilogram)3000.0;
         Assert.IsTrue((tonnes.Value < kilograms.Value) && (tonnes != (Tonne)kilograms) && ((Kilogram)tonnes > kilograms) && ((Tonne)kilograms <= tonnes));
     }
 }
Example #6
0
        private static void MassConverter()
        {
            ICalculator calculator = new MassCalculator();

            Console.WriteLine("What mass unit do you want to convert from?");
            Console.WriteLine("Options: 1 for Milligrams, 2 for Grams, 3 for Kilograms, 4 for Ounces, 5 for Pounds, 6 for Stones");
            Console.WriteLine("Type 'exit' to stop the program.");
            var convertFrom = Console.ReadLine();

            while (!int.TryParse(convertFrom, out int number) || (Convert.ToInt32(convertFrom) < 1 || Convert.ToInt32(convertFrom) > 6))
            {
                Console.WriteLine("Error write only numbers and it must be between 1 and 6");
                Console.WriteLine("Type 'exit' to stop the program.");
                convertFrom = Console.ReadLine();

                if (convertFrom.ToLower() == "exit")
                {
                    break;
                }
            }

            Console.WriteLine("What mass unit do you want to convert to?");
            Console.WriteLine("Options: 1 for Milligrams, 2 for Grams, 3 for Kilograms, 4 for Ounces, 5 for Pounds, 6 for Stones");
            Console.WriteLine("Type 'exit' to stop the program.");
            var convertTo = Console.ReadLine();

            while (!int.TryParse(convertTo, out int number) || (Convert.ToInt32(convertTo) < 1 || Convert.ToInt32(convertTo) > 6))
            {
                Console.WriteLine("Error write only numbers and it must be between 1 and 6");
                Console.WriteLine("Type 'exit' to stop the program.");
                convertTo = Console.ReadLine();

                if (convertTo.ToLower() == "exit")
                {
                    break;
                }
            }

            Console.WriteLine("What is the value you want to convert?");
            var valueToConvert = Console.ReadLine();

            while (!double.TryParse(valueToConvert, out double number))
            {
                Console.WriteLine("Error write only numbers.");
                Console.WriteLine("Type 'exit' to stop the program.");
                valueToConvert = Console.ReadLine();

                if (valueToConvert.ToLower() == "exit")
                {
                    break;
                }
            }

            IUnit from = null;
            IUnit to   = null;

            double valueInDoubleToConvert = double.Parse(valueToConvert);

            switch (convertFrom)
            {
            case "1":
                from = new Milligram {
                    Value = valueInDoubleToConvert
                };
                break;

            case "2":
                from = new Gram {
                    Value = valueInDoubleToConvert
                };
                break;

            case "3":
                from = new Kilogram {
                    Value = valueInDoubleToConvert
                };
                break;

            case "4":
                from = new Ounce {
                    Value = valueInDoubleToConvert
                };
                break;

            case "5":
                from = new Pound {
                    Value = valueInDoubleToConvert
                };
                break;

            case "6":
                from = new Stone {
                    Value = valueInDoubleToConvert
                };
                break;
            }

            switch (convertTo)
            {
            case "1":
                to = new Milligram();
                break;

            case "2":
                to = new Gram();
                break;

            case "3":
                to = new Kilogram();
                break;

            case "4":
                to = new Ounce();
                break;

            case "5":
                to = new Pound();
                break;

            case "6":
                to = new Stone();
                break;
            }

            var result = calculator.Calculate(from, to);

            Console.WriteLine($"Well, {from.Value} {from.Name}(s) is equal to {result} {to.Name}(s).");
        }
Example #7
0
 public static Stone From(Pound pounds) => new Stone(pounds.Value / 14d);
Example #8
0
 public virtual double ConvertFrom(Pound fromUnit, double amount)
 {
     return(0);
 }
Example #9
0
 public override double ConvertFrom(Pound fromUnit, double amount)
 {
     return(amount);
 }
Example #10
0
 public static Pixel ToPixel(this Pound pound) => new Pixel(pound.Value * 96 / 72);
Example #11
0
 public static PoundHundredfold ToPoundHundredfold(this Pound pound) => new PoundHundredfold(pound.Value * 100);
Example #12
0
 public static Kilogram From(Pound pounds) => new Kilogram(pounds.Value / 2.20462d);