Beispiel #1
0
            public static string TestImpartire()
            {
                object[,] testeComparari = new object[, ] {
                    { "4", "2", "2" },
                    { "355", "113", "3,14159292035398230088" },
                    { "6", "2", "3" }
                };

                string str = "";

                for (int i = 0; i < testeComparari.GetLength(0); i++)
                {
                    Floatz a             = new Floatz((string)testeComparari[i, 0]);
                    Floatz b             = new Floatz((string)testeComparari[i, 1]);
                    Floatz resultCorrect = new Floatz((string)testeComparari[i, 2]);
                    Floatz c             = a / b;

                    if (c != resultCorrect)
                    {
                        str += String.Format(
                            "\n Test failed:Impartire #{0} nereusita.\n \n {1}/{2}={3} |corect e: {4}\n\n",
                            i, a.ToString(), b.ToString(), c.ToString(), resultCorrect.ToString()
                            );
                    }
                }
                if (str == "")
                {
                    return("Nu exista probleme la impartire.");
                }
                return(str);
            }
Beispiel #2
0
            public static string TestPow()
            {
                object[,] testeComparari = new object[, ] {
                    { "0", "9", "0,0" },
                    { "1", "0", "1,0" },
                    { "1", "1", "1,0" },
                    { "2", "1", "2,0" },
                    { "2", "3", "8,0" },
                    { "2", "10", "1024,0" },
                    { "20", "9", "512000000000,0" },
                    { "4", "0,5", "2" },
                    { "256", "0,25", "4" },
                    { "4", "0,5", "2" },
                    { "256", "0,4", "4" },
                    { "2", "0,5", "1" }
                };

                string str = "";

                for (int i = 0; i < testeComparari.GetLength(0); i++)
                {
                    Floatz a = new Floatz((string)testeComparari[i, 0]);
                    Floatz b = new Floatz((string)testeComparari[i, 1]);
                    //Console.WriteLine("{0}->{1}",b.ToString(),b.isOne());
                    string resultCorrect = (string)testeComparari[i, 2];
                    Floatz c             = Floatz.Pow(a, b);
                    if (c.ToString() != resultCorrect)
                    {
                        str += String.Format(
                            "\n Test failed:Putere #{0} nereusita.\n \n Pow({1};{2})={3} |corect e: {4}\n\n",
                            i, a.ToString(), b.ToString(), c.ToString(), resultCorrect
                            );
                    }
                }
                if (str == "")
                {
                    return("Nu exista probleme la putere.");
                }
                return(str);
            }
Beispiel #3
0
            public static string TestScadere()
            {
                object[,] testeComparari = new object[, ] {
                    { "0", "0", "0,0" },
                    { "0", "1", "-1,0" },
                    { "1", "0", "1,0" },
                    { "2", "1", "1,0" },
                    { "1,32", "1,12", "0,2" },
                    { "1,2", "1", "0,2" },
                    { "-1,2", "1,0", "-2,2" },
                    { "1", "-1,2", "2,2" },
                    { "3,46666", "0,57", "2,89666" },
                    { "10", "1", "9,0" },
                    { "101", "2", "99,0" },
                    { "204,8900000011920928955078125", "256", "-51,1099999" }
                };

                string str = "";

                for (int i = 0; i < testeComparari.GetLength(0); i++)
                {
                    Floatz a             = new Floatz((string)testeComparari[i, 0]);
                    Floatz b             = new Floatz((string)testeComparari[i, 1]);
                    string resultCorrect = (string)testeComparari[i, 2];
                    Floatz c             = a - b;
                    if (c.ToString() != resultCorrect)
                    {
                        str += String.Format(
                            "\n Test failed:Scaderea #{0} nereusita.\n \n {1}-{2}={3} |corect e: {4}\n\n",
                            i, a.ToString(), b.ToString(), c.ToString(), resultCorrect
                            );
                    }
                }
                if (str == "")
                {
                    return("Nu exista probleme la scadere.");
                }
                return(str);
            }
Beispiel #4
0
            public static string TestInmultire()
            {
                object[,] testeComparari = new object[, ] {
                    { "0,0", "0,0", "0,0" },
                    { "0", "1", "0,0" },
                    { "1", "1", "1,0" },
                    { "2", "1", "2,0" },
                    { "2", "2", "4,0" },
                    { "2", "6,2", "12,4" },
                    { "384,1789454", "-1", "-384,1789454" },
                    { "3,1415", "3,1415", "9,86902225" },
                    { "31415", "31415", "986902225" },
                    { "384,1789454", "98,87546", "37985,869948739884" },
                    { "456", "2", "912,0" }
                };

                string str = "";

                for (int i = 0; i < testeComparari.GetLength(0); i++)
                {
                    Floatz a             = new Floatz((string)testeComparari[i, 0]);
                    Floatz b             = new Floatz((string)testeComparari[i, 1]);
                    Floatz resultCorrect = new Floatz((string)testeComparari[i, 2]);
                    Floatz c             = Floatz.Multiply(a, b);

                    if (c != resultCorrect)
                    {
                        str += String.Format(
                            "\n Test failed:Inmultirea #{0} nereusita.\n \n {1}*{2}={3} |corect e: {4}\n\n",
                            i, a.ToString(), b.ToString(), c.ToString(), resultCorrect.ToString()
                            );
                    }
                }
                if (str == "")
                {
                    return("Nu exista probleme la inmultirea.");
                }
                return(str);
            }
Beispiel #5
0
            public static string TestComparari()
            {
                object[,] testeComparari = new object[, ] {
                    { "0", '<', "1", true },
                    { "1", '<', "0", false },
                    { "-1", '>', "2", false },
                    { "-1", '<', "2", true },
                    { "-1", '<', "-2", false },
                    { "-1", '>', "-2", true },
                    { "-1", '<', "0", true },
                    { "3,14159265358979323846264338327950", '>', "2,71828182845904523536028747135266", true },
                    { "-1.123123", '<', "-1.123023", true },
                    { "1,32", '>', "1,12", true },
                    { "1,2", '>', "0,2", true },
                    { "1,32", '<', "1,12", false },
                    { "1,2", '<', "0,2", false },
                    { "-1,2", '<', "1", true },
                    { "-1,2", '>', "1", false },
                    { "1", '<', "-1,2", false },
                    { "1", '>', "-1,2", true },
                    { "1,0000000000000000000", '>', "1", false },
                    { "1,0000000000000000000", '<', "1", false },
                    { "9", '<', "355", true },
                    { "355", '>', "9", true }
                };

                string str = "";

                for (int i = 0; i < testeComparari.GetLength(0); i++)
                {
                    Floatz a      = new Floatz((string)testeComparari[i, 0]);
                    Floatz b      = new Floatz((string)testeComparari[i, 2]);
                    bool   result = (bool)testeComparari[i, 3];
                    char   type   = (char)testeComparari[i, 1];
                    if (type == '<')
                    {
                        if ((a < b) != result)
                        {
                            str += String.Format("\n Test failed:Compararea #{2} nereusita.\n \n {3}<{4}={0} |corect e: {1}\n\n", (a < b), result, i, a.ToString(), b.ToString());
                        }
                    }
                    else
                    {
                        if ((a > b) != result)
                        {
                            str += String.Format("\n Test failed:Compararea #{2} nereusita.\n \n {3}>{4}={0} |corect e: {1}\n\n", (a > b), result, i, a.ToString(), b.ToString());
                        }
                    }
                }
                if (str == "")
                {
                    return("Nu exista probleme la comparari.");
                }
                return(str);
            }