コード例 #1
0
        public void initialize_with_range_array_skip_duplicates()
        {
            var input  = new[] { "1-2", "2-3", "1-5" };
            var ranges = new RangeCompare(input, 10);

            Assert.AreEqual(2, ranges.Length);
        }
コード例 #2
0
        public void initialize_with_range_array()
        {
            var input  = new [] { "1-2", "2-3" };
            var ranges = new RangeCompare(input, 10);

            Assert.AreEqual(input.Length, ranges.Length);
        }
コード例 #3
0
        public void compute_to_max_32_bit_int()
        {
            var input  = new[] { "0-2147483640", "2147483647-2147483647" };
            var ranges = new RangeCompare(input, int.MaxValue);

            ranges.CalculateNonBlocked();
            Assert.AreEqual(6, ranges.Count);
        }
コード例 #4
0
        public void return_none_allowed_in_range()
        {
            var input  = new[] { "0-3", "2-4", "2-7", "8-10" };
            var ranges = new RangeCompare(input, 10);

            ranges.CalculateNonBlocked();
            Assert.AreEqual(0, ranges.Count);
        }
コード例 #5
0
        public void return_count_of_allowed_in_range()
        {
            var input  = new[] { "2-4", "1-3", "2-3", "8-10", "5-5", "9-8" };
            var ranges = new RangeCompare(input, 10);

            ranges.CalculateNonBlocked();
            Assert.AreEqual(3, ranges.Count);
        }
コード例 #6
0
        public void return_zero_if_first()
        {
            var input  = new[] { "1-3", "2-4", "2-3" };
            var ranges = new RangeCompare(input, 10);

            ranges.CalculateNonBlocked();
            Assert.AreEqual(0, ranges.First);
        }
コード例 #7
0
        public void return_first_non_blocked_int_considering_duplicates()
        {
            var input  = new[] { "0-3", "2-4", "2-3" };
            var ranges = new RangeCompare(input, 10);

            ranges.CalculateNonBlocked();
            Assert.AreEqual(5, ranges.First);
        }
コード例 #8
0
        public void convert_input_to_pair()
        {
            string input = "1-2";
            long   start;
            long   end;

            RangeCompare.ConvertInputToInt(input, out start, out end);

            Assert.AreEqual(1, start);
            Assert.AreEqual(2, end);
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: smonaco47/advent_of_code
        static void Main(string[] args)
        {
            string fileName = "C:\\Source\\AdventOfCode\\Day20\\input.txt";
            var    file     = new FileImportAdapter();

            string[] input        = file.ReadFileToArray(fileName);
            var      rangeCompare = new RangeCompare(input, uint.MaxValue);

            rangeCompare.CalculateNonBlocked();
            Console.Write("Lowest : " + rangeCompare.First);
            Console.Write(" IP Count : " + rangeCompare.Count);
            Console.ReadKey();
        }
コード例 #10
0
        //---------------------------------------------------------------------------
        // Helper for RangeFromPoint() test cases
        //---------------------------------------------------------------------------
        internal void RangeFromPointHelper2(SampleText sampleText, bool isMultiLineExpected, TargetRangeType rangeType, BoundingRectangleLocation pointLocation, RangeCompare rangeCompare)
        {
            Point screenLocation;
            Rect[] boundRects = new Rect[0];
            TextPatternRange callingRange = null;
            TextPatternRange rangeFromPt = null;

            // Pre-Condition Control must supports multi-line = <<expectedResult>>
            TS_IsMultiLine(isMultiLineExpected, CheckType.IncorrectElementConfiguration);

            // Pre-Condition Verify text is expected value <<sampleText>>
            TS_SetText(sampleText, CheckType.IncorrectElementConfiguration);

            // Pre-Condition Create range equal to <<rangeType>>
            TS_CreateRange(out callingRange, rangeType, null, false, CheckType.IncorrectElementConfiguration);

            // Pre-Condition Scroll range into view
            // Bug 1134054: TextPatternRange.ScrollIntoView fails to scroll horizontally on edit control
            // We need to make sure we scroll off the view so we can scroll back on it.
            // Otherwise the second scrollIntoView call may be a no-op...
            Range_ScrollIntoView(callingRange, false, null, CheckType.Verification);
            TS_ScrollIntoView(callingRange, true, null, CheckType.Verification);

            // Pre-Condition Call GetBoundingRectangles() on that range
            TS_GetBoundingRectangles(callingRange, ref boundRects, false, null, CheckType.Verification);

            // Pre-Condition Create a point <<pointLocation>> of bounding rect
            TS_CreatePoint(ref callingRange, boundRects, out screenLocation, pointLocation, CheckType.Verification);

            // Call RangeFromPoint on point without errors
            TS_RangeFromPoint(ref rangeFromPt, screenLocation, null, CheckType.Verification);

            // Verify that range returned is <<rangeCompare>>
            TS_CompareRanges(callingRange, rangeFromPt, rangeCompare, null, CheckType.Verification);
        }
コード例 #11
0
        //---------------------------------------------------------------------------
        // Helper for RangeFromPoint() test cases
        //---------------------------------------------------------------------------
        internal void RangeFromPointHelper(SampleText sampleText, int expandBy, TextPatternRangeEndpoint endPoint, RangeLocation rangeLocation, BoundingRectangleLocation pointLocation, RangeCompare rangeCompare, Type expectedException)
        {
            Point screenLocation;
            Rect[] boundRects = new Rect[0];
            string actualText = "";
            TextPatternRange callingRange = null;
            TextPatternRange rangeFromPt = null;

            // Pre-Condition Verify text is expected value <<sampleText>>
            TS_SetText(sampleText, out actualText, CheckType.IncorrectElementConfiguration);

            // Pre-Condition Create empty calling range @ <<RangeLocation>> of TextPattern.DocumentRange
            TS_CreateEmptyRange(out callingRange, rangeLocation, CheckType.Verification);

            // Pre-Condition Expand <<endPoint>> endPoint by <<expandby>> character(s)
            TS_ExpandRange(ref callingRange, endPoint, TextUnit.Character, expandBy, true, CheckType.Verification);

            // Pre-Condition Scroll range into view
            // Bug 1134054: TextPatternRange.ScrollIntoView fails to scroll horizontally on edit control
            // We need to make sure we scroll off the view so we can scroll back on it.
            // Otherwise the second scrollIntoView call may be a no-op...
            Range_ScrollIntoView(callingRange, false, null, CheckType.Verification);
            TS_ScrollIntoView(callingRange, true, null, CheckType.Verification);

            // Pre-Condition Call GetBoundingRectangles() on that range
            TS_GetBoundingRectangles(callingRange, ref boundRects, false, null, CheckType.Verification);

            // Pre-Condition Create a point <<pointLocation>> of bounding rect
            TS_CreatePoint(ref callingRange, boundRects, out screenLocation, pointLocation, CheckType.Verification);

            // Call RangeFromPoint on point 
            TS_RangeFromPoint(ref rangeFromPt, screenLocation, expectedException, CheckType.Verification);

            // Verify that range returned is  <<rangeCompare>>
            TS_CompareRanges(callingRange, rangeFromPt, rangeCompare, expectedException, CheckType.Verification);
        }
コード例 #12
0
        //---------------------------------------------------------------------------
        // Verify that range returned is within the range we created
        //---------------------------------------------------------------------------
        internal void TS_CompareRanges(TextPatternRange callingRange, TextPatternRange rangeFromPt, RangeCompare compareResults, Type expectedException, CheckType checkType)
        {
            int actualResult = 0;
            int docStart = 0; // offset of range compared to document start
            int docEnd = 0; // offset of range compared to document end
            int compareStart = 0; // offset of range compared to callingRange start
            int compareEnd = 0; // offset of range compared to callingRange end
            TextPatternRange documentRange = Pattern_DocumentRange(CheckType.Verification);

            Comment("Validating that RangeFromPoint return value is " + Parse(compareResults));

            // Sanity check
            if (callingRange == null)
                throw new ArgumentNullException("TS_CompareRanges requires non-null TextPatternRange");

            // The earlier call to Pattern_GetRangeFromPoint() will validate expecting exception/not getting one
            // But if we did get one/expected it, then "range" is null
            if (expectedException != null)
                actualResult += (int)RangeCompare.Exception;
            else
            {
                // Evaluate what actual results are
                Range_CompareEndpoints(documentRange, TextPatternRangeEndpoint.Start, rangeFromPt, TextPatternRangeEndpoint.Start, ref docStart, null, checkType);
                Range_CompareEndpoints(documentRange, TextPatternRangeEndpoint.End, rangeFromPt, TextPatternRangeEndpoint.End, ref docEnd, null, checkType);
                Range_CompareEndpoints(callingRange, TextPatternRangeEndpoint.Start, rangeFromPt, TextPatternRangeEndpoint.Start, ref compareStart, null, checkType);
                Range_CompareEndpoints(callingRange, TextPatternRangeEndpoint.End, rangeFromPt, TextPatternRangeEndpoint.End, ref compareEnd, null, checkType);

                if ((docStart <= 0) && (docEnd >= 0))
                    actualResult += (int)RangeCompare.WithinDocRange;  // likely this will always be true

                if ((compareStart <= 0) && (compareEnd >= 0))
                    actualResult += (int)RangeCompare.Contained;

                if (IsEmptyRange(rangeFromPt, checkType))
                    actualResult += (int)RangeCompare.Empty;

                if ((compareStart == 0) && (compareEnd == 0))
                    actualResult += (int)RangeCompare.Equal;
            }

            // Good to go???                
            if ((actualResult & ((int)compareResults)) > 0)
                Comment("RangeFromPoint returned expected range");
            else
                ThrowMe(checkType, "RangeFromPoint failed to return expected range " + ParseType(compareResults));
            m_TestStep++;
        }
コード例 #13
0
ファイル: TextTests.cs プロジェクト: sergeyDyadenchuk/Testing
 /// ---------------------------------------------------------------------------
 /// <summary>Parses values for enum</summary>
 /// ---------------------------------------------------------------------------
 static public string ParseType(RangeCompare value)
 {
     return ParseType(value.GetType().ToString(), value.ToString());
 }
コード例 #14
0
ファイル: TextTests.cs プロジェクト: sergeyDyadenchuk/Testing
 static public string Parse(RangeCompare value)
 {
     switch (value)
     {
         case RangeCompare.Equal: return "Target Range Equal to Calling Range";
         case RangeCompare.Empty: return "Target Range EMPTY";
         case RangeCompare.Contained: return "Target Range within Calling range";
         case RangeCompare.WithinDocRange: return "Target Range is within DocumentRange";
         case RangeCompare.Exception: return "Exception generated, no target range";
         default:
             throw new ArgumentException("Parse() has no support for " + ParseType(value));
     }
 }