示例#1
0
        static void Main(string[] args)
        {
            //////////////// Day 1 ////////////
            Average             av = new Average();
            DisplayNumber       dn = new DisplayNumber();
            MultiplicationTable mt = new MultiplicationTable();
            StringSwap          ss = new StringSwap();
            Temperature         tt = new Temperature();
            LongWord            lw = new LongWord();

            //av.FindAverage();
            //dn.GetNumber();
            //mt.FindMultiplication();
            //ss.SwapString();
            //lw.FindLongWord();
            //tt.TemperatureConversion();

            ///////////Day 2///////////////
            CubeNumber cn = new CubeNumber();
            Fibonacci  fs = new Fibonacci();

            //cn.FindCubic();
            //fs.DisplayFibonacci();

            fs.DisplayFibonacciByRecursion();
        }
        public async Task Multiplies_primes()
        {
            var expected = new int?[, ]
            {
                { null, 2, 3, 5 },
                { 2, 4, 6, 10 },
                { 3, 6, 9, 15 },
                { 5, 10, 15, 25 },
            };

            var count  = 3;
            var actual = new int?[count + 1, count + 1];

            await using var table = new MultiplicationTable(count).GetAsyncEnumerator();

            for (var rowNumber = 0; rowNumber <= count && await table.MoveNextAsync(); rowNumber++)
            {
                await using var row = table.Current.GetAsyncEnumerator();

                for (var cellNumber = 0; cellNumber <= count && await row.MoveNextAsync(); cellNumber++)
                {
                    actual[rowNumber, cellNumber] = row.Current;
                }
            }

            actual.Should().BeEquivalentTo(expected);
        }
        private static void Menu()
        {
            while (true)
            {
                string message = "\nHello user! Welcome to the functional application!" +
                                 "\n  Enter an option below:" +
                                 "\n    0 - Ending Application" +
                                 "\n    1 - Read Files" +
                                 "\n    2 - Initialize multiplication table" +
                                 "\n    3 - Calculate averages";

                Console.WriteLine(message);
                int entry = int.Parse(Console.ReadLine());

                Console.WriteLine("=========================================");
                if (entry == READ_FILES)
                {
                    ReadFiles.UseReadFiles(1);
                }
                else if (entry == MULTIPLICATION_TABLE)
                {
                    MultiplicationTable.UseMultiplicationTable(5);
                }
                else if (entry == CALCULATE_AVERAGE)
                {
                    CalculateAverage.UseCalculateAverage(5.4, 8.2);
                }
                else
                {
                    Console.WriteLine("\nApplication ending successfully!");
                    break;
                }
            }
        }
示例#4
0
        private void MultiplicationTableExport_Click(object sender, RoutedEventArgs e)
        {
            var csv = new StringBuilder();

            csv.AppendLine("*;" + string.Join(";", MultiplicationTable.GetLabels()));

            for (int i = 0; i < MultiplicationTable.Rows.Count(); i++)
            {
                csv.AppendLine(MultiplicationTable.Rows[i].ToString());
            }

            Microsoft.Win32.SaveFileDialog dialog = getDialog();

            // Show save file dialog box
            Nullable <bool> result = dialog.ShowDialog();

            // Process save file dialog box results
            if (result == true)
            {
                // Save document
                string filename = dialog.FileName;

                File.WriteAllText(filename, csv.ToString());
            }
        }
示例#5
0
        public ViewResult Table5(int id, int?highestMultiple)
        {
            var table = new MultiplicationTable()
            {
                Number = id,
                Max    = 10
            };

            if (highestMultiple != null)
            {
                table.Max = highestMultiple.Value;
            }

            //PROBLEM: controller shouldn't have business logic.
            for (int i = 1; i <= table.Max; i++)
            {
                table.Results.Add(new BinaryOperationInfo()
                {
                    Left   = table.Number,
                    Right  = i,
                    Result = table.Number * i
                });
            }

            return(View("table", table)); //generated table as the model
        }
示例#6
0
        protected override async Task WriteResponseBodyAsync(MultiplicationTable table, OutputFormatterWriteContext context, Encoding encoding, CancellationToken cancellationToken)
        {
            using var writer = new Utf8JsonWriter(context.HttpContext.Response.Body);

            writer.WriteStartArray();

            await foreach (var row in table.WithCancellation(cancellationToken))
            {
                writer.WriteStartArray();

                await foreach (var cell in row)
                {
                    if (cell.HasValue)
                    {
                        writer.WriteNumberValue(cell.Value);
                    }
                    else
                    {
                        writer.WriteNullValue();
                    }
                }

                writer.WriteEndArray();
            }

            writer.WriteEndArray();
            await writer.FlushAsync();
        }
        public void GetGrid_ZeroElementsInput_OneElementGrid()
        {
            var result = MultiplicationTable.GetGrid(new List <ulong>());

            Assert.AreEqual(1, result.GetLength(0));
            Assert.AreEqual(1, result.GetLength(1));
            Assert.AreEqual(0, result[0, 0]);
        }
示例#8
0
 public static void PhpMain()
 {
     Header("Welcome to CS2PHP");
     echo("<p>You can use echo just like in PHP</p>");
     Html.EchoTagBound(Tags.P, "Or use some helpers.");
     MultiplicationTable.ShowMultiplicationTable(10, 12);
     Footer();
 }
        public void ShouldReturnHeaders()
        {
            var target = new MultiplicationTable(new[] { 2, 3, 5 });

            Assert.Equal(2, target.Header[0]);
            Assert.Equal(3, target.Header[1]);
            Assert.Equal(5, target.Header[2]);
        }
示例#10
0
        public void Given_N_prime_numbers_should_return_N_x_N_matrix_with_prime_numbers_in_first_row()
        {
            var primes = new MultiplicationTable();
            var input = new[] { 2, 3, 5, 7 };
            var expected = input;

            Assert.Equal(expected, Enumerable.Range(1, input.Length).Select(colNum => primes.GetMatrix(input)[0, colNum]).ToArray());
        }
        public void ShouldReturnHeaders()
        {
            var target = new MultiplicationTable(new[] { 2, 3, 5 });

            Assert.Equal(2, target.Header[0]);
            Assert.Equal(3, target.Header[1]);
            Assert.Equal(5, target.Header[2]);
        }
示例#12
0
        private async void generateTablesAsync()
        {
            await Task.Run(() =>
            {
                ResultGrid.Dispatcher.Invoke(() => {
                    List <ClsPolinom.Polinom> columns = FiniteFieldLibrary.FiniteField.generateMembers(MyOrder);

                    //Prepare tables representation
                    int i = 0;
                    foreach (ClsPolinom.Polinom polinom in columns)
                    {
                        SummationTable.createRow(columns.Count());
                        SummationGrid.Columns.Add(getDataGridTemplateColumn(getPolinomTextBlock(polinom), String.Format("Polinoms[{0}]", i)));
                        SummationTable.Rows[i].Label = polinom;

                        MultiplicationTable.createRow(columns.Count());
                        MultiplicationGrid.Columns.Add(getDataGridTemplateColumn(getPolinomTextBlock(polinom), String.Format("Polinoms[{0}]", i)));
                        MultiplicationTable.Rows[i].Label = polinom;

                        i++;
                    }
                });
            });

            ResultGrid.Visibility = Visibility.Visible;

            await Task.Run(() =>
            {
                FiniteFieldLibrary.FiniteField.calculateTables(SummationTable.GetLabelPolinoms(), MyOrder, IrreduciblePolinom, ((ClsPolinom.Polinom res, int i, int j) =>
                {
                    SummationTable.Rows[i].Polinoms[j] = res;
                    ResultGrid.Dispatcher.Invoke(() =>
                    {
                        SummationGrid.ItemsSource = null;
                        SummationGrid.ItemsSource = SummationTable.Rows;
                    });
                }), ((ClsPolinom.Polinom res, int i, int j) =>
                {
                    MultiplicationTable.Rows[i].Polinoms[j] = res;
                    ResultGrid.Dispatcher.Invoke(() =>
                    {
                        MultiplicationGrid.ItemsSource = null;
                        MultiplicationGrid.ItemsSource = MultiplicationTable.Rows;
                    });
                }), () =>
                {
                    Dispatcher.Invoke(() =>
                    {
                        TableButtonSpinner.Visibility = Visibility.Hidden;
                        TableButton.IsEnabled         = true;
                        enableExportButtons();
                    });
                });
            });
        }
示例#13
0
        public void TestSmallTableAsListOfStrings()
        {
            MathTable table = MultiplicationTable.CreatePrimeMultiplicationTable(3);
            var       lst   = table.AsListOfStrings();

            Assert.AreEqual("    | 2  | 3  | 5  ", lst[0]);
            Assert.AreEqual("-------------------", lst[1]);
            Assert.AreEqual(" 2  | 4  | 6  | 10 ", lst[2]);
            Assert.AreEqual(" 3  | 6  | 9  | 15 ", lst[3]);
            Assert.AreEqual(" 5  | 10 | 15 | 25 ", lst[4]);
        }
        public void GetTable_Should_Returns_Correct_Count()
        {
            // Arrange
            IMultiplicationTable table = new MultiplicationTable();

            // Act
            IList <int> result = table.GetTable(3, 7);

            // Assert
            Assert.AreEqual(7, result.Count);
        }
示例#15
0
        static void Main(string[] args)
        {
            var kb     = new Input();
            var number = kb.Read <int>("Number?");
            var max    = kb.Read <int>("max[default 10]?", 10);

            var table = MultiplicationTable.Generate(number, max);

            foreach (var result in table.Results)
            {
                Console.WriteLine("{0} x {1} = {2}", result.Left, result.Right, result.Result);
            }
        }
        public void GetGrid_TwolementsInput_ThreeElementGrid()
        {
            var expected = new ulong[3, 3] {
                { 2, 2, 3 }, { 2, 4, 6 }, { 3, 6, 9 }
            };

            var result = MultiplicationTable.GetGrid(new List <ulong>()
            {
                2, 3
            });

            Assert.AreEqual(expected, result);
        }
示例#17
0
        public void EnumConstructorSingleTableReturnsSelectedQuizMultiple()
        {
            // Arrange
            const MultiplicationTable testMultiple = MultiplicationTable.Five;
            var engine = new MultiplicationEngine(new[] { testMultiple });
            var p      = engine.CreateRandomMultiplicationProblem();

            // Act
            int multiple = p.Multiple;

            // Assert
            Assert.AreEqual((int)testMultiple, multiple);
            Assert.IsFalse(p.IsAnswered);
        }
        private async Task ExecuteAsync(int count, int?timeout, bool throwOnCancel, IConsole console, CancellationToken cancellationToken)
        {
            using var telemetryConfiguration          = TelemetryConfiguration.CreateDefault();
            telemetryConfiguration.InstrumentationKey = Program.InstrumentationKey;

            var telemetry = new TelemetryClient(telemetryConfiguration);

            telemetry.TrackEvent(
                "CLI executing",
                new Dictionary <string, string?>
            {
                ["count"]         = count.ToString(CultureInfo.InvariantCulture),
                ["timeout"]       = timeout?.ToString(CultureInfo.InvariantCulture),
                ["throwOnCancel"] = throwOnCancel.ToString(),
            });

            if (timeout.HasValue)
            {
                cancellationToken =
                    CancellationTokenSource.CreateLinkedTokenSource(
                        cancellationToken,
                        new CancellationTokenSource(timeout.Value).Token).Token;
            }

            var options = throwOnCancel ?
                          PrimeGeneratorOptions.ThrowOnCancel :
                          PrimeGeneratorOptions.None;

            var table = new MultiplicationTable(count, options);

            try
            {
                await foreach (var row in table.WithCancellation(cancellationToken))
                {
                    await foreach (var cell in row)
                    {
                        console.Out.Write($"{cell,10}");
                    }

                    console.Out.WriteLine(); // LF
                }
            }
            catch (Exception e)
            {
                telemetry.TrackException(e);

                throw;
            }
        }
示例#19
0
        public void EnumConstructorSingleTableEvaluateReturnsFalseWhenAnswerIsNotCorrect()
        {
            // Arrange
            const MultiplicationTable testMultiple = MultiplicationTable.Five;
            var engine = new MultiplicationEngine(new[] { testMultiple });
            var p      = engine.CreateRandomMultiplicationProblem();

            p.Answer = 33; // just a number that is not a multiple of testMultiple

            // Act
            bool result = engine.Evaluate(p);

            // Assert
            Assert.IsTrue(p.IsAnswered);
            Assert.IsFalse(result);
        }
示例#20
0
        public ViewResult Table4(int id, int?highestMultiple)
        {
            var table = new MultiplicationTable()
            {
                Number = id,
                Max    = 10
            };


            if (highestMultiple != null)
            {
                table.Max = highestMultiple.Value;
            }

            return(View(table)); //generated table as the model
        }
示例#21
0
        public void EnumConstructorSingleTableEvaluateReturnsTrueWhenAnswerIsCorrect()
        {
            // Arrange
            const MultiplicationTable testMultiple = MultiplicationTable.Five;
            var engine = new MultiplicationEngine(new[] { testMultiple });
            var p      = engine.CreateRandomMultiplicationProblem();

            p.Answer = p.Multiple * p.Multiplier;

            // Act
            bool result = engine.Evaluate(p);

            // Assert
            Assert.IsTrue(p.IsAnswered);
            Assert.IsTrue(result);
        }
        public void GetTable_Should_Returns_Correct_Numbers()
        {
            // Arrange
            int[] resultArray          = new int[10];
            IMultiplicationTable table = new MultiplicationTable();

            // Act
            IList <int> result = table.GetTable(3, 5);

            result.CopyTo(resultArray, 0);

            // Assert
            Assert.AreEqual(3, resultArray[0]);
            Assert.AreEqual(6, resultArray[1]);
            Assert.AreEqual(9, resultArray[2]);
            Assert.AreEqual(12, resultArray[3]);
            Assert.AreEqual(15, resultArray[4]);
        }
示例#23
0
        private void generateTables(object sender, RoutedEventArgs e)
        {
            disableExportButtons();
            TableButtonSpinner.Visibility = Visibility.Visible;
            TableButton.IsEnabled         = false;

            SummationGrid.ItemsSource = null;
            SummationTable.Clear();;
            SummationGrid.Columns.Clear();
            SummationGrid.ItemsSource = SummationTable.Rows;

            MultiplicationGrid.ItemsSource = null;
            MultiplicationTable.Clear();
            MultiplicationGrid.Columns.Clear();
            MultiplicationGrid.ItemsSource = MultiplicationTable.Rows;

            generateTablesAsync();
        }
示例#24
0
        public ViewResult Of(int?id, int?max)
        {
            if (id == null)
            {
                Response.StatusCode = 400;
                return(View("ErrorView", (object)"Please specify the number"));
            }

            if (max == null)
            {
                max = 10;
            }

            //Controller should call Business Service methods
            //to get necessary Model Data
            var table = MultiplicationTable.Generate((int)id, (int)max);

            return(View("table", table));
        }
        public void ShouldGenerateMultiplicationTable()
        {
            var expected = new[]
            {
                new { Row = 0, Column = 0, Result = 4 },
                new { Row = 0, Column = 1, Result = 6 },
                new { Row = 0, Column = 2, Result = 10 },
                new { Row = 1, Column = 0, Result = 6 },
                new { Row = 1, Column = 1, Result = 9 },
                new { Row = 1, Column = 2, Result = 15 },
                new { Row = 2, Column = 0, Result = 10 },
                new { Row = 2, Column = 1, Result = 15 },
                new { Row = 2, Column = 2, Result = 25 },
            };

            var target = new MultiplicationTable(new[] { 2, 3, 5 });
            foreach (var item in expected)
            {
                Assert.Equal(item.Result, target[item.Column, item.Row]);
            }
        }
示例#26
0
        public sealed override async Task WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding encoding)
        {
            var data = (ApiParameters)context.Object;

            var table = new MultiplicationTable(data.Count);

            var cancellationToken =
                CancellationTokenSource.CreateLinkedTokenSource(
                    data.CancellationToken,
                    context.HttpContext.RequestAborted).Token;

            if (data.Timeout.HasValue)
            {
                cancellationToken =
                    CancellationTokenSource.CreateLinkedTokenSource(
                        cancellationToken,
                        new CancellationTokenSource(data.Timeout.Value).Token).Token;
            }

            await this.WriteResponseBodyAsync(table, context, encoding, cancellationToken);
        }
        protected override async Task WriteResponseBodyAsync(MultiplicationTable table, OutputFormatterWriteContext context, Encoding encoding, CancellationToken cancellationToken)
        {
            using var writer = context.WriterFactory(context.HttpContext.Response.Body, encoding);

            await foreach (var row in table.WithCancellation(cancellationToken))
            {
                var fieldNumber = 0;
                await foreach (var cell in row)
                {
                    if (fieldNumber++ > 0)
                    {
                        await writer.WriteAsync(",");
                    }

                    await writer.WriteAsync(cell?.ToString(CultureInfo.InvariantCulture));
                }

                await writer.WriteLineAsync();
            }

            await writer.FlushAsync();
        }
        public void ShouldGenerateMultiplicationTable()
        {
            var expected = new[]
            {
                new { Row = 0, Column = 0, Result = 4 },
                new { Row = 0, Column = 1, Result = 6 },
                new { Row = 0, Column = 2, Result = 10 },
                new { Row = 1, Column = 0, Result = 6 },
                new { Row = 1, Column = 1, Result = 9 },
                new { Row = 1, Column = 2, Result = 15 },
                new { Row = 2, Column = 0, Result = 10 },
                new { Row = 2, Column = 1, Result = 15 },
                new { Row = 2, Column = 2, Result = 25 },
            };

            var target = new MultiplicationTable(new[] { 2, 3, 5 });

            foreach (var item in expected)
            {
                Assert.Equal(item.Result, target[item.Column, item.Row]);
            }
        }
示例#29
0
        protected override async Task WriteResponseBodyAsync(MultiplicationTable table, OutputFormatterWriteContext context, Encoding encoding, CancellationToken cancellationToken)
        {
            using var writer = XmlWriter.Create(context.WriterFactory(context.HttpContext.Response.Body, encoding), new XmlWriterSettings { Async = true });

            await writer.WriteStartElementAsync(null, "table", null);

            await foreach (var row in table.WithCancellation(cancellationToken))
            {
                await writer.WriteStartElementAsync(null, "row", null);

                await foreach (var cell in row)
                {
                    await writer.WriteElementStringAsync(null, "cell", null, cell.ToString());
                }

                await writer.WriteEndElementAsync();
            }

            await writer.WriteEndElementAsync();

            await writer.FlushAsync();
        }
示例#30
0
        public void TestPrimeTableValues()
        {
            MathTable table = MultiplicationTable.CreatePrimeMultiplicationTable(3);

            Assert.AreEqual(table.ColNameAt(0), "2");
            Assert.AreEqual(table.ColNameAt(1), "3");
            Assert.AreEqual(table.ColNameAt(2), "5");
            Assert.AreEqual(table.ColNameAt(3), string.Empty);

            Assert.AreEqual(table.RowNameAt(0), "2");
            Assert.AreEqual(table.RowNameAt(1), "3");
            Assert.AreEqual(table.RowNameAt(2), "5");
            Assert.AreEqual(table.RowNameAt(3), string.Empty);

            Assert.AreEqual(table.FormattedValue(0, 0), "4");
            Assert.AreEqual(table.FormattedValue(0, 1), "6");
            Assert.AreEqual(table.FormattedValue(0, 2), "10");
            Assert.AreEqual(table.FormattedValue(1, 0), "6");
            Assert.AreEqual(table.FormattedValue(1, 1), "9");
            Assert.AreEqual(table.FormattedValue(1, 2), "15");
            Assert.AreEqual(table.FormattedValue(2, 0), "10");
            Assert.AreEqual(table.FormattedValue(2, 1), "15");
            Assert.AreEqual(table.FormattedValue(2, 2), "25");
        }
示例#31
0
        public void Given_prime_numbers_matrix_should_return_multiplication_table()
        {
            var primes = new MultiplicationTable();
            var input = new[] { 2, 3, 5, 7 };
            var expected = new[,] { { 0,  2,  3,  5,  7 },
                                    { 2,  4,  6, 10, 14 },
                                    { 3,  6,  9, 15, 21 },
                                    { 5, 10, 15, 25, 35 },
                                    { 7, 14, 21, 35, 49 } };

            Assert.Equal(expected, primes.GetMatrix(input));
        }
示例#32
0
        public static void ShouldReturnMatrix(this int[] input, int[,] expected)
        {
            var primes = new MultiplicationTable();

            Assert.Equal(expected.Length, primes.GetMatrix(input).Length);
        }
示例#33
0
        public void Given_empty_list_of_prime_numbers_should_return_argument_exception()
        {
            var primes = new MultiplicationTable();

            Assert.Throws(typeof(ArgumentException), () => primes.GetMatrix(new int[] { }));
        }
 public MultiplicationTableTest()
 {
     _underTest = new MultiplicationTable();
 }
示例#35
0
        // Method selection
        public void select(int num)
        {
            switch (num)
            {
            case 1:
                basic display = new basic();
                display.one();
                display.two();
                display.three();
                break;

            case 2:
                summation res = new summation();
                res.four();
                res.five();
                res.six();
                break;

            case 3:
                MultiplicationTable multiply = new MultiplicationTable();
                multiply.seven();
                break;

            case 4:
                PrimeNumbers printPrime = new PrimeNumbers();
                printPrime.eight();
                break;

            case 5:
                MaxNum maxi = new MaxNum();
                maxi.nine();
                break;

            case 6:
                ReverseList rev = new ReverseList();
                rev.ten();
                break;

            case 7:
                ContainsElement con = new ContainsElement();
                con.eleven();
                break;

            case 8:
                ReturnItemsOddPos oddPos = new ReturnItemsOddPos();
                oddPos.twelve();
                break;

            case 9:
                RunningTotal runTotal = new RunningTotal();
                runTotal.thirteen();
                break;

            case 10:
                Palindrome pali = new Palindrome();
                pali.fourteen();
                break;

            case 11:
                SumFunct sumF = new SumFunct();
                sumF.fifteenA();
                sumF.fifteenB();
                sumF.fifteenC();
                break;

            case 12:
                Concatenation conca = new Concatenation();
                conca.display();
                conca.seventeen();
                conca.nineteen();
                break;

            default:
                Console.WriteLine("Choose a valid option");
                break;
            }
        }
 public Task <ulong[, ]> GetPrimesAsync(int count)
 {
     return(Task.FromResult(MultiplicationTable.GetGrid(PrimeService.Instance.FindPrimes(count).ToList())));
 }