public int CalculateDistinctSlices(int[] sequence)
        {
            if (sequence.Length == 0)
            {
                return(0);
            }

            var totalSlices = 0L;
            var slice       = new Slice();

            slice.Add(sequence[0], 0);
            for (int i = 1; i < sequence.Length; i++)
            {
                if (slice.ContainsValue(sequence[i]))
                {
                    totalSlices += GetNumberOfSubSlices(slice.Count);
                    slice.CleanUpToValue(sequence[i]);
                    totalSlices -= GetNumberOfSubSlices(slice.Count);
                }
                slice.Add(sequence[i], i);
            }
            totalSlices += GetNumberOfSubSlices(slice.Count);

            return((int)totalSlices);
        }
Example #2
0
        public void TestAddPlacesNewElementAtEndOfCollection()
        {
            var list  = new[] { 0, 1, 2, 3, 4 };
            var slice = new Slice <int>(list, 2, 2);

            Assert.ThrowsException <InvalidOperationException>(() => slice.Add(5));
        }
Example #3
0
        public void Converter_ToText_SimpleIntegerOneMaterialRectsIntersectionInvert()
        {
            #region TestData
            var scene = new Slice();
            scene.Add(new Rect(2, 0, 4, 2, 2));
            scene.Add(new Rect(0, 0, 3, 2, 2));
            #endregion

            var expected = @"SLICE NUMBER:  1  FIRST ROW:  1  LAST ROW:  2
ROW NR.   1  FIRST PIXEL:   1  NUMBER OF AREAS:  1
    4   2
ROW NR.   2  FIRST PIXEL:   1  NUMBER OF AREAS:  1
    4   2";
            var actual   = scene.ToText(1, false);

            Assert.AreEqual(expected, actual);
        }
Example #4
0
        public void Converter_ToText_SimpleIntegerOneMaterialRectsSmalledFirst()
        {
            #region TestData
            var scene = new Slice();
            scene.Add(new Rect(1, 1, 3, 3, 1));
            scene.Add(new Rect(0, 0, 4, 4, 1));
            #endregion

            var expected = @"SLICE NUMBER:  1  FIRST ROW:  1  LAST ROW:  4
ROW NR.   1  FIRST PIXEL:   1  NUMBER OF AREAS:  1
    4   1
ROW NR.   2  FIRST PIXEL:   1  NUMBER OF AREAS:  1
    4   1
ROW NR.   3  FIRST PIXEL:   1  NUMBER OF AREAS:  1
    4   1
ROW NR.   4  FIRST PIXEL:   1  NUMBER OF AREAS:  1
    4   1";
            var actual   = scene.ToText(1, false);

            Assert.AreEqual(expected, actual);
        }
Example #5
0
        public void Converter_ToText_SimpleDecimalCircle3()
        {
            #region TestData
            var scene = new Slice();
            scene.Add(new Circle(1.5, 1.5, 0.5, 8));
            #endregion

            var expected = @"SLICE NUMBER:  1  FIRST ROW:  2  LAST ROW:  2
ROW NR.   2  FIRST PIXEL:   2  NUMBER OF AREAS:  1
    2   8";
            var actual   = scene.ToText(1, false);

            Assert.AreEqual(expected, actual);
        }
Example #6
0
        public void Converter_FromText_SimpleDecimalCircle3()
        {
            #region TestData
            var text     = @"SLICE NUMBER:  1  FIRST ROW:  2  LAST ROW:  2
ROW NR.   2  FIRST PIXEL:   2  NUMBER OF AREAS:  1
    2   8";
            var expected = new Scene();
            var slice    = new Slice();
            slice.Add(new Circle(1.5, 1.5, 0.5, 8));
            expected.AddSlice(1, slice);
            #endregion

            var actual = TextConventer.SceneFromText(text);

            AreEqualScene(expected, actual);
        }
Example #7
0
        public void Converter_ToText_SimpleIntegerCircle()
        {
            #region TestData
            var scene = new Slice();
            scene.Add(new Circle(1, 1, 1, 4));
            #endregion

            var expected = @"SLICE NUMBER:  1  FIRST ROW:  1  LAST ROW:  2
ROW NR.   1  FIRST PIXEL:   1  NUMBER OF AREAS:  1
    2   4
ROW NR.   2  FIRST PIXEL:   1  NUMBER OF AREAS:  1
    2   4";
            var actual   = scene.ToText(1, false);

            Assert.AreEqual(expected, actual);
        }
Example #8
0
        public void Converter_FromText_SimpleIntegerCircle()
        {
            #region TestData
            var text     = @"SLICE NUMBER:  1  FIRST ROW:  1  LAST ROW:  2
ROW NR.   1  FIRST PIXEL:   1  NUMBER OF AREAS:  1
    2   4
ROW NR.   2  FIRST PIXEL:   1  NUMBER OF AREAS:  1
    2   4";
            var expected = new Scene();
            var slice    = new Slice();
            slice.Add(new Circle(1, 1, 1, 4));
            expected.AddSlice(1, slice);
            #endregion

            var actual = TextConventer.SceneFromText(text);

            AreEqualScene(expected, actual);
        }