Example #1
0
        public static RemoteCommand Deserialize(Message message)
        {
            ArgumentCheck.IsNull(message, "message");

            var jsonData = Encoding.UTF8.GetString(message.GetBytes());

            return(JsonConvert.DeserializeObject <RemoteCommand>(jsonData));
        }
Example #2
0
        public static Message Serialize(object obj)
        {
            ArgumentCheck.IsNull(obj, "obj");

            var jsonData = JsonConvert.SerializeObject(obj);

            return(new Message(Encoding.UTF8.GetBytes(jsonData)));
        }
        /// <summary>
        /// MSTest doesn't support comparing jagged arrays
        /// </summary>
        /// <param name="expected">expected value</param>
        /// <param name="actual">actuall value</param>
        public static void AreEqual(int[][] expected, int [][] actual)
        {
            ArgumentCheck.IsNull(expected, nameof(expected));
            ArgumentCheck.IsNull(actual, nameof(actual));

            Assert.AreEqual(expected.Length, actual.Length, "arrays not the same length");
            for (int i = 0; i < expected.Length; i++)
            {
                CollectionAssert.AreEqual(expected[i], actual[i]);
            }
        }
        public IEnumerable <int[]> GetAdjacentIntegers(GridAdjacentIntegerWindow gridWindow)
        {
            ArgumentCheck.IsNull(gridWindow, nameof(gridWindow));

            int[] current = new int[gridWindow.WindowSize];
            for (int i = 0; i < gridWindow.WindowSize; i++)
            {
                current[i] = gridWindow.GridData[gridWindow.MinY + i][gridWindow.MaxX - i];
            }

            yield return(current);
        }
Example #5
0
        public void VisitGridWindow(GridAdjacentIntegerWindow gridWindow)
        {
            ArgumentCheck.IsNull(gridWindow, nameof(gridWindow));

            var max = _upAdjacentGridIntegers.GetAdjacentIntegers(gridWindow)
                      .Concat(_rightAdjacentGridIntegers.GetAdjacentIntegers(gridWindow))
                      .Concat(_rightUpAdjacentGridIntegers.GetAdjacentIntegers(gridWindow))
                      .Concat(_rightDownAdjacentGridIntegers.GetAdjacentIntegers(gridWindow))
                      .Select(Product)
                      .Max();

            if (max > LargestProduct)
            {
                LargestProduct = max;
            }
        }
        public void VisitGridWindow(GridAdjacentIntegerWindow gridWindow)
        {
            ArgumentCheck.IsNull(gridWindow, nameof(gridWindow));

            var distinct = _upAdjacentGridIntegers.GetAdjacentIntegers(gridWindow)
                           .Concat(_downAdjacentGridIntegers.GetAdjacentIntegers(gridWindow))
                           .Concat(_leftAdjacentGridIntegers.GetAdjacentIntegers(gridWindow))
                           .Concat(_rightAdjacentGridIntegers.GetAdjacentIntegers(gridWindow))
                           .Concat(_leftUpAdjacentGridIntegers.GetAdjacentIntegers(gridWindow))
                           .Concat(_leftDownAdjacentGridIntegers.GetAdjacentIntegers(gridWindow))
                           .Concat(_rightUpAdjacentGridIntegers.GetAdjacentIntegers(gridWindow))
                           .Concat(_rightDownAdjacentGridIntegers.GetAdjacentIntegers(gridWindow))
                           .Select(a => Tuple.Create(a[0], a[1], a[2]))
                           .Distinct();

            _distinct3Adjacent.AddRange(distinct);
        }
Example #7
0
        public RemoteCameraViewModel(CaptureElement captureElement)
        {
            // Check if CaptureElement is not null and throw an exception accordingly
            ArgumentCheck.IsNull(captureElement, "captureElement");

            // Store reference to the CaptureElement
            this.captureElement = captureElement;

            // Instantiate CameraCapture and ImageProcessor
            cameraCapture  = new CameraCapture();
            ImageProcessor = new ImageProcessor(cameraCapture);

            // Instantiate CloudHelper
            CloudHelper = new CloudHelper();

            // Instantiate AnomalyDetector
            AnomalyDetector = new AnomalyDetector();
        }
        /// <summary>
        /// A very basic method to assert an exception was thrown.
        /// This is prefereable to ExpectedExceptionAttribue because I can check the exeption message
        /// and it follows the Assert. pattern
        /// </summary>
        /// <typeparam name="TExpectedException">The Type of exception that should be thrown</typeparam>
        /// <param name="methodUnderTest">method under test</param>
        /// <param name="message">the expected message. Ignored if null or empty</param>
        public static void AssertThrows <TExpectedException>(Action methodUnderTest, string message) where TExpectedException : Exception
        {
            ArgumentCheck.IsNull(methodUnderTest, nameof(methodUnderTest));
            var expectedExceptionType = typeof(TExpectedException);

            try
            {
                methodUnderTest();
                Assert.Fail($"Expected exception { expectedExceptionType.Name } { message }");
            }
            catch (Exception e)
            {
                Assert.AreEqual(expectedExceptionType, e.GetType());
                if (!string.IsNullOrEmpty(message))
                {
                    Assert.AreEqual(message, e.Message);
                }
            }
        }
Example #9
0
        public ImageProcessor(CameraCapture cameraCapture)
        {
            ArgumentCheck.IsNull(cameraCapture, "cameraCapture");

            this.cameraCapture = cameraCapture;
        }