コード例 #1
0
        public void Should_produces_the_expected_output_when_given_transactions()
        {
            var input = new[] { "10", "1 42", "2", "1 14", "3", "1 28", "3", "1 60", "1 78", "2", "2" };

            var isFirst = true;
            var printer = new FakePrinter("{0:#}");
            var sut     = new ATaleOfTwoStacks(printer);

            foreach (var transaction in input)
            {
                if (isFirst)
                {
                    isFirst = false;
                }
                else
                {
                    sut.ParseTrasaction(transaction);
                }
            }

            var output = new[] { "14", "14" };
            var i      = 0;

            foreach (var s in output)
            {
                Assert.Equal(s, printer.Printed[i++].ToString());
            }
        }
        public void SetWriterCorrectly_WhenPassedAValidWriter()
        {
            // arrange and act
            var writer  = new Mock <IWriter>();
            var printer = new FakePrinter(writer.Object);

            // assert
            Assert.AreSame(writer.Object, printer.TestWriter);
        }
コード例 #3
0
            public void ShouldCreatePDFFile()
            {
                using (var app = new App(testing: true)) {
                  var printer = new FakePrinter();
                  var ctrl = new GateInController(printer, app);
                  var result = ctrl.CreateTicket("1234");

                  Assert.Equal(true, printer.HasPrinted);
                }
            }
コード例 #4
0
        public void Should_return_number_of_words_when_find_for_prefix()
        {
            var input   = new[] { "CAR", "CARD", "CARDAN", "TRY", "TRIES", "TRIED" };
            var printer = new FakePrinter("{0:#}");
            var tries   = new Tries();

            foreach (var s in input)
            {
                tries.Add(s);
            }

            var cCount = tries.Find("C");

            Assert.Equal(3, cCount);
            var carCount = tries.Find("CAR");

            Assert.Equal(3, carCount);
            var cardCount = tries.Find("CARD");

            Assert.Equal(2, cardCount);
            var cardanCount = tries.Find("CARDAN");

            Assert.Equal(1, cardanCount);

            var tCount = tries.Find("T");

            Assert.Equal(3, tCount);
            var trCount = tries.Find("TR");

            Assert.Equal(3, trCount);
            var tryCount = tries.Find("TRY");

            Assert.Equal(1, tryCount);
            var trieCount = tries.Find("TRIE");

            Assert.Equal(2, trieCount);
            var triesCount = tries.Find("TRIES");

            Assert.Equal(1, triesCount);
            var triedCount = tries.Find("TRIED");

            Assert.Equal(1, triedCount);

            var nCount = tries.Find("N");

            Assert.Equal(0, nCount);

            tries.Print(printer);

            foreach (var s in input)
            {
                Assert.Contains(s, printer.Printed);
            }
            Assert.Equal(6, printer.Printed.Count);
        }
コード例 #5
0
        public void Should_sort_an_array(int[] a, int numSwaps, int firstElement, int lastElement)
        {
            var printer = new FakePrinter();
            var sort    = new BubbleSort(printer);

            sort.Sort(a);
            AssertHelpers.AssertIsSorted(a);
            Assert.Equal($"Array is sorted in {numSwaps} swaps.", printer.Printed[0]);
            Assert.Equal($"First Element: {firstElement}", printer.Printed[1]);
            Assert.Equal($"Last Element: {lastElement}", printer.Printed[2]);
        }
コード例 #6
0
            public void ShouldCreatedPDFFile()
            {
                using (var app = new App(testing: true)) {
                  var printer = new FakePrinter();
                  var ctrl = new GateInController(printer, app);

                  ctrl.CreateTicket("000");

                  Assert.True(printer.hasPrinted);
                }
            }
コード例 #7
0
            public void ShouldCreatePdfFile()
            {
                using (var app = new App(testing: true))
                {
                    var printer = new FakePrinter();
                    var ctrl    = new GateInController(printer, app);

                    ctrl.CreateTicket("000");

                    Assert.True(printer.HasPrinted);
                }
            }
コード例 #8
0
        public void PrintDocuments_WithValidPrinter_PrintsAllDocuments()
        {
            var documents = new[]
            {
                TestUtils.CreateRandom <StubDocument>(),
                TestUtils.CreateRandom <StubDocument>(),
            };

            var printer = new FakePrinter(true);

            var printManager = CreateSystemUnderTest(printer);

            printManager.PrintDocuments(documents);

            Assert.That(printer.PrintedDocuments, Is.EquivalentTo(documents));
        }
コード例 #9
0
        public void Should_construct_a_valid_tries_when_adding_strings()
        {
            var input   = new[] { "CAR", "CARD", "CARDAN" };
            var printer = new FakePrinter("{0:#}");
            var tries   = new Tries();

            foreach (var s in input)
            {
                tries.Add(s);
            }
            tries.Print(printer);
            Assert.Equal("CAR", printer.Printed[0]);
            Assert.Equal("CARD", printer.Printed[1]);
            Assert.Equal("CARDAN", printer.Printed[2]);

            Assert.Equal(3, printer.Printed.Count);
        }
コード例 #10
0
        public void Should_calculate_running_median_when_adding_integers()
        {
            var printer = new FakePrinter("{0:0.0}");
            var sut     = new FindTheRunningMedian(printer);
            var input   = new[] { 12, 4, 5, 3, 8, 7 };
            var output  = new[] { "12.0", "8.0", "5.0", "4.5", "5.0", "6.0" };

            foreach (var i in input)
            {
                sut.Add(i);
            }

            var j = 0;

            foreach (var s in output)
            {
                Assert.Equal(s, printer.Printed[j++]);
            }
        }
コード例 #11
0
        public void Should_treat_contact_operations_when_received()
        {
            var input  = new[] { "add hack", "add hackerrank", "find hac", "find hak" };
            var output = new[] { 2, 0 };

            var printer  = new FakePrinter("{0:0}");
            var contacts = new Contacts(printer);

            foreach (var s in input)
            {
                contacts.TreatTransaction(s);
            }

            var i = 0;

            foreach (var o in output)
            {
                Assert.Equal(o, int.Parse((string)printer.Printed[i++]));
            }
        }
コード例 #12
0
        public void Should_print_in_order_when_calling_in_order_print()
        {
            var printer = new FakePrinter();
            var values  = new[] { 10, 10, 12, 5, 9, 15 };
            var bt      = CreateTreeWithValues(values);

            bt.PrintInOrder(printer);

            var lastValue = int.MinValue;

            foreach (var p in printer.Printed)
            {
                var value = (int)p;
                Assert.True(lastValue <= value);
                lastValue = value;
            }
            var orderedValues = values.OrderBy(i => i).ToArray();
            var printedValues = printer.Printed.Select(o => (int)o).ToArray();

            Assert.Equal(orderedValues, printedValues);
        }