Пример #1
0
        public void CreateAndConvertInchesValidINput()
        {
            //test positive cases
            var mm = Inch.ConvertTo(1.25, DynamoUnitType.Millimeters);

            Assert.AreEqual(25.4 * 1.25, mm, 0.001);

            var cm = Inch.ConvertTo(1.25, DynamoUnitType.Centimeters);

            Assert.AreEqual(2.54 * 1.25, cm, 0.001);

            var m = Inch.ConvertTo(1.25, DynamoUnitType.Meters);

            Assert.AreEqual(0.0254 * 1.25, m, 0.001);

            var inch = Inch.ConvertTo(1.25, DynamoUnitType.Inches);

            Assert.AreEqual(1.0 * 1.25, inch, 0.001);

            var ft = Inch.ConvertTo(1.25, DynamoUnitType.Feet);

            Assert.AreEqual(0.083333 * 1.25, ft, 0.001);

            Assert.AreEqual("1 1/4\"", Inch.AsString(1.25));

            //test negative cases
            mm = Inch.ConvertTo(-1.25, DynamoUnitType.Millimeters);
            Assert.AreEqual(-25.4 * 1.25, mm, 0.001);

            cm = Inch.ConvertTo(-1.25, DynamoUnitType.Centimeters);
            Assert.AreEqual(-2.54 * 1.25, cm, 0.001);

            m = Inch.ConvertTo(-1.25, DynamoUnitType.Meters);
            Assert.AreEqual(-0.0254 * 1.25, m, 0.001);

            inch = Inch.ConvertTo(-1.25, DynamoUnitType.Inches);
            Assert.AreEqual(-1.0 * 1.25, inch, 0.001);

            ft = Inch.ConvertTo(-1.25, DynamoUnitType.Feet);
            Assert.AreEqual(-0.083333 * 1.25, ft, 0.001);

            Assert.AreEqual("-1 1/4\"", Inch.AsString(-1.25));

            //test just the fractional case
            Assert.AreEqual("1/4\"", Inch.AsString(.25));
            Assert.AreEqual("-1/4\"", Inch.AsString(-.25));

            //test just the whole case
            Assert.AreEqual("1\"", Inch.AsString(1.0));
            Assert.AreEqual("-1\"", Inch.AsString(-1.0));

            //test some edge cases
            Assert.AreEqual("0\"", Inch.AsString(0.0));
            Assert.AreEqual("1/64\"", Inch.AsString(0.01));
            Assert.AreEqual("1\"", Inch.AsString(0.99));
        }