Beispiel #1
0
        public static TimeSpan TimeForGetLayers(int iterations, IEnumerable <int> layersToCheck = null)
        {
            var layerMasking = new LayerMasker(POSSIBLE_LAYERS.Length);

            var stopwatch = new Stopwatch();

            int[] layers = layersToCheck == null ? new int[] { 0, 2, 5 } : layersToCheck.ToArray();

            uint mask = layerMasking.Mask(layers);

            // For caching
            int myLayer;

            foreach (var i in layerMasking.Layers(mask))
            {
                myLayer = i;
            }

            stopwatch.Start();
            for (int it = 0; it < iterations; it++)
            {
                foreach (var i in layerMasking.Layers(mask))
                {
                    myLayer = i;
                }
            }
            stopwatch.Stop();

            return(stopwatch.Elapsed);
        }
Beispiel #2
0
    public int SumLayersInAllMask()
    {
        int sum = 0;

        foreach (int layer in _masker.Layers(_allMask))
        {
            sum += layer;
        }
        return(sum);
    }
Beispiel #3
0
        public void GetLayers()
        {
            var masker = new LayerMasker();

            int[] layers = { 0, 2, 5 };

            var mask        = masker.Mask(layers);
            var layerReturn = masker.Layers(mask).ToEnumerable().ToArray();

            layers = layers.OrderByDescending(i => i).ToArray();

            _output.WriteLine("Actual layers");
            _output.WriteLine(layers.ExtendToString());
            _output.WriteLine("Returned layers:");
            _output.WriteLine(layerReturn.ExtendToString());

            Assert.Equal(layers.Length, layerReturn.Length);
            for (var i = 0; i < layers.Length; i++)
            {
                Assert.Equal(layers[i], layerReturn[i]);
            }

            masker      = new LayerMasker(3);
            layerReturn = masker.Layers(mask).ToEnumerable().ToArray();
            layers      = layers.OrderByDescending(i => i).Where(i => i < 3).ToArray();
            Assert.Equal(layers.Length, layerReturn.Length);
            for (var i = 0; i < layers.Length; i++)
            {
                Assert.Equal(layers[i], layerReturn[i]);
            }
        }
Beispiel #4
0
        public void Layers()
        {
            var masker = new LayerMasker();

            int[] layers = new int[] { 0, 2, 5 };

            var mask        = masker.Mask(layers);
            var layerReturn = masker.Layers(mask).ToArray();

            layers = layers.OrderByDescending(i => i).ToArray();

            Console.WriteLine("Actual layers");
            Console.WriteLine(layers.ExtendToString());
            Console.WriteLine("Returned layers:");
            Console.WriteLine(layerReturn.ExtendToString());

            Assert.AreEqual(layers.Length, layerReturn.Length);
            for (int i = 0; i < layers.Length; i++)
            {
                Assert.AreEqual(layers[i], layerReturn[i]);
            }

            masker      = new LayerMasker(3);
            layerReturn = masker.Layers(mask).ToArray();
            layers      = layers.OrderByDescending(i => i).Where(i => i < 3).ToArray();
            Assert.AreEqual(layers.Length, layerReturn.Length);
            for (int i = 0; i < layers.Length; i++)
            {
                Assert.AreEqual(layers[i], layerReturn[i]);
            }
        }