Exemplo n.º 1
0
        public unsafe void Can_Add_With_Weight()
        {
            int[] firstArray  = new int[] { 10, 100, 200 };
            int[] secondArray = new int[] { 5, 50, 40 };
            int[] result      = new int[3];

            int weight = 30;

            int[] expexpectedResult = new int[]
            {
                (int)(0.3 * firstArray[0] + 0.7 * secondArray[0]),
                (int)(0.3 * firstArray[1] + 0.7 * secondArray[1]),
                (int)(0.3 * firstArray[2] + 0.7 * secondArray[2])
            };

            fixed(int *pointerToFirst = &firstArray[0], pointerToSecond = &secondArray[0], pointerToResult = &result[0])
            {
                BitmapAdditionDllManager.AddWithWeight(pointerToFirst, pointerToSecond, pointerToResult, firstArray.Length, weight);
            }

            Assert.IsTrue(Math.Abs(expexpectedResult[0] - result[0]) <= 1);
            Assert.IsTrue(Math.Abs(expexpectedResult[1] - result[1]) <= 1);
            Assert.IsTrue(Math.Abs(expexpectedResult[2] - result[2]) <= 1);
        }