Jelajahi Sumber

Fix unit test.

BDisp 11 bulan lalu
induk
melakukan
84225fcdcb

+ 1 - 3
Terminal.Gui/Views/Scroll/ScrollSlider.cs

@@ -165,9 +165,7 @@ internal class ScrollSlider : View
         if ((SuperViewAsScroll.Orientation == Orientation.Vertical && location + Frame.Height >= scrollSize)
             || (SuperViewAsScroll.Orientation == Orientation.Horizontal && location + Frame.Width >= scrollSize))
         {
-            return Math.Min (
-                             Math.Max (SuperViewAsScroll.Position + location, 0),
-                             SuperViewAsScroll.KeepContentInAllViewport ? SuperViewAsScroll.Size - scrollSize : SuperViewAsScroll.Size - 1);
+            return SuperViewAsScroll.Size - scrollSize + (SuperViewAsScroll.KeepContentInAllViewport ? 0 : scrollSize);
         }
 
         return (int)Math.Min (

+ 4 - 3
UnitTests/Views/ScrollSliderTests.cs

@@ -43,8 +43,8 @@ public class ScrollSliderTests
 
     // Randomized Test for more extensive testing
     [Theory]
-    [InlineData (Orientation.Vertical, 26, 236, 5)]
-    public void Test_Position_Location_Consistency_Random (Orientation orientation, int scrollLength, int size, int testCount)
+    [InlineData (Orientation.Vertical, true, 26, 236, 5)]
+    public void Test_Position_Location_Consistency_Random (Orientation orientation, bool keepContentInAllViewport, int scrollLength, int size, int testCount)
     {
         var random = new Random ();
 
@@ -53,7 +53,8 @@ public class ScrollSliderTests
             Orientation = orientation,
             Width = orientation == Orientation.Vertical ? 1 : scrollLength,
             Height = orientation == Orientation.Vertical ? scrollLength : 1,
-            Size = size
+            Size = size,
+            KeepContentInAllViewport = keepContentInAllViewport
         };
 
         scroll.BeginInit ();