예제 #1
0
        public void TestSimpleCount()
        {
            var testBitmap = TestingHelper.GetTestBitmap();
            using (var provider = new SlowBitmapPixelProvider(testBitmap, false))
            {
                var scanner = new DefaultScanner(provider);

                int count = scanner.Count();
                Assert.AreEqual(testBitmap.Width * testBitmap.Height, count);

                count = scanner.Count(Colors.Black);
                Assert.AreEqual(18, count); // There are exactly 18 Black pixels

                int trues = 0;

                count = scanner.Count((x, y, c) =>
                                          {
                                              if (TestingHelper.GetRandomBool())
                                              {
                                                  ++trues;
                                                  return true;
                                              }
                                              return false;
                                          });
                Assert.AreEqual(trues, count);
            }
        }
예제 #2
0
        public void TestSimpleFindPixels()
        {
            var testBitmap = TestingHelper.GetTestBitmap();
            using (var provider = new SlowBitmapPixelProvider(testBitmap, false))
            {
                var scanner = new DefaultScanner(provider);

                var iterator = scanner.FindPixels(Colors.White);
                int counter = 0;
                foreach (var pixel in iterator)
                {
                    Assert.AreEqual(4, pixel.X);
                    Assert.AreEqual(8, pixel.Y);
                    ++counter;
                }
                Assert.AreEqual(1, counter);
            }

            using (var provider = new SlowBitmapPixelProvider(testBitmap))
            {
                var scanner = new DefaultScanner(provider);

                var iterator = scanner.FindPixels(Colors.Black);
                int counter = iterator.Count();
                Assert.AreEqual(18, counter); // There are exactly 18 Black pixels
            }
        }
예제 #3
0
 public void TestSimple()
 {
     var testBitmap = TestingHelper.GetTestBitmap();
     using (var provider = new SlowBitmapPixelProvider(testBitmap))
     {
         var scanner = new DefaultScanner(provider);
     }
 }
예제 #4
0
        public void TestSimpleAny()
        {
            var testBitmap = TestingHelper.GetTestBitmap();
            using (var provider = new SlowBitmapPixelProvider(testBitmap))
            {
                var scanner = new DefaultScanner(provider);

                bool actual = scanner.Any(Colors.White);
                Assert.AreEqual(true, actual);

                actual = scanner.Any(new NativeColor(255, 255, 255, 255));
                Assert.AreEqual(true, actual);
            }
        }
예제 #5
0
        public void TestViewForEach()
        {
            var testBitmap = TestingHelper.GetTestBitmap();
            using (var provider = new SlowBitmapPixelProvider(testBitmap))
            {
                var scanner = new DefaultScanner(provider)
                                  {
                                      View = new Rectangle(3, 3, 2, 2)
                                  };

                var counter = 0;
                scanner.ForEach((x, y, c) => ++counter);

                int expected = scanner.View.Width * scanner.View.Height;
                int actual = counter;
                Assert.AreEqual(expected, actual);
            }
        }
예제 #6
0
        public void TestSimpleTolerance()
        {
            var testBitmap = TestingHelper.GetToleranceBitmap();
            using (var provider = new SlowBitmapPixelProvider(testBitmap, false))
            {
                var scanner = new DefaultScanner(provider);
                bool actual = scanner.Any(new NativeColor(255, 100, 100, 100), new ColorTolerance(60, true));
                Assert.AreEqual(true, actual);

                actual = scanner.Any(new NativeColor(255, 100, 100, 100), new ColorTolerance(60, false));
                Assert.AreEqual(true, actual);

                actual = scanner.Any(new NativeColor(255, 100, 100, 100), new ColorTolerance(30, true));
                Assert.AreEqual(false, actual);

                actual = scanner.Any(new NativeColor(255, 100, 100, 100), new ColorTolerance(30, false));
                Assert.AreEqual(false, actual);
            }
        }
예제 #7
0
        public void TestSimpleForEach()
        {
            var testBitmap = TestingHelper.GetTestBitmap();
            using (var provider = new SlowBitmapPixelProvider(testBitmap))
            {
                var scanner = new DefaultScanner(provider);
                var counter = 0;
                scanner.ForEach((x, y, c) => ++counter);

                int expected = testBitmap.Width * testBitmap.Height;
                int actual = counter;
                Assert.AreEqual(expected, actual);
            }
        }