Пример #1
0
        public void TestSumm(int x, int y, int z)
        {
            Summator actualResult = new Summator(x, y);
            int      exp          = z;

            Assert.Equal(exp, actualResult.Summ());
        }
Пример #2
0
        public void SumOfDigitsShouldWorkCorrectlyWithNegativeNumber()
        {
            var summator = new Summator();
            var result   = summator.SumOfDigits(-123);

            Assert.AreEqual(6, result);
        }
Пример #3
0
        public void TestSummator(Int32 a, Int32 b, Int32 actualR, Int32 actualP, Int32 p = 0)
        {
            Register reg;
            Register reg2;
            Summator sum;
            Wire     wire;
            Wire     wire2;

            reg          = new Register();
            reg.P.Value  = a;
            reg2         = new Register();
            reg2.P.Value = b;
            sum          = new Summator("Summator");
            sum.P.Value  = p;

            wire  = new Wire(reg.Output.FirstOrDefault());
            wire2 = new Wire(reg2.Output.FirstOrDefault());
            wire.ConnectTo(sum.Input.FirstOrDefault());
            wire2.ConnectTo(sum.Input.LastOrDefault());

            reg.Step();
            reg2.Step();
            wire.Execute();
            wire2.Execute();
            sum.Sum();

            Assert.AreEqual(sum.Output.FirstOrDefault().Value, actualR, "a=" + a + ", b=" + b + ", p=" + p);
            Assert.AreEqual(sum.P.Value, actualP, "a=" + a + ", b=" + b + ", p=" + p);
        }
Пример #4
0
        public void SumMinusOneAndMinusOneShouldEqualMinusTwo()
        {
            var summator = new Summator();
            var result   = summator.Sum(-1, -1);

            Assert.AreEqual(-2, result);
        }
Пример #5
0
        static async void SumAndShowResultAsync(uint value, Summator summator, CancellationToken cancellation)
        {
            int resultCursorTop  = default(int);
            int resultCursorLeft = default(int);

            EnqueueConsoleAction(() =>
            {
                Console.Write("Calculating sum of {0} integers...Result: ", value);
                // save position to update result after calculation
                resultCursorTop  = Console.CursorTop;
                resultCursorLeft = Console.CursorLeft;
                Console.WriteLine();
            });
            var result = await summator.SumAsync(value, cancellation);

            string report = result.Cancelled
                                ? "cancelled"
                                : result.Sum.ToString();

            EnqueueConsoleAction(() =>
            {
                var cursorTop  = Console.CursorTop;
                var cursorLeft = Console.CursorLeft;
                // update result, then go back to current position
                Console.SetCursorPosition(resultCursorLeft, resultCursorTop);
                Console.Write(report);
                Console.SetCursorPosition(cursorLeft, cursorTop);
            });
        }
Пример #6
0
        public void SumInt32MaxValueAndInt32MaxValueShouldProduceCorrectResult()
        {
            var summator = new Summator();
            var result   = summator.Sum(int.MaxValue, int.MaxValue);

            Assert.AreEqual((long)int.MaxValue + int.MaxValue, result);
        }
 public void GetZeroReturnsZero()
 {
     var summator = new Summator();
     var privateObject = new PrivateObject(summator);
     var getZeroValue = privateObject.Invoke("GetZero");
     Assert.AreEqual(0, getZeroValue);
 }
Пример #8
0
        public void SumInt32MaxValueAndInt32MinValueShouldEqualMinusOne()
        {
            var summator = new Summator();
            var result   = summator.Sum(int.MaxValue, int.MinValue);

            Assert.AreEqual(-1, result);
        }
Пример #9
0
    static void Main()
    {
        string sequence    = Console.ReadLine();
        long   sumSequence = Summator.GetSumSequence(sequence);

        Console.WriteLine(sumSequence);
    }
Пример #10
0
        public void SumTwoPlusTwoShouldEqualFour()
        {
            var summator = new Summator();
            var result   = summator.Sum(2, 2);

            Assert.AreEqual(4, result);
        }
Пример #11
0
        public void SumOfDigitsShouldWorkCorrectlyWithMillions()
        {
            var summator = new Summator();
            var result   = summator.SumOfDigits(1111111);

            Assert.AreEqual(7, result);
        }
Пример #12
0
        public void SumOfDigitsShouldWorkCorrectlyWithLongNumber()
        {
            var summator = new Summator();
            var result   = summator.SumOfDigits(9876543210);

            Assert.AreEqual(45, result);
        }
Пример #13
0
        public void SumOfDigitsShouldWorkCorrectlyWithZero()
        {
            var summator = new Summator();
            var result   = summator.SumOfDigits(0);

            Assert.AreEqual(0, result);
        }
Пример #14
0
        static void Test()
        {
            //Calculate x+y
            var summ  = new Summator();
            var summ2 = new Summator();
            var summ3 = new Summator();
            var str   = new Stringer();

            var one   = new InPoint(new IntColor(1));
            var one2  = new OutPoint(new IntColor(1));
            var two   = new InPoint(new IntColor(2));
            var three = new OutPoint(new IntColor(3));
            var four  = new OutPoint(new IntColor(5));
            var mix1  = new MixNode();

            one.ConnectTo(summ);
            two.ConnectTo(summ);

            one2.ConnectTo(summ).ConnectTo(summ2);
            three.ConnectTo(summ2).ConnectTo(str);

            four.ConnectTo(summ2);
            summ.ConnectTo(summ3);
            summ2.ConnectTo(summ3);
            summ3.ConnectTo(str);
            new OutPoint(new IntColor(6)).ConnectTo(str);
            //str.ConnectTo(mix1);
            // new OutPoint(new StringColor("abba")).ConnectTo(mix1);/**/
            // graph.Add(new ColorableClass[] { one, two, one2, three });
            graph.Add(new ConnectionPoint[] { one, two, one2, three, four });
            graph.OnFinish += OnFinish;
            graph.StartAsync();
        }
Пример #15
0
        static int Sum(int x, int y)
        {
            var xNode    = new InPoint(new IntColor(x));
            var yNode    = new InPoint(new IntColor(y));
            int res      = 0;
            var summator = new Summator();

            //connect x and y to summato
            xNode.ConnectTo(summator);
            yNode.ConnectTo(summator);

            //both x and y will recieve the same result in this text, so add just one of them
            graph.Add(xNode);
            graph.OnFinish += delegate(GraphResult result)
            {
                GraphPath path = result[xNode];
                if (path != null)
                {
                    var color = path.LastColor as IntColor;
                    if (color != null)
                    {
                        res = color.Value;
                    }
                    //sum is list of transitions of first value — result is the last one.
                }
            };

            graph.Start();
            return(res);
        }
Пример #16
0
        public void TestX()
        {
            int      x            = 10;
            Summator actualResult = new Summator(x);
            int      exp          = x;

            Assert.Equal(exp, actualResult.X);
        }
Пример #17
0
        public void TwoItemsInArray()
        {
            var testArray = new int[2] {
                2, 2
            };

            Assert.AreEqual(4, Summator.GetSumOfMinElements(testArray));
        }
Пример #18
0
        public void TestY()
        {
            int      y            = 31;
            Summator actualResult = new Summator(0, y);
            int      exp          = y;

            Assert.Equal(exp, actualResult.Y);
        }
Пример #19
0
        public void SeveralItemsInArray()
        {
            var testArray = new int[5] {
                -10, 5, 0, 7, 167
            };

            Assert.AreEqual(-10, Summator.GetSumOfMinElements(testArray));
        }
Пример #20
0
        public void OneItemInArray()
        {
            var testArray = new int[1] {
                10
            };

            Assert.AreEqual(10, Summator.GetSumOfMinElements(testArray));
        }
Пример #21
0
        public void GetZeroReturnsZero()
        {
            var summator      = new Summator();
            var privateObject = new PrivateObject(summator);
            var getZeroValue  = privateObject.Invoke("GetZero");

            Assert.AreEqual(0, getZeroValue);
        }
Пример #22
0
        public static void Main()
        {
            var summator      = new Summator();
            var privateObject = new PrivateObject(summator);
            var result        = privateObject.Invoke("GetSum", 12, 13);

            System.Console.WriteLine(result);
        }
Пример #23
0
        public void SummatorTest(long value1, long value2, long expectedSumm)
        {
            //Act
            long actualSumm = Summator.Summ(value1, value2);

            //Assert
            Assert.Equal(expectedSumm, actualSumm);
        }
Пример #24
0
        public void SumOfDigitsShouldWorkCorrectlyForADigit()
        {
            // Arange
            var summator = new Summator();

            // Act
            var result = summator.SumOfDigits(8);

            // Assert
            Assert.AreEqual(8, result);
        }
Пример #25
0
        public void SetUp()
        {
            _sum             = 0;
            _nEventsReceived = 0;
            _numberSource    = Substitute.For <INumberSource>();
            _uut             = new Summator(_numberSource);

            _uut.SumChanged += (o, args) =>
            {
                _sum = args.Sum;
                ++_nEventsReceived;
            };
        }
Пример #26
0
        /// <summary>
        /// TODO: write the documentation
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="C"></typeparam>
        /// <param name="estimatedY"></param>
        /// <param name="realY"></param>
        /// <returns></returns>
        public static Numeric <T, C> LeastSquares_RSS <T, C>(IList <T> estimatedY, IList <T> realY) where C : ICalc <T>, new()
        {
            Summator <T> summator = new Summator <T>(Numeric <T, C> .Zero, Numeric <T, C> .Calculator.sum);

            Func <int, T> memberFormula = delegate(int i)
            {
                Numeric <T, C> simpleDif = Numeric <T, C> .Calculator.dif(estimatedY[i], realY[i]);

                return(simpleDif * simpleDif);
            };

            return(summator.Sum_SmallerToBigger(memberFormula, 0, estimatedY.Count - 1, Numeric <T, C> .TComparer));
        }
Пример #27
0
        public void TooManyItemsInArray()
        {
            var testArray = new int[1000000];
            var random    = new Random();

            for (int i = 0; i < testArray.Length - 1; i++)
            {
                testArray[i] = random.Next();
            }
            testArray[10] = -10;
            testArray[20] = -20;

            Assert.AreEqual(-30, Summator.GetSumOfMinElements(testArray));
        }
Пример #28
0
        /// <summary>
        /// TODO: write the documentation
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="C"></typeparam>
        /// <param name="realY"></param>
        /// <param name="averageY"></param>
        /// <returns></returns>
        public static Numeric <T, C> LeastSquares_TSS <T, C>(IList <T> realY, T averageY) where C : ICalc <T>, new()
        {
            if (averageY == null)
            {
                averageY = realY.SampleAverage <T, C>();
            }

            Summator <T> summator = new Summator <T>(Numeric <T, C> .Zero, Numeric <T, C> .Calculator.sum);

            Func <int, T> memberFormula = delegate(int i)
            {
                Numeric <T, C> simpleDif = Numeric <T, C> .Calculator.dif(realY[i], averageY);

                return(simpleDif * simpleDif);
            };

            return(summator.Sum_SmallerToBigger(memberFormula, 0, realY.Count - 1, Numeric <T, C> .TComparer));
        }
Пример #29
0
        static void Main(string[] args)
        {
            var summator = new Summator();

            Console.WriteLine("Summator v1.0");
            Console.WriteLine();

            var value = ProcessInput();

            while (true)
            {
                using (var cancellationSource = new CancellationTokenSource())
                {
                    var cancellation = cancellationSource.Token;
                    SumAndShowResultAsync(value, summator, cancellation);
                    value = ProcessInput();
                    cancellationSource.Cancel();
                }
            }
        }
Пример #30
0
        static void Test()
        {
            //Calculate x+y
            var summ = new Summator();
            var summ2 = new Summator();
            var summ3 = new Summator();
            var str = new Stringer();

            var one = new InPoint(new IntColor(1));
            var one2 = new OutPoint(new IntColor(1));
            var two = new InPoint(new IntColor(2));
            var three = new OutPoint(new IntColor(3));
            var four = new OutPoint(new IntColor(5));
            var mix1 = new MixNode();

            one.ConnectTo(summ);
            two.ConnectTo(summ);

            one2.ConnectTo(summ).ConnectTo(summ2);
            three.ConnectTo(summ2).ConnectTo(str);

            four.ConnectTo(summ2);
            summ.ConnectTo(summ3);
            summ2.ConnectTo(summ3);
            summ3.ConnectTo(str);
            new OutPoint(new IntColor(6)).ConnectTo(str);
            //str.ConnectTo(mix1);
            // new OutPoint(new StringColor("abba")).ConnectTo(mix1);/**/
            // graph.Add(new ColorableClass[] { one, two, one2, three });
            graph.Add(new ConnectionPoint[] { one, two, one2, three, four });
            graph.OnFinish += OnFinish;
            graph.StartAsync();
        }
Пример #31
0
        public void EmptyArray()
        {
            var testArray = new int[0];

            Assert.AreEqual(0, Summator.GetSumOfMinElements(testArray));
        }
Пример #32
0
        static int Sum(int x, int y)
        {
            var xNode = new InPoint(new IntColor(x));
            var yNode = new InPoint(new IntColor(y));
            int res = 0;
            var summator = new Summator();

            //connect x and y to summato
            xNode.ConnectTo(summator);
            yNode.ConnectTo(summator);

            //both x and y will recieve the same result in this text, so add just one of them
            graph.Add(xNode);
            graph.OnFinish += delegate(GraphResult result)
                {
                    GraphPath path = result[xNode];
                    if (path != null)
                    {
                        var color = path.LastColor as IntColor;
                        if (color != null)
                            res = color.Value;
                        //sum is list of transitions of first value — result is the last one.

                    }

                };

            graph.Start();
            return res;
        }
 public void SumMinusOneAndMinusOneShouldEqualMinusTwo()
 {
     var summator = new Summator();
     var result = summator.Sum(-1, -1);
     Assert.AreEqual(-2, result);
 }
Пример #34
0
 public ActionResult Index(Summator summator)
 {
     summator.Result = SumNumbers(summator.FirstNumber, summator.SecondNumber);
     return(View(summator));
 }
 public void SumTwoPlusTwoShouldEqualFour()
 {
     var summator = new Summator();
     var result = summator.Sum(2, 2);
     Assert.AreEqual(4, result);
 }
 public void SumInt32MaxValueAndInt32MinValueShouldEqualMinusOne()
 {
     var summator = new Summator();
     var result = summator.Sum(int.MaxValue, int.MinValue);
     Assert.AreEqual(-1, result);
 }
 public void SumInt32MaxValueAndInt32MaxValueShouldProduceCorrectResult()
 {
     var summator = new Summator();
     var result = summator.Sum(int.MaxValue, int.MaxValue);
     Assert.AreEqual((long)int.MaxValue + int.MaxValue, result);
 }