Пример #1
0
        public void ParseTest(string p, double A1, double B1, double C1, UnitOfMeasure Unit1)
        {
            var p1 = Pudelko.Parse(p);
            var p2 = new Pudelko(A1, B1, C1);

            Assert.AreEqual(p2, p1);
        }
Пример #2
0
        public void Parsing_ToString()
        {
            string  p               = "2.500 m × 9.321 m × 0.100 m";
            Pudelko pudlo           = Pudelko.Parse(p);
            Pudelko expectedPudelko = new Pudelko(2.5, 9.321);

            Assert.AreEqual(expectedPudelko, pudlo);
        }
        public void Parse_Pudelko_Meters(double a, double b, double c, string stringToParse, bool expected)
        {
            Pudelko p1 = new Pudelko(a, b, c, unit: UnitOfMeasure.meter);


            var result = p1 == p1.Parse(stringToParse);


            Assert.AreEqual(expected, result);
        }
Пример #4
0
        static void Main()
        {
            Console.WriteLine("Pudelko Marek Woźniak");

            Pudelko p1      = new Pudelko(5, 7, 4);
            Pudelko p2      = new Pudelko(40, 50, 50, UnitOfMeasure.centimeter);
            Pudelko p3      = new Pudelko(100, 300, 500, UnitOfMeasure.centimeter);
            var     pudelka = new Pudelko[] { p3, p2, p1 };

            Console.WriteLine("\nForeach: ");
            foreach (var p in pudelka)
            {
                Console.WriteLine(p);
            }

            Console.WriteLine("\nSort: ");
            Array.Sort(pudelka, Pudelko.CompareBoxes);

            foreach (var p in pudelka)
            {
                Console.WriteLine(p);
            }


            Console.WriteLine("\nNasze p1: " + p1);
            Console.WriteLine("Nasze p2: " + p2);

            Console.WriteLine("\nPole p1: " + p1.Pole);
            Console.WriteLine("Objetosc p2: " + p2.Objetosc);
            Console.WriteLine("\nCzy p1 jest równe p2 :" + p1.Equals(p2));
            Console.WriteLine("GetHashCode p1:" + p1.GetHashCode());
            Console.WriteLine("GetHashCode p2:" + p2.GetHashCode());

            Console.WriteLine("\nPudełko sześcienne o takiej samej objętości, jak p: " + p1.Compress());
            Console.WriteLine("p1[1]: " + p1[1]);
            Console.WriteLine("\nPrzeglądanie długości krawędzi: ");
            foreach (var i in p1)
            {
                Console.WriteLine(i);
            }
            Console.Write("Parse: ");
            Console.WriteLine(new Pudelko(2.5, 9.321, 0.1) == Pudelko.Parse("2.500 m × 9.321 m × 0.100 m"));
        }
Пример #5
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());
        }
Пример #6
0
        static void Main(string[] args)
        {
            //16 lista pudełek
            List <Pudelko> Pudelka = new List <Pudelko>();
            Pudelko        p1      = new Pudelko(2.5, 9.321, 0.1, UnitOfMeasure.meter);
            Pudelko        p2      = new Pudelko(9, 6, 0.5, UnitOfMeasure.meter);
            Pudelko        p3      = new Pudelko(9, 60, 14, UnitOfMeasure.milimeter);
            Pudelko        p4      = new Pudelko(9.41, null, 1.7, UnitOfMeasure.meter);
            Pudelko        p5      = new Pudelko(6, 6, 0.5);
            Pudelko        p6      = new Pudelko();
            Pudelko        p7      = p2.Kompresuj();
            Pudelko        p8      = Pudelko.Parse("2.500 m × 9.321 m × 0.100 m");

            Pudelka.Add(p1);
            Pudelka.Add(p2);
            Pudelka.Add(p3);
            Pudelka.Add(p4);
            Pudelka.Add(p5);
            Pudelka.Add(p6);
            Pudelka.Add(p7);
            Pudelka.Add(p8);
            //16 wypisanie pudełek
            foreach (var i in Pudelka)
            {
                Console.WriteLine(i.ToString());
            }
            //16 Compare
            Pudelka.Sort(CompareThroughObjThenPoleThenSuma);
            Console.WriteLine();
            Console.WriteLine("Lista Pudełek Posortowana");
            Console.WriteLine();
            foreach (var i in Pudelka)
            {
                Console.WriteLine(i.ToString());
            }
        }
Пример #7
0
        static void Main(string[] args)
        {
            List <Pudelko> listaPudelek = new List <Pudelko>();

            listaPudelek.Add(new Pudelko());
            listaPudelek.Add(new Pudelko(1));
            listaPudelek.Add(new Pudelko(2, 5));
            listaPudelek.Add(new Pudelko(7, 8, 3));
            listaPudelek.Add(Pudelko.Parse("2,500 m × 4,700 m × 1,990 m"));
            listaPudelek.Add(new Pudelko(9, 5, 3, UnitOfMeasure.meter));
            listaPudelek.Add(new Pudelko(2, 7, 5, UnitOfMeasure.meter));
            listaPudelek.Add(new Pudelko(4, 9, 7, UnitOfMeasure.meter));
            listaPudelek.Add(new Pudelko(6, 2, 9, UnitOfMeasure.meter));
            listaPudelek.Add(new Pudelko(80, 4, 10, UnitOfMeasure.centimeter));
            listaPudelek.Add(new Pudelko(1, 6, 10, UnitOfMeasure.centimeter));
            listaPudelek.Add(new Pudelko(40, 8, 5, UnitOfMeasure.centimeter));
            listaPudelek.Add(new Pudelko(60, 10, 70, UnitOfMeasure.milimeter));
            listaPudelek.Add(new Pudelko(70, 30, 90, UnitOfMeasure.milimeter));
            listaPudelek.Add(new Pudelko(90, 50, 20, UnitOfMeasure.milimeter));
            Console.WriteLine("Lista nieposortowana");
            foreach (var item in listaPudelek)
            {
                Console.WriteLine(item);
            }
Пример #8
0
        public void Parse_InMillimeters_ReturnsNewPudelkoInMillimeters()
        {
            var p = Pudelko.Parse("2000 mm × 1000 mm × 3000 mm");

            AssertPudelko(p, 2, 1, 3);
        }
Пример #9
0
        public void Parse_InMeters_ReturnsNewPudelkoInMeters()
        {
            var p = Pudelko.Parse("2.0 m × 1.0 m × 3.0 m");

            AssertPudelko(p, 2, 1, 3);
        }
Пример #10
0
 public void Parse_InvalidInput_ThrowsFormatException(string input)
 {
     var p = Pudelko.Parse(input);
 }
Пример #11
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);
            }
        }
        public void Parsing(string parseString)
        {
            Pudelko expected = new Pudelko(2500, 9321, null, UnitOfMeasure.milimeter);

            Assert.AreEqual(expected, Pudelko.Parse(parseString));
        }