public void ToString_Default_Culture_EN()
        {
            var    p = new Pudelko(2.5, 9.321);
            string expectedStringEN = "2.500 m × 9.321 m × 0.100 m";

            Assert.AreEqual(expectedStringEN, p.ToString());
        }
Example #2
0
        static void Main(string[] args)
        {
            List <Pudelko> pudelka = new List <Pudelko>();

            pudelka.Add(new Pudelko(1, 2.1, 3.05, UnitOfMeasure.milimeter));
            pudelka.Add(new Pudelko(1, 3.05, 2.1));
            pudelka.Add(new Pudelko(2.1, 1, 3.05, UnitOfMeasure.milimeter));
            pudelka.Add(new Pudelko(2100, 1001, 3050, UnitOfMeasure.milimeter));
            pudelka.Add(new Pudelko(2.5, 9.321, 0.1).Kompresuj());

            Console.WriteLine();
            Pudelko p1 = new Pudelko(11.0, 11.0, 10.0, UnitOfMeasure.centimeter);

            Console.WriteLine(p1);
            Console.WriteLine(p1.ToString());

            Console.WriteLine(pudelka[0].Equals(pudelka[2]));
            Console.WriteLine(pudelka[1].Equals(pudelka[3]));



            pudelka.Sort();

            int count = 1;

            foreach (Pudelko pudelko in pudelka)
            {
                Console.WriteLine($"Pudelko: {count}");
                foreach (var item in pudelko)
                {
                    Console.Write(item + "m - ");
                }
                Console.WriteLine();
                count++;
            }
            Console.WriteLine("______________________________________-");
            Console.WriteLine(Pudelko.Parse("2.5 cm x 9 cm x 1 cm").ToString());
        }
 public void ToString_Formattable_WrongFormat_FormatException()
 {
     var p = new Pudelko(1);
     var stringformatedrepreentation = p.ToString("wrong code");
 }
        public void ToString_Formattable_Culture_EN(string format, double a, double b, double c, string expectedStringRepresentation)
        {
            var p = new Pudelko(a, b, c, unit: UnitOfMeasure.meter);

            Assert.AreEqual(expectedStringRepresentation, p.ToString(format));
        }
Example #5
0
        static void Main(string[] args)
        {
            var test1 = new Pudelko(10, 5, 5);
            var test2 = new Pudelko(7, 5, 1);

            Console.WriteLine($"{test1.ToString()} == {test2.ToString()} : {test1 == test2}");
            Console.WriteLine($"{test1.ToString()} != {test2.ToString()} : {test1 != test2}");
            var test3 = test1 + test2;

            Console.WriteLine($"Po dodaniu: {test3.ToString()}");
            Console.WriteLine($"W centymetrach: {test3.ToString("cm")}");
            Console.WriteLine($"W milimetrach: {test3.ToString("mm")}");

            Console.WriteLine("============\nKonwersja");

            double[] test3Arr = test3;
            Console.WriteLine($"Jawna: Typ zwracany => {test3Arr}");

            var test4 = (Pudelko)(1000, 2000, 3000);

            Console.WriteLine($"Niejawna: W milimetrach => {test4.ToString("mm")}");


            Console.WriteLine("============\nIndexer");

            var indexer = new Pudelko(0.1, 1, 2);

            Console.WriteLine($"Index 0 => {indexer[0]}");
            Console.WriteLine($"Index 1 => {indexer[1]}");
            Console.WriteLine($"Index 2 => {indexer[2]}");
            try
            {
                Console.WriteLine(indexer[3]);
            }
            catch (ArgumentOutOfRangeException ex)
            {
                Console.WriteLine($"Index 3 => {ex}");
            }

            Console.WriteLine("============");



            var toCompress    = new Pudelko(2, 3, 4);
            var afterCompress = toCompress.Kompresuj();


            Console.WriteLine($"Przed kompresja: objetosc = {toCompress.Volume}, wymiary = {toCompress.ToString()}");
            Console.WriteLine($"Po kompresji: objetosc = {Math.Round(afterCompress.Volume, 3)}, wymiary = {afterCompress.ToString()}");



            Console.WriteLine("============");

            var p0  = new Pudelko();
            var p1  = new Pudelko(1);
            var p2  = new Pudelko(2, 3);
            var p3  = new Pudelko(400, 100, 500, UnitOfMeasure.Centimeter);
            var p4  = new Pudelko(9000, 1000, 3000, UnitOfMeasure.Millimeter);
            var p5  = new Pudelko(10, 10, 10);
            var p6  = new Pudelko(3, 3, 3);
            var p7  = new Pudelko(1, 5, 10);
            var p8  = new Pudelko(2, 5, 5);
            var p9  = p7 + p8;
            var p10 = Pudelko.Parse("5 m × 3 m × 2 m");

            var boxes = new List <Pudelko> {
                p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10
            };

            Console.WriteLine("NIEPOSORTOWANE:");
            foreach (var box in boxes)
            {
                Console.WriteLine(box.ToString());
            }

            boxes.Sort(((box1, box2) =>
            {
                if (Math.Abs(box1.Volume - box2.Volume) > 0.001)
                {
                    return(box1.Volume > box2.Volume ? 1 : -1);
                }
                if (Math.Abs(box1.Area - box2.Area) > 0.001)
                {
                    return(box1.Area > box2.Area ? 1 : -1);
                }

                return(box1.A + box1.B + box1.C > box2.A + box2.B + box2.C
                    ? 1
                    : -1);
            }));

            Console.WriteLine("=============\nPOSORTOWANE:");

            foreach (var box in boxes)
            {
                Console.WriteLine(box.ToString() + " obj: " + box.Volume + " pole: " + box.Area);
            }
        }