Exemple #1
0
        private void ApplyTest(int num, int[] arr, int expected)
        {
            Gcd calculator = new Gcd(num, arr);
            int result     = calculator.GetResult();

            Assert.AreEqual(expected, result);
        }
 public void ValidateArguments_method_throws_exception(
     int number1, int number2)
 {
     Assert.That(
         () => Gcd.GetEuclid(number1, number2),
         Throws.TypeOf(typeof(ArgumentException)));
 }
Exemple #3
0
        public void TestMeasuringOfComputingTimeGcdArray()
        {
            var path = @"..\temp\";

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            var testFile = new FileInfo(path + "test2.txt");

            if (!testFile.Exists)
            {
                testFile.Create();
            }

            var array  = new int[] { -1000, 1050, 2030, 2500 };
            var times1 = Gcd.MeasureRunningTimeGcd(array);

            times1 = Gcd.MeasureRunningTimeGcd(array);
            var times2 = Gcd.MeasureRunningTimeGcd2(array);

            times2 = Gcd.MeasureRunningTimeGcd2(array);
            using (var sw = new StreamWriter(testFile.FullName))
            {
                sw.WriteLine("Running time of gcd of array method(measured by System.Diagnostics):");
                sw.WriteLine(" Euclidean algorithm: {0,10} ticks.\n Stein's algorithm: {1,12} ticks.", times1[0],
                             times1[1]);
                sw.WriteLine("Running time of gcd of array method(measured by System.DateTime):");
                sw.WriteLine(" Euclidean algorithm: {0,10} ticks.\n Stein's algorithm: {1,12} ticks.", times2[0],
                             times2[1]);
            }

            Assert.Pass();
        }
Exemple #4
0
        public void GCD_Smoke_Test()
        {
            Assert.AreEqual(3, Gcd.Find(-9, 3));
            Assert.AreEqual(15, Gcd.Find(45, 30));

            Assert.AreEqual(1, Gcd.Find(3, 5));
        }
Exemple #5
0
        public static void GetGcd()
        {
            int n   = 50;
            int m   = 15;
            var gcd = new Gcd();

            System.Console.WriteLine("GCD({0},{1}) = {2}", n, m, gcd.Euclidean(n, m));
        }
        public void Binary_3ArgumentsThereIsAnswer(int a, int b, int c, int expected)
        {
            long ticks;
            var  actual = Gcd.Binary(a, b, c, out ticks);

            Debug.WriteLine(ticks);

            Assert.AreEqual(expected, actual);
        }
        public int GetEuclidWithTime_method_that_returns_Int32_with_several_params_works_properly(
            params int[] numbers)
        {
            double time;

            int result = Gcd.GetEuclidWithTime(out time, numbers);

            Assert.That(time, Is.Not.Zero);

            return(result);
        }
        public int GetSteinWithTime_method_that_returns_tuple_with_three_params_works_properly(
            int number1, int number2, int number3)
        {
            ValueTuple <int, double> result;

            result = Gcd.GetSteinWithTime(number1, number2, number3);

            Assert.That(result.Item2, Is.Not.Zero);

            return(result.Item1);
        }
        public int GetSteinWithTime_method_that_returns_tuple_with_several_params_works_properly(
            params int[] numbers)
        {
            ValueTuple <int, double> result;

            result = Gcd.GetSteinWithTime(numbers);

            Assert.That(result.Item2, Is.Not.Zero);

            return(result.Item1);
        }
        public int GetEuclidWithTime_method_that_returns_Int32_with_three_params_works_properly(
            int number1, int number2, int number3)
        {
            double time;

            int result = Gcd.GetEuclidWithTime(number1, number2, number3, out time);

            Assert.That(time, Is.Not.Zero);

            return(result);
        }
        public Fraction Reduce()
        {
            var gcdOperator = new Gcd();
            var gcd         = gcdOperator.Execute((ulong)Math.Abs(Numerator), Denominator);
            var negative    = Numerator < 0;

            Numerator /= (long)gcd;
            if (negative)
            {
                Numerator *= -1;
            }

            Denominator /= (ulong)gcd;

            return(this);
        }
Exemple #12
0
        public int Solution(int[] A, int[] B)
        {
            var countPairs  = 0;
            var gcdProvider = new Gcd();

            for (int i = 0; i < A.Length; i++)
            {
                var gcd = gcdProvider.GcdBinary(A[i], B[i], 1);

                var residueA = A[i] / gcd;
                var residueB = B[i] / gcd;

                if ((gcd % residueA == 0) && (gcd % residueB == 0))
                {
                    countPairs++;
                }
            }

            return(countPairs);
        }
Exemple #13
0
 /// <summary>
 /// Runs the work with user
 /// </summary>
 private static void Run()
 {
     int[] array = GetUserInput();
     if (array.Length == 2)
     {
         Result resultOfEuclidiusAlgoritmm = Gcd.GetGcd(array[0], array[1]);
         Result resultOfBinaryAlgoritmm    = Gcd.GetBinaryGcd(array[0], array[1]);
         Console.WriteLine($"Euclidius algoritmm: {resultOfEuclidiusAlgoritmm.Gcd.ToString()}; elapsed time: {resultOfEuclidiusAlgoritmm.Time.TotalMilliseconds.ToString()}");
         Console.WriteLine($"Binary algoritmm: {resultOfBinaryAlgoritmm.Gcd.ToString()}; elapsed time: {resultOfBinaryAlgoritmm.Time.TotalMilliseconds.ToString()}");
     }
     else
     {
         int   a = array[0], b = array[1];
         int[] newArray = new int[array.Length - 2];
         for (int i = 0; i < newArray.Length; i++)
         {
             newArray[i] = array[i + 2];
         }
         Result resultOfEuclidiusAlgoritmm = Gcd.GetGcd(a, b, newArray);
         Result resultOfBinaryAlgoritmm    = Gcd.GetBinaryGcd(a, b, newArray);
         Console.WriteLine($"Euclidius algoritmm: {resultOfEuclidiusAlgoritmm.Gcd.ToString()}; elapsed time: {resultOfEuclidiusAlgoritmm.Time.TotalMilliseconds.ToString()}");
         Console.WriteLine($"Binary algoritmm: {resultOfBinaryAlgoritmm.Gcd.ToString()}; elapsed time: {resultOfBinaryAlgoritmm.Time.TotalMilliseconds.ToString()}");
     }
 }
 public int GetEuclid_method_with_two_params_works_properly(
     int number1, int number2)
 => Gcd.GetEuclid(number1, number2);
Exemple #15
0
 public int CheckGcdEuclid(int a, int b)
 {
     return(Gcd.GcdEuclid(a, b));
 }
 public int GcdBinaryTest(int n1, int n2)
 {
     return(Gcd.Calculate(new BinaryGcdAlgorithm(), n1, n2));
 }
 public void GcdBinary_ArgumentExeption_Test(int n1, int n2) => Assert.Throws <ArgumentException>(() => Gcd.Calculate(new BinaryGcdAlgorithm(), n1, n2));
 public int GetEuclid_method_with_three_params_works_properly(
     int number1, int number2, int number3)
 => Gcd.GetEuclid(number1, number2, number3);
 public void GcdEuclidian_ArgumentExeption_Test(int n1, int n2) => Assert.Throws <ArgumentException>(() => Gcd.Calculate(new EuclideanGcdAlgorithm(), n1, n2));
Exemple #20
0
 public void GcdEuclidArray_CheckArgumentException(int[] array)
 {
     Assert.Throws <ArgumentException>(
         () => Gcd.GcdEuclid(array));
 }
Exemple #21
0
 public int CheckGcdSteinArray(int[] array)
 {
     return(Gcd.GcdStein(array));
 }
Exemple #22
0
 public int CheckGcdStein(int a, int b)
 {
     return(Gcd.GcdStein(a, b));
 }
Exemple #23
0
    public Lcm(int a, int b)
    {
        Gcd gcd = new Gcd(a, b);

        this.value = a / gcd.value * b;
    }
 public int GetEuclid_method_with_several_params_works_properly(
     params int[] numbers)
 => Gcd.GetEuclid(numbers);
Exemple #25
0
 public int CheckGcdEuclidArray(int[] array)
 {
     return(Gcd.GcdEuclid(array));
 }
Exemple #26
0
 public BuiltInFunctions()
 {
     // Text
     Functions["len"]         = new Len();
     Functions["lower"]       = new Lower();
     Functions["upper"]       = new Upper();
     Functions["left"]        = new Left();
     Functions["right"]       = new Right();
     Functions["mid"]         = new Mid();
     Functions["replace"]     = new Replace();
     Functions["rept"]        = new Rept();
     Functions["substitute"]  = new Substitute();
     Functions["concatenate"] = new Concatenate();
     Functions["concat"]      = new Concat();
     Functions["textjoin"]    = new Textjoin();
     Functions["char"]        = new CharFunction();
     Functions["exact"]       = new Exact();
     Functions["find"]        = new Find();
     Functions["fixed"]       = new Fixed();
     Functions["proper"]      = new Proper();
     Functions["search"]      = new Search();
     Functions["text"]        = new Text.Text();
     Functions["t"]           = new T();
     Functions["hyperlink"]   = new Hyperlink();
     Functions["value"]       = new Value(CultureInfo.CurrentCulture);
     Functions["trim"]        = new Trim();
     Functions["clean"]       = new Clean();
     Functions["unicode"]     = new Unicode();
     Functions["unichar"]     = new Unichar();
     Functions["numbervalue"] = new NumberValue();
     Functions["dollar"]      = new Dollar();
     // Numbers
     Functions["int"] = new CInt();
     // Math
     Functions["aggregate"]       = new Aggregate();
     Functions["abs"]             = new Abs();
     Functions["asin"]            = new Asin();
     Functions["asinh"]           = new Asinh();
     Functions["acot"]            = new Acot();
     Functions["acoth"]           = new Acoth();
     Functions["cos"]             = new Cos();
     Functions["cot"]             = new Cot();
     Functions["coth"]            = new Coth();
     Functions["cosh"]            = new Cosh();
     Functions["csc"]             = new Csc();
     Functions["csch"]            = new Csch();
     Functions["power"]           = new Power();
     Functions["gcd"]             = new Gcd();
     Functions["lcm"]             = new Lcm();
     Functions["sec"]             = new Sec();
     Functions["sech"]            = new SecH();
     Functions["sign"]            = new Sign();
     Functions["sqrt"]            = new Sqrt();
     Functions["sqrtpi"]          = new SqrtPi();
     Functions["pi"]              = new Pi();
     Functions["product"]         = new Product();
     Functions["ceiling"]         = new Ceiling();
     Functions["ceiling.precise"] = new CeilingPrecise();
     Functions["ceiling.math"]    = new CeilingMath();
     Functions["iso.ceiling"]     = new IsoCeiling();
     Functions["combin"]          = new Combin();
     Functions["combina"]         = new Combina();
     Functions["permut"]          = new Permut();
     Functions["permutationa"]    = new Permutationa();
     Functions["count"]           = new Count();
     Functions["counta"]          = new CountA();
     Functions["countblank"]      = new CountBlank();
     Functions["countif"]         = new CountIf();
     Functions["countifs"]        = new CountIfs();
     Functions["fact"]            = new Fact();
     Functions["factdouble"]      = new FactDouble();
     Functions["floor"]           = new Floor();
     Functions["floor.precise"]   = new FloorPrecise();
     Functions["floor.math"]      = new FloorMath();
     Functions["radians"]         = new Radians();
     Functions["roman"]           = new Roman();
     Functions["sin"]             = new Sin();
     Functions["sinh"]            = new Sinh();
     Functions["sum"]             = new Sum();
     Functions["sumif"]           = new SumIf();
     Functions["sumifs"]          = new SumIfs();
     Functions["sumproduct"]      = new SumProduct();
     Functions["sumsq"]           = new Sumsq();
     Functions["sumxmy2"]         = new Sumxmy2();
     Functions["sumx2my2"]        = new SumX2mY2();
     Functions["sumx2py2"]        = new SumX2pY2();
     Functions["seriessum"]       = new Seriessum();
     Functions["stdev"]           = new Stdev();
     Functions["stdeva"]          = new Stdeva();
     Functions["stdevp"]          = new StdevP();
     Functions["stdevpa"]         = new Stdevpa();
     Functions["stdev.s"]         = new StdevDotS();
     Functions["stdev.p"]         = new StdevDotP();
     Functions["subtotal"]        = new Subtotal();
     Functions["exp"]             = new Exp();
     Functions["log"]             = new Log();
     Functions["log10"]           = new Log10();
     Functions["ln"]              = new Ln();
     Functions["max"]             = new Max();
     Functions["maxa"]            = new Maxa();
     Functions["median"]          = new Median();
     Functions["min"]             = new Min();
     Functions["mina"]            = new Mina();
     Functions["mod"]             = new Mod();
     Functions["mode"]            = new Mode();
     Functions["mode.sngl"]       = new ModeSngl();
     Functions["mround"]          = new Mround();
     Functions["multinomial"]     = new Multinomial();
     Functions["average"]         = new Average();
     Functions["averagea"]        = new AverageA();
     Functions["averageif"]       = new AverageIf();
     Functions["averageifs"]      = new AverageIfs();
     Functions["round"]           = new Round();
     Functions["rounddown"]       = new Rounddown();
     Functions["roundup"]         = new Roundup();
     Functions["rand"]            = new Rand();
     Functions["randbetween"]     = new RandBetween();
     Functions["rank"]            = new Rank();
     Functions["rank.eq"]         = new RankEq();
     Functions["rank.avg"]        = new RankAvg();
     Functions["percentile"]      = new Percentile();
     Functions["percentile.inc"]  = new PercentileInc();
     Functions["percentile.exc"]  = new PercentileExc();
     Functions["quartile"]        = new Quartile();
     Functions["quartile.inc"]    = new QuartileInc();
     Functions["quartile.exc"]    = new QuartileExc();
     Functions["percentrank"]     = new Percentrank();
     Functions["percentrank.inc"] = new PercentrankInc();
     Functions["percentrank.exc"] = new PercentrankExc();
     Functions["quotient"]        = new Quotient();
     Functions["trunc"]           = new Trunc();
     Functions["tan"]             = new Tan();
     Functions["tanh"]            = new Tanh();
     Functions["atan"]            = new Atan();
     Functions["atan2"]           = new Atan2();
     Functions["atanh"]           = new Atanh();
     Functions["acos"]            = new Acos();
     Functions["acosh"]           = new Acosh();
     Functions["covar"]           = new Covar();
     Functions["covariance.p"]    = new CovarianceP();
     Functions["covariance.s"]    = new CovarianceS();
     Functions["var"]             = new Var();
     Functions["vara"]            = new Vara();
     Functions["var.s"]           = new VarDotS();
     Functions["varp"]            = new VarP();
     Functions["varpa"]           = new Varpa();
     Functions["var.p"]           = new VarDotP();
     Functions["large"]           = new Large();
     Functions["small"]           = new Small();
     Functions["degrees"]         = new Degrees();
     Functions["odd"]             = new Odd();
     Functions["even"]            = new Even();
     // Information
     Functions["isblank"]    = new IsBlank();
     Functions["isnumber"]   = new IsNumber();
     Functions["istext"]     = new IsText();
     Functions["isnontext"]  = new IsNonText();
     Functions["iserror"]    = new IsError();
     Functions["iserr"]      = new IsErr();
     Functions["error.type"] = new ErrorType();
     Functions["iseven"]     = new IsEven();
     Functions["isodd"]      = new IsOdd();
     Functions["islogical"]  = new IsLogical();
     Functions["isna"]       = new IsNa();
     Functions["na"]         = new Na();
     Functions["n"]          = new N();
     Functions["type"]       = new TypeFunction();
     // Logical
     Functions["if"]      = new If();
     Functions["ifs"]     = new Ifs();
     Functions["maxifs"]  = new MaxIfs();
     Functions["minifs"]  = new MinIfs();
     Functions["iferror"] = new IfError();
     Functions["ifna"]    = new IfNa();
     Functions["not"]     = new Not();
     Functions["and"]     = new And();
     Functions["or"]      = new Or();
     Functions["true"]    = new True();
     Functions["false"]   = new False();
     Functions["switch"]  = new Switch();
     Functions["xor"]     = new Xor();
     // Reference and lookup
     Functions["address"]  = new Address();
     Functions["hlookup"]  = new HLookup();
     Functions["vlookup"]  = new VLookup();
     Functions["lookup"]   = new Lookup();
     Functions["match"]    = new Match();
     Functions["row"]      = new Row();
     Functions["rows"]     = new Rows();
     Functions["column"]   = new Column();
     Functions["columns"]  = new Columns();
     Functions["choose"]   = new Choose();
     Functions["index"]    = new RefAndLookup.Index();
     Functions["indirect"] = new Indirect();
     Functions["offset"]   = new Offset();
     // Date
     Functions["date"]             = new Date();
     Functions["datedif"]          = new DateDif();
     Functions["today"]            = new Today();
     Functions["now"]              = new Now();
     Functions["day"]              = new Day();
     Functions["month"]            = new Month();
     Functions["year"]             = new Year();
     Functions["time"]             = new Time();
     Functions["hour"]             = new Hour();
     Functions["minute"]           = new Minute();
     Functions["second"]           = new Second();
     Functions["weeknum"]          = new Weeknum();
     Functions["weekday"]          = new Weekday();
     Functions["days"]             = new Days();
     Functions["days360"]          = new Days360();
     Functions["yearfrac"]         = new Yearfrac();
     Functions["edate"]            = new Edate();
     Functions["eomonth"]          = new Eomonth();
     Functions["isoweeknum"]       = new IsoWeekNum();
     Functions["workday"]          = new Workday();
     Functions["workday.intl"]     = new WorkdayIntl();
     Functions["networkdays"]      = new Networkdays();
     Functions["networkdays.intl"] = new NetworkdaysIntl();
     Functions["datevalue"]        = new DateValue();
     Functions["timevalue"]        = new TimeValue();
     // Database
     Functions["dget"]     = new Dget();
     Functions["dcount"]   = new Dcount();
     Functions["dcounta"]  = new DcountA();
     Functions["dmax"]     = new Dmax();
     Functions["dmin"]     = new Dmin();
     Functions["dsum"]     = new Dsum();
     Functions["daverage"] = new Daverage();
     Functions["dvar"]     = new Dvar();
     Functions["dvarp"]    = new Dvarp();
     //Finance
     Functions["cumipmt"]    = new Cumipmt();
     Functions["cumprinc"]   = new Cumprinc();
     Functions["dollarde"]   = new DollarDe();
     Functions["dollarfr"]   = new DollarFr();
     Functions["ddb"]        = new Ddb();
     Functions["effect"]     = new Effect();
     Functions["fvschedule"] = new FvSchedule();
     Functions["pduration"]  = new Pduration();
     Functions["rri"]        = new Rri();
     Functions["pmt"]        = new Pmt();
     Functions["ppmt"]       = new Ppmt();
     Functions["ipmt"]       = new Ipmt();
     Functions["ispmt"]      = new IsPmt();
     Functions["pv"]         = new Pv();
     Functions["fv"]         = new Fv();
     Functions["npv"]        = new Npv();
     Functions["rate"]       = new Rate();
     Functions["nper"]       = new Nper();
     Functions["nominal"]    = new Nominal();
     Functions["irr"]        = new Irr();
     Functions["mirr"]       = new Mirr();
     Functions["xirr"]       = new Xirr();
     Functions["sln"]        = new Sln();
     Functions["syd"]        = new Syd();
     Functions["xnpv"]       = new Xnpv();
     Functions["coupdays"]   = new Coupdays();
     Functions["coupdaysnc"] = new Coupdaysnc();
     Functions["coupdaybs"]  = new Coupdaybs();
     Functions["coupnum"]    = new Coupnum();
     Functions["coupncd"]    = new Coupncd();
     Functions["couppcd"]    = new Couppcd();
     Functions["price"]      = new Price();
     Functions["yield"]      = new Yield();
     Functions["yieldmat"]   = new Yieldmat();
     Functions["duration"]   = new Duration();
     Functions["disc"]       = new Disc();
     //Engineering
     Functions["bitand"]       = new BitAnd();
     Functions["bitor"]        = new BitOr();
     Functions["bitxor"]       = new BitXor();
     Functions["bitlshift"]    = new BitLshift();
     Functions["bitrshift"]    = new BitRshift();
     Functions["convert"]      = new ConvertFunction();
     Functions["bin2dec"]      = new Bin2Dec();
     Functions["bin2hex"]      = new Bin2Hex();
     Functions["bin2oct"]      = new Bin2Oct();
     Functions["dec2bin"]      = new Dec2Bin();
     Functions["dec2hex"]      = new Dec2Hex();
     Functions["dec2oct"]      = new Dec2Oct();
     Functions["hex2bin"]      = new Hex2Bin();
     Functions["hex2dec"]      = new Hex2Dec();
     Functions["hex2oct"]      = new Hex2Oct();
     Functions["oct2bin"]      = new Oct2Bin();
     Functions["oct2dec"]      = new Oct2Dec();
     Functions["oct2hex"]      = new Oct2Hex();
     Functions["delta"]        = new Delta();
     Functions["erf"]          = new Erf();
     Functions["erf.precise"]  = new ErfPrecise();
     Functions["erfc"]         = new Erfc();
     Functions["erfc.precise"] = new ErfcPrecise();
     Functions["besseli"]      = new BesselI();
     Functions["besselj"]      = new BesselJ();
     Functions["besselk"]      = new BesselK();
     Functions["bessely"]      = new BesselY();
 }
Exemple #27
0
 public void GcdEuclid_CheckArgumentException(int a, int b)
 {
     Assert.Throws <ArgumentException>(
         () => Gcd.GcdEuclid(a, b));
 }
 public int GcdEuclidianTest(int n1, int n2)
 {
     return(Gcd.Calculate(new EuclideanGcdAlgorithm(), n1, n2));
 }
Exemple #29
0
        public void Evclid_ExecutionTime_IsLessThan3000Ticks(int time)
        {
            var executionTime = Extensions.GetExecutionTime(() => Gcd.Evclid(10, 100)).Elapsed.Ticks;

            Assert.Less(executionTime, time);
        }
 public int GetStein_method_with_several_params_works_properly(
     params int[] numbers)
 => Gcd.GetStein(numbers);