Ejemplo n.º 1
0
        [InlineData(10, 11, 12, 14, 13)] // right of center missing
        public void Correct_Results_For_Four_Item_Lists(int value0, int value1, int value2, int value3, int missingNumber)
        {
            int[] values = new int[] { value0, value1, value2, value3 };
            int   result = NumberFinder.FindMissingValue(values);

            Assert.True(result == missingNumber, $"Incorrect value. Actual: {result}, Expected: {missingNumber}");
        }
Ejemplo n.º 2
0
        public void Correct_Results_For_Five_Item_Lists(int value0, int value1, int value2, int value3, int value4, int delta)
        {
            int[] values = new int[] { value0, value1, value2, value3, value4 };
            int   result = NumberFinder.FindDelta(values);

            Assert.True(result == delta, $"Incorrect value. Actual: {result}, Expected: {delta}");
        }
        public void IncorrectInput_MissingMultipleNumbers(int[] value)
        {
            // Act
            FindMissingNumberResult result = NumberFinder.FindMissingNumber(value);

            // Assert
            Assert.IsType <FindMissingNumberMultipleNumbersMissingResult>(result);
        }
Ejemplo n.º 4
0
        public void TestMethod1()
        {
            var T = new NumberFinder(3, 5);

            Assert.AreEqual(T.GetDecentNumber(2), "-1");
            Assert.AreEqual(T.GetDecentNumber(4), "-1");
            Assert.AreEqual(T.GetDecentNumber(3), "333");
        }
        public void IncorrectInput_DuplicateNumbers(int[] value)
        {
            // Act
            FindMissingNumberResult result = NumberFinder.FindMissingNumber(value);

            // Assert
            Assert.IsType <FindMissingNumberDuplicateNumbersResult>(result);
        }
Ejemplo n.º 6
0
        public void FindNextBiggerNumberAndGetTimeByTimer_with_valid_data(int number, int?expected)
        {
            long time;
            int? result = NumberFinder.FindNextBiggerNumberAndGetTimeByTimer(number, out time);

            Assert.GreaterOrEqual(time, 0);
            Assert.AreEqual(expected, result);
        }
        [InlineData(new int[] { 5, 2, 4, 14, 6, 13, 1, 9, 10, 12, 3, 7, 8 })] // Unordered
        public void CorrectInput_Expecting11(int[] value)
        {
            // Act
            FindMissingNumberResult result = NumberFinder.FindMissingNumber(value);

            // Assert
            Assert.IsType <FindMissingNumberSuccessResult>(result);
            Assert.Equal(11, (result as FindMissingNumberSuccessResult).MissingNumber);
        }
        public void IncorrectInput_NotMissingANumber()
        {
            // Arrange
            int[] arrayNoMissingNumber = new int[] { 1, 2, 3, 4, 5, 6 };

            // Act
            FindMissingNumberResult result = NumberFinder.FindMissingNumber(arrayNoMissingNumber);

            // Assert
            Assert.IsType <FindMissingNumberNotMissingANumberResult>(result);
        }
        public void IncorrectInput_EmptyArray()
        {
            // Arrange
            int[] arrayEmpty = new int[] { };

            // Act
            FindMissingNumberResult result = NumberFinder.FindMissingNumber(arrayEmpty);

            // Assert
            Assert.IsType <FindMissingNumberEmptyArrayResult>(result);
        }
Ejemplo n.º 10
0
        public void Invalid_Length_Array_Should_Throw()
        {
            // Empty array should throw
            Assert.Throws <InvalidOperationException>(() => NumberFinder.FindDelta(new int[] {}));

            // Array length of 1 should throw
            Assert.Throws <InvalidOperationException>(() => NumberFinder.FindDelta(new int[] { 0 }));

            // Array length of 2 should throw
            Assert.Throws <InvalidOperationException>(() => NumberFinder.FindDelta(new int[] { 0, 1 }));
        }
Ejemplo n.º 11
0
        public void TestNumberFinder1()
        {
            var circleProcessor = new CircleProcessor();
            var circles         = circleProcessor.FindCircles(TestImg.test_card_1);
            var nf = new NumberFinder();

            for (int i = 0; i < circles.Size; i++)
            {
                var circle = circles[i];
                var score  = nf.FindNumbers(circle, TestImg.test_card_1);
                if (i == 0)
                {
                    Assert.AreEqual(score, 1);
                }
                if (i == 1)
                {
                    Assert.AreEqual(score, 4);
                }
            }
        }
Ejemplo n.º 12
0
        public void TestNumberFinder3()
        {
            var circleProcessor = new CircleProcessor();
            var circles         = circleProcessor.FindCircles(TestImg.test_card_3);
            var nf = new NumberFinder();

            for (int i = 0; i < circles.Size; i++)
            {
                var circle = circles[i];
                var score  = nf.FindNumbers(circle, TestImg.test_card_3);
                if (i == 0)
                {
                    Assert.AreEqual(score, 2);
                }
                if (i == 1)
                {
                    //there is some bogus stuff going on here
                    //Assert.AreEqual(score, 2);
                }
            }
        }
Ejemplo n.º 13
0
 public void Null_Array_Should_Throw()
 {
     Assert.Throws <ArgumentNullException>(() => NumberFinder.FindDelta(null));
 }
Ejemplo n.º 14
0
 public void NextBiggerThan_WithNegativeNumber_ThrowArgumentException(int number)
 => Assert.Throws <ArgumentException>(() => NumberFinder.NextBiggerThan(number),
                                      message: $"Value of {nameof(number)} cannot be less zero.");
Ejemplo n.º 15
0
 public int?NextBiggerThan_WithNumberForWhichBiggerNumberDoesNotExist(int number)
 => NumberFinder.NextBiggerThan(number);
 public void NextBiggerThanArgumentOutOfRangeException(int number)
 {
     Assert.Throws <ArgumentOutOfRangeException>(() => NumberFinder.FindNextBiggerNumber(number));
 }
 public int?NextBiggerThanSimpleTests(int number) => NumberFinder.FindNextBiggerNumber(number);
 public void InsertNumberMethod_InvalidValues_ThrowArgumentException()
 {
     Assert.Throws <ArgumentException>(() => NumberFinder.NextBiggerThan(-1));
     Assert.Throws <ArgumentException>(() => NumberFinder.NextBiggerThan(-900));
 }
Ejemplo n.º 19
0
 public int?FindNextBiggerNumber_with_valid_data(int number)
 {
     return(NumberFinder.FindNextBiggerNumber(number));
 }
Ejemplo n.º 20
0
        private IPlotPOLCNTOutput ProcessFile(string path, CircleProcessor imgProcessor)
        {
            if (!File.Exists(path))
            {
                Logging.Logger.LogErrorFormat("File does not exist: {0}", path);
                return(null);
            }
            try {
                if (path.EndsWith(".zip"))
                {
                    return(null);
                }
                if (path.EndsWith(".gz"))
                {
                    var fs       = new FileStream(path, FileMode.Open);
                    var finfo    = new FileInfo(path);
                    var currFile = Path.GetFullPath(path);
                    var newFile  = currFile.Remove(currFile.Length - finfo.Extension.Length);
                    using (var newFs = new FileStream(newFile, FileMode.OpenOrCreate))
                        using (var stream = new System.IO.Compression.GZipStream(fs, System.IO.Compression.CompressionMode.Decompress))
                        {
                            stream.CopyTo(newFs);
                            Logging.Logger.LogInfoFormat("Decompressed {0} to {1}", path, newFs.Name);
                        }
                    if (Directory.Exists(newFile))
                    {
                        var newFiles = Directory.GetFiles(newFile);
                        foreach (var i in newFiles)
                        {
                            return(ProcessFile(i, imgProcessor));
                        }
                    }
                    else
                    {
                        return(ProcessFile(newFile, imgProcessor));
                    }
                }
            }
            catch (Exception ex)
            {
                Logging.Logger.LogError("Error while decompressing", ex);
            }
            var entry = new PlotPOLCNTOutput();

            Logging.Logger.LogInfo(string.Format("Processing File: {0}", path));
            int euid = 0;
            var bc   = ReadBarcode(path);

            if (!int.TryParse(bc, out euid))
            {
                Logging.Logger.LogErrorFormat("Expected Euid in barcode, got: {0}", bc);
                Logging.Logger.LogInfo("Moving on to next file...");
                return(null);
            }
            else
            {
                entry.EUID = euid;
            }

            Logging.Logger.LogInfo(string.Format("Finding circles:", path));
            var bm       = new Bitmap(path);
            var circles  = imgProcessor.FindCircles(bm);
            var midPoint = bm.Width / 2;

            Logging.Logger.LogInfo(string.Format("Finding scores:", path));
            var numFinder = new NumberFinder();

            for (int i = 0; i < circles.Size; i++)
            {
                var circle = circles[i];
                var score  = numFinder.FindNumbers(circle, bm);
                if (circle.ToArray().All(x => x.X > midPoint))
                {
                    entry.POLCNT = score;
                }
                else
                {
                    entry.Plot = score;
                }
            }
            return(entry);
        }
Ejemplo n.º 21
0
 public int?NextBiggerThan_ConcreteNumber_ReturnResult(int number)
 {
     return(NumberFinder.NextBiggerThan(number));
 }
Ejemplo n.º 22
0
 public void Zero_Delta_Should_Throw()
 {
     Assert.Throws <InvalidOperationException>(() => NumberFinder.FindMissingValue(new int[] { 0, 0, 0 }));
 }
 public int?NextBiggerThanTests(int number)
 => NumberFinder.NextBiggerThan(number);
Ejemplo n.º 24
0
 public void NextBiggerThan_NumberNotPositive_ThrowArgumentException(int number) =>
 Assert.Throws <ArgumentOutOfRangeException>(() => NumberFinder.NextBiggerThan(number));
Ejemplo n.º 25
0
 public void FindNextBiggerNumber_with_negative_number_returns_ArgumentExeption(int number)
 {
     Assert.Throws <ArgumentException>(() => NumberFinder.FindNextBiggerNumber(number));
 }