Esempio n. 1
0
        static void Main()
        {
            Point3D p1 = new Point3D(2, 3.5, 6);
            Point3D p2 = new Point3D(2.1, 4, 41);
            Point3D p3 = new Point3D(0, 8.8, -5);

            Console.WriteLine("The center of the coordinate system {0}", Point3D.O.ToString());
            Console.WriteLine("A point {0}", p3.ToString());
            Console.WriteLine("The distance between points p1 {0} and p2 {1} is: {2:F2}",
                p1.ToString(), p2.ToString(), Distance.CalculateDistance(p1, p2));

            Path path = new Path();
            path.AddPoint(p1);
            path.AddPoint(p2);
            path.AddPoint(p3);
            Console.WriteLine("A path from 3 points: {0}", path.ToString());
            Console.Write("Loaded point from file:");
            PathStorage.LoadPath(@"..\..\points.txt");
            Console.WriteLine("Points p1,p2,p3 are saved in file.");
            PathStorage.SavePath(path);
        }
Esempio n. 2
0
        private static void Main()
        {
            // Point test
            Point3D nuevo = Point3D.ZeroPoint;
            var far = new Point3D(2.56, 3.8, 5.98);
            Console.WriteLine("first point - {0}\nsecond point - {1}", nuevo, far);
            var distance = DistanceCalc.CalcDistance(nuevo, far);
            Console.WriteLine("distance {0:F}", distance);

            // Path test
            var path = new Path(nuevo, far);
            for (int count = 0; count < 10; count++)
            {
                path.AddPoint(new Point3D(rng.Next(10), rng.Next(10), rng.Next(10)));
            }

            Console.WriteLine(path);
            PathStorage.SavePath(path);
            path = new Path();
            path = PathStorage.LoadPath();
            Console.WriteLine(path);
        }
        static void Main()
        {
            // Test Path
            Path points = new Path();
            points.AddPoint(new Point3D(1, 2, 3));
            points.AddPoint(new Point3D(5, 2, 3));
            points.AddPoint(new Point3D(6, 3, 3));

            // Test PathStorage
            PathStorage.SavePath(points);
            PathStorage.LoadPath();

            // Test distance
            Console.WriteLine("Distance: {0}", Distance.CalculateDistance(new Point3D(1, 2, 3), new Point3D(5, 2, 3)));

            // Test Matrix operators
            Matrix<int> matrix1 = new Matrix<int>(3, 2);
            matrix1[0, 0] = 1;
            matrix1[0, 1] = 3;
            matrix1[1, 0] = 1;
            matrix1[1, 1] = 0;
            matrix1[2, 0] = 1;
            matrix1[2, 1] = 2;
            Matrix<int> matrix2 = new Matrix<int>(3, 2);
            matrix2[0, 0] = 0;
            matrix2[0, 1] = 0;
            matrix2[1, 0] = 7;
            matrix2[1, 1] = 5;
            matrix2[2, 0] = 2;
            matrix2[2, 1] = 1;

            // Test +
            Console.WriteLine("The sum is");
            Console.WriteLine(matrix1 + matrix2);

            // Test -
            Console.WriteLine("The subtraction is");
            Console.WriteLine(matrix1 - matrix2);

            // Test *
            Matrix<int> matrix3 = new Matrix<int>(2, 3);
            matrix3[0, 0] = 1;
            matrix3[0, 1] = 2;
            matrix3[0, 2] = 3;
            matrix3[1, 0] = 4;
            matrix3[1, 1] = 5;
            matrix3[1, 2] = 6;
            Matrix<int> matrix4 = new Matrix<int>(3, 2);
            matrix4[0, 0] = 7;
            matrix4[0, 1] = 8;
            matrix4[1, 0] = 9;
            matrix4[1, 1] = 10;
            matrix4[2, 0] = 11;
            matrix4[2, 1] = 12;
            Console.WriteLine("The multiplication is");
            Console.WriteLine(matrix3 * matrix4);

            // Test True
            if (matrix1)
            {
                Console.WriteLine("The matrix has not zero element!");
            }
            else
            {
                Console.WriteLine("The matrix has zero element!");
            }

            if (matrix4)
            {
                Console.WriteLine("The matrix has not zero element!");
            }
            else
            {
                Console.WriteLine("The matrix has zero element!");
            }

            // Test Version attribute
            Console.WriteLine();
            VersionClass.TestVersion();
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            // Test Problems 01 - 04
            Console.WriteLine("Class point3d");
            Console.WriteLine("------------------------------------------------");
            Path points = new Path();
            points.Add(new Point3d(Point3d.O.X, Point3d.O.Y, Point3d.O.Z));
            points.Add(new Point3d(1, 1, 1));
            points.Add(new Point3d(2, 2, 2));
            points.Add(new Point3d(3, 3, 3));

            Console.WriteLine("Points in the object");
            Console.WriteLine(points);

            try
            {
                Console.WriteLine("Store points in file");
                points.StoreInFile("test.txt");
            }
            catch (System.IO.IOException)
            {
                Console.WriteLine("Error writing in file!");
                return;
            }

            Console.WriteLine("Clear points");
            points.Clear();

            try
            {
                Console.WriteLine("Read from file: ");
                points.LoadFromFile("test.txt");
                Console.WriteLine(points);
            }
            catch (System.IO.IOException)
            {
                Console.WriteLine("Error writing in file!");
                return;
            }

            // Test Problems 08 - 11
            Matrix<double> matrix1 = new Matrix<double>(5, 4);
            Matrix<double> matrix2 = new Matrix<double>(5, 4);
            Console.WriteLine("Matrix Generix");
            Console.WriteLine("------------------------------------------------");

            for (int x = 0; x < 5; x++)
                for (int y = 0; y < 4; y++)
                {
                    matrix1[x, y] = x + y;
                    matrix2[x, y] = (x + y) * 2;
                }

            Console.WriteLine("Matrix1");
            Console.WriteLine(matrix1);

            Console.WriteLine("Matrix2");
            Console.WriteLine(matrix2);

            Console.WriteLine("Matrix1 + Matrix2");
            Console.WriteLine(matrix1 + matrix2);

            Console.WriteLine("Matrix1 - Matrix2");
            Console.WriteLine(matrix1 - matrix2);

            Console.WriteLine("Matrix1 * Matrix2");
            Console.WriteLine(matrix1 * matrix2);

            Console.WriteLine("Is matrix1 true? ");
            if (matrix1)
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");

            Console.WriteLine("Attributes");
            Console.WriteLine("------------------------------------------------");

            // Reflection.
            var attrs = typeof(TestAttribute).GetCustomAttributes(typeof(VersionAttribute), true);

            foreach (VersionAttribute attr in attrs)
            {
                System.Console.WriteLine("Version:  {0}", attr.Version);
            }
        }