Beispiel #1
0
        public void PercentOfTestDivideByZero()
        {
            // ReSharper disable once ReturnValueOfPureMethodIsNotUsed
            Action test = () => Int16Ex.PercentOf(0, 100);

            Assert.Throws <DivideByZeroException>(test);
        }
Beispiel #2
0
        public void MayTest()
        {
            var expected = new DateTime(2000, 5, 10);
            var actual   = Int16Ex.May(10, 2000);

            Assert.Equal(expected, actual);
        }
Beispiel #3
0
        public void PercentOfTest2DivideByZero()
        {
            // ReSharper disable once ReturnValueOfPureMethodIsNotUsed
            Action test = () => Int16Ex.PercentOf(0, (Int64)100);

            test.ShouldThrow <DivideByZeroException>();
        }
        public void SeptemberTest()
        {
            var expected = new DateTime(2000, 9, 10);
            var actual   = Int16Ex.September(10, 2000);

            Assert.Equal(expected, actual);
        }
Beispiel #5
0
        public void JuneTest()
        {
            var expected = new DateTime(2000, 6, 10);
            var actual   = Int16Ex.June(10, 2000);

            Assert.Equal(expected, actual);
        }
Beispiel #6
0
        public void FebruaryTest()
        {
            var expected = new DateTime(2000, 2, 10);
            var actual   = Int16Ex.February(10, 2000);

            Assert.Equal(expected, actual);
        }
        public void AugustTest()
        {
            var expected = new DateTime(2000, 8, 10);
            var actual   = Int16Ex.August(10, 2000);

            Assert.Equal(expected, actual);
        }
Beispiel #8
0
        public void AprilTest()
        {
            var expected = new DateTime(2000, 4, 10);
            var actual   = Int16Ex.April(10, 2000);

            Assert.Equal(expected, actual);
        }
Beispiel #9
0
        /*public static int ToIndex2D(int x, int y, int width, int height)
         * {
         *  if (x < 0 || y < 0 || width <= 0 || height <= 0 || x >= width || y >= height)
         *      return -1;
         *
         *  return x + (width * y);
         * }
         *
         * public static Point FromIndex2D(int index, int width, int height)
         * {
         *  if (index < 0 || width <= 0 || height <= 0 || index >= (width * height))
         *      return new Point(-1, -1);
         *
         *
         *  int y = index / width;
         *  int x = index + (width * y);
         *
         *
         *  return new Point(x, y);
         * }*/

        /// <summary>
        /// maximum allowed matrix dimentions are 32767x32767
        /// </summary>
        /// <param name="bitmaps"></param>
        /// <returns></returns>
        public static byte[] ToByteArray_16(this Bitmap[,] bitmaps, ImageFormat format = null)
        {
            if (bitmaps.IsNullOrEmpty())
            {
                return(null);
            }

            int xParts = bitmaps.Width();
            int yParts = bitmaps.Height();

            if (!xParts.InClosedInterval(1, Int16.MaxValue))
            {
                return(null);
            }
            if (!yParts.InClosedInterval(1, Int16.MaxValue))
            {
                return(null);
            }


            List <byte> result = new List <byte>();

            result.AddRange(Int16Ex.ToBytes((Int16)xParts));
            result.AddRange(Int16Ex.ToBytes((Int16)yParts));

            Int16 x = 0, y;

            byte[] dd;
            for (; x < xParts; x++)
            {
                for (y = 0; y < yParts; y++)
                {
                    dd = bitmaps[x, y].ToByteArray(format);

                    if (dd.IsNullOrEmpty())
                    {
                        continue;
                    }

                    result.AddRange(Int16Ex.ToBytes(x));
                    result.AddRange(Int16Ex.ToBytes(y));
                    result.AddRange(Int32Ex.ToBytes(dd.Length));
                    result.AddRange(dd);
                }
            }

            if (result.IsCountLessOrEqual(24))
            {
                return(null);
            }

            return(result.ToArray());
        }
Beispiel #10
0
        public static Bitmap[,] ToBitmap2D_16(this byte[] data, int offset)
        {
            if (data.IsCountLessOrEqual(24 + offset))
            {
                return(null);
            }

            int xParts = Int16Ex.FromBytes(data);
            int yParts = Int16Ex.FromBytes(data, 2);

            if (1.IsGreaterThenAny(xParts, yParts))
            {
                return(null);
            }

            Bitmap[,] result = new Bitmap[xParts, yParts];

            int i = 4;

            for (; i < data.Length;)
            {
                int x = Int16Ex.FromBytes(data, i);
                int y = Int16Ex.FromBytes(data, i + 2);
                int l = Int32Ex.FromBytes(data, i + 4);

                if (
                    !x.InClosedInterval(0, xParts - 1) ||
                    !y.InClosedInterval(0, yParts - 1) ||
                    l <= 0)
                {
                    return(null);
                }


                byte[] packet = data.SubArray(i + 8, l);

                result[x, y] = packet.ToBitmap();

                i += (8 + l);
            }

            return(result);
        }