mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-01 16:59:35 +01:00
Fixes #3192. Improve correctness / clarity of existing View.AutoSize functionality/unit tests (#3202)
* Removed resharper settings from editorconfig * Remove constructors with frame parameters from Button class. * Remove constructors with frame parameters from CheckBox class. * Cleanup code. * Remove constructors with frame parameters from ComboBox class. * @BDisp Remove constructors with frame parameters from FrameView class. * Remove constructors with frame parameters from Label class. * Remove constructors with frame parameters from ListView class. * Remove constructors with frame parameters from ScrollBarView class. * Remove constructors with frame parameters from ScrollView class. * Remove namespace braces. * Cleanup code. * Cleanup code. * Cleanup code. * Remove constructors with frame parameters from TextField class. * Remove constructors with frame parameters from TimeField class. * Fixes #3182. OnResizeNeeded returns int.MaxValue and int.MaxValue when Application.Top is null, should return Size.Empty. * Remove constructors with frame parameters from Toplevel class. * Remove constructors with frame parameters from Window class. * Fix merge errors. * Revert "Fixes #3182. OnResizeNeeded returns int.MaxValue and int.MaxValue when Application.Top is null, should return Size.Empty." This reverts commitcf9c24b846. * Revert unit test. * Fixes #2882. TabView: 'Frame.DrawFrame(Rect, bool)' is obsolete: 'This method is obsolete in v2. Use use LineCanvas or Frame (#2980) * Fixes #2882. TabView: 'Frame.DrawFrame(Rect, bool)' is obsolete: 'This method is obsolete in v2. Use use LineCanvas or Frame * Trying fix this unit test that sometimes fail. * Fixes #2983. View need a alternative DrawFrame for the v2. * Use new DrawFrame method. * Change _lines field to Lines property. * Add TabWindow unit test. * Add DrawIncompleteFrame method and unit tests. * Add more unit tests to LineCanvas. * Fix newline conflict errors. * Revert "Change _lines field to Lines property." This reverts commitab6c5f3094. * Add DrawIncompleteFrame method and unit tests. * Add more unit tests to LineCanvas. * Fix newline conflict errors. * Force render immediately instead of join. * I will never rely on zero-location-based unit test again. * Fix TestTreeViewColor unit test fail. * Using location of 3 to avoid be divisible by 2 and so avoiding bugs. * Revert "Using location of 3 to avoid be divisible by 2 and so avoiding bugs." This reverts commitdd3df135d8. * Revert "I will never rely on zero-location-based unit test again." This reverts commit62adf6f285. * Revert "Fix newline conflict errors." This reverts commit4acf72612d. * Revert "Add more unit tests to LineCanvas." This reverts commit66bc6f514e. * Revert "Add DrawIncompleteFrame method and unit tests." This reverts commit680ba264e1. * Resolving merge conflicts. * Revert "Use new DrawFrame method." This reverts commit69a7f17f19. * Revert "Fixes #2983. View need a alternative DrawFrame for the v2." This reverts commitdade9fd767. * Reverting this changes to start a new one. * Add horizontal and vertical support for combining glyphs. * Fix text and auto size behavior. * Add TabWidth property. * Add unit test for WordWrap. * Fixes #3017. View TextDirection returns incorrect size on a vertical direction instance with AutoSize as false. * Using Frame to force read from the get method. * Fix some issues with AutoSize and ForceValidatePosDim. * Fixing broken unit tests. * Restoring code I've broken. * Removing forgotten code. * Only LayoutStyle.Computed can change the Frame. * DateField and TimeField depends on LayoutStyle.Computed. * Fix unit tests related with LayoutStyle. * Implements tabs, left and right arrows as View. * Draws a minimum full border. * Adds missing XML parameter. * Adds assert tests for Frame. * Removes duplicates InlineData. * Adds more unit tests for minimum full border without Left and Right thickness. * Trying to fix the TestTreeViewColor unit test fail. * Prevents a user to set TextDirection to -1. * Prevents any invalid TextDirection value. * Removes (TextDirection)(-1). * Removes unnecessary TextDirection initialization. * Removes LayoutStyle. * Fixing unit tests with border. * Trying to fix TestTreeViewColor again. * Revert "Trying to fix TestTreeViewColor again." This reverts commitc2efa8e42e. * Trying to fix TestTreeViewColor again. * Fix merge errors. * Fix merge errors. * Restoring unit test. * Restores the right XML comment. * Fix Disposing unit tests that sometimes throws because some instances aren't cleared on others unit tests classes. * Fix Disposing unit tests that sometimes throws because some instances aren't cleared on others unit tests classes. * Only call OnResizeNeeded if it's LayoutStyle.Computed. * Fix merge errors. * Fix merge errors. * Fix unit tests fail. * Reformat. * Again. * Rename to OnDrawAdornments. * Fix failing unit tests. * Reduces indentation and cleanup code. * Cleanup code. * Fix bug done when cleanup. * Replace FrameHandledMouseEvent to AdornmentHandledMouseEvent. * Removes Tab constructor parameters. --------- Co-authored-by: Tig <tig@users.noreply.github.com> * Fix merge errors. * Remove constructors with parameters from Button. * Remove parenthesis on objects initializers from Button. * Remove constructors with parameters from CheckBox. * Remove parenthesis on objects initializers from CheckBox. * Remove constructors with parameters from ComboBox. * Remove constructors with parameters from FrameView. * Remove parenthesis on objects initializers from FrameView. * Initial commit * Renamed Direction enum for clarity in refactoring unit tests * Moved nav tests to NavigationTests * Moved view tests around * Cleaning up TextFormatter and View.AutoSize code * Fixed latent TextFormatter bug with \n * removed Application dependency on some autosize unit tests * Fixed Label tests to deal with auotsize overriding height/width * Fixed more label tests. WIP * Fixed all places where AutoSize = happend after setting Dims * Started adding new primitive View.Text tests * Code comments * WIP: Enforce that it makes no sense to set Width/Height if AutoSize = true. Update Unit tests to match. * WIP: Enforce that it makes no sense to set Width/Height if AutoSize = true. Update Unit tests to match. * Remove frame set from the View constructor and prevent SetRelativeLayout running if not yet initialized. * Changes needed for unit tests pass on remove parameters constructors from the Label class. * Remove constructors with parameters from Label. * Remove parenthesis on objects initializers from Label. * Prefix private fields with underscore. * Renamed to MaxLength. * Remove constructors with parameters from ListView. * MakeWrapper not needed anymore. * Remove parenthesis on objects initializers from ListView. * WIP: Enforce that it makes no sense to set Width/Height if AutoSize = true. Update Unit tests to match. * Massive code cleanup - use parameterless constructors and ensure AutoSize is set properly. Code reformat. * Massive code cleanup - use parameterless constructors and ensure AutoSize is set properly. Code reformat. * Fixed messagebox * Remove constructors with parameters from ScrollBarView and ScrollView. * Remove parenthesis on objects initializers from ScrollBarView and ScrollView. * Cleanup code. * Fix merge errors. * Add empty dotsettings for solution and projects. * Set ReSharper language analysis level for projects to C#12 * Make ReSharper consider itself the boss for style * Add rule to enforce property backing fields above the property * Disable auto-detection of naming rules so ReSharper doesn't change them by itself * Don't let someone's VS settings override the indent settings * Explicitly set tab width to 4 spaces and force spaces. * Rules to keep various multi-line constructs aligned within themselves * Curly brace rules (Using K&R style, per current project spec) * Blank line rules Mostly to add breaks in various situations, and also to enforce max of 1 blank line. * Increase auto-wrap to 160 from default of 120 * Line break at end of all files, to make Unixy systems happy * Keep attributes on their own lines except for methods and records that are themselves single-line * Increase attribute auto-wrap to 60 from default of 38 * Wrap/chop rules for long method signatures and record declarations Chop if either already multi-line or if over 8 parameters. Chop AFTER the left paren and BEFORE the first parameter. * Chop rules for generics For generics with multi-line type parameters or multiple type parameter constraints, chop in a way that has consistent alignment. * Always enforce enum members on their own lines * One-line functions completely on one line They're usually expression-bodied anyway, here, so this is almost irrelevant * Keep control flow statements on their own lines * Follow same chop rules for method invocation as method declaration * Chop long or multi-line method chains or patterns * Wrap rules for binary operators Operator at beginning of new lines Auto-chop if long or already multi-line * Spaces between keywords and their opening parentheses * Add file layout rules for organization of reorderable items like fields, properties, etc. Ugly XML, so load it up in the UI to look at it It's MOSTLY the ReSharper defaults, but with more aggressive sorting, generally by access modifier and name, within each grouping. * Deconstructors use per-member types * Use keywords for built-in types and increase severity of inspection for violations Also apply to IntPtr and similar, which should now be nint and similar * Apply syntax style on completion. * Use var when evident for built-in and simple types, but not elsewhere * Increase severity for some minor redundancy and clarity inspections * Enforce braces always required for blocks, and treat as error * Warn if a local function is not statement-bodied * Increase various inspection severities IF Condition => Severity: Attributes not wrapped property => Suggestion Constructors expression-bodied => Error default doesn't have type when it isn't clear => suggestion Namespaces not file-scoped => error Methods not statement-bodied => hint Null check pattern not the object property pattern => Error * Adjust preference order of null check patterns to make object pattern highest * XmlDoc rules to keep tags and contents aligned and wrapped * Add a few custom profiles for code cleanup and make the full profile default * Remove parts for languages not used in this solution * copied in v2_develop changes * Merged v2_develop * Added Begin/Init unit tests. Removed Application dependencey from AutoSizeFalse tests * TextFormatter.Lines -> GetLines () * Let ReSharper know we intend to localize things * TextFormatter code cleanup * copied in v2_develop changes * Merged v2_develop * Spaces aren't wanted here either. * Fix merge errors. * Fixes ContentBottomRightCorner related with https://github.com/gui-cs/Terminal.Gui/issues/3211#issue-2098878820 * Remove constructors with parameters from ContextMenu. * Remove commented code. * Remove constructors with parameters from OpenDialog. * Remove constructors with parameters from SaveDialog. * Remove constructors with parameters from TextField. * Remove constructors with parameters from TimeField. * Fix unit test. * Remove unnecessary SetInitialProperties method. * Remove unnecessary SetInitialProperties method. * Remove parenthesis on objects initializers from Toplevel and Window. * Remove constructors with parameters from RadioGroup. * Remove constructors with parameters from TextView. * Remove constructors with parameters from MenuBar. * TEMPORARY: Turn everything that was set to error down to warning or lower * Fixes #3219. MenuBar is opened by call OpenMenu even it's disabled. * Remove constructors with parameters from Menu. * Remove constructors with parameters from View. * Change constructor to internal because is mainly useful for testing. * ReSharper Cleanup Code. * Added format only r# config * Fixes #3224. TextFormatter.Lines should return a single string.Empty list even with Width or Height equal to zero. * Remove constructors with parameters from Dialog. * Remove constructors with parameters from TextValidateField. * Fixes https://github.com/gui-cs/Terminal.Gui/issues/3224#issuecomment-1924096038 * Fixes #3225. Press CursorDown on TabView doesn't move to the next view. * Fixes #3229. TextFormatter should have a FillRemaining property. * Testing formatting merge in bdisp * Testing formatting merge * Testing formatting merge bdisp * Testing formatting merge 2 * xmldoc format * R# Full Code Cleanup * R# Full Code Cleanup2 * R# Full Code Cleanup2 * Merged! But broke tests * Refixing... * Refixed DrawTests * Refixed ViewTests * Refixed Text Tests * Refixed more unit tests * Refixed scenarios * Refixed rest of scenarios * Refixed ViewsTests * Refixed rest of tests. All unit tests pass again! * Fixed warnings * Updated R# version. Added new code cleanup settings * Applied latest code cleanup to solution * Another code cleanup pass * Tweaked r# settings. .editorconfig now matches. * r# else on separate line * r# - update * r# - full solution * test commit * test commit * test commit * Removed extra profiles * Full cleanup following cleaning up profiles * Null checking pattern rules/inspections * Tabs and extra whitespace are evil * Attributes on their own lines * Code layout rules to put fields first and to put backing fields with their properties * Merged v2_develop * Full cleanup following dodexahedron's PR --------- Co-authored-by: BDisp <bd.bdisp@gmail.com> Co-authored-by: Brandon Thetford <github@snapsinazfs.com>
This commit is contained in:
@@ -1,376 +1,375 @@
|
||||
using Xunit;
|
||||
// Alias Console to MockConsole so we don't accidentally use Console
|
||||
using Console = Terminal.Gui.FakeConsole;
|
||||
|
||||
namespace Terminal.Gui.DrawingTests;
|
||||
|
||||
public class AttributeTests {
|
||||
|
||||
[Fact]
|
||||
public void Attribute_Is_Value_Type () =>
|
||||
// prove that Color is a value type
|
||||
Assert.True (typeof (Attribute).IsValueType);
|
||||
|
||||
|
||||
[Fact]
|
||||
public void DefaultConstructor ()
|
||||
{
|
||||
// Arrange & Act
|
||||
var attribute = new Attribute ();
|
||||
|
||||
// Assert
|
||||
//Assert.False (attribute.Initialized);
|
||||
Assert.Equal (-1, attribute.PlatformColor);
|
||||
Assert.Equal (new Color (Color.White), attribute.Foreground);
|
||||
Assert.Equal (new Color (Color.Black), attribute.Background);
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PlatformColorConstructor ()
|
||||
{
|
||||
// Arrange & Act
|
||||
var attribute = new Attribute (42);
|
||||
|
||||
// Assert
|
||||
//Assert.True (attribute.Initialized);
|
||||
Assert.Equal (42, attribute.PlatformColor);
|
||||
Assert.Equal (new Color (Color.White), attribute.Foreground);
|
||||
Assert.Equal (new Color (Color.Black), attribute.Background);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ColorNamesConstructor ()
|
||||
{
|
||||
// Arrange & Act
|
||||
var attribute = new Attribute (ColorName.Blue);
|
||||
|
||||
// Assert
|
||||
Assert.Equal (new Color (Color.Blue), attribute.Foreground);
|
||||
Assert.Equal (new Color (Color.Blue), attribute.Background);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
public void ColorConstructor ()
|
||||
{
|
||||
// Arrange & Act
|
||||
var foregroundColor = new Color (0, 0, 255);
|
||||
var backgroundColor = new Color (255, 255, 255);
|
||||
var attribute = new Attribute (foregroundColor, backgroundColor);
|
||||
|
||||
// Assert
|
||||
Assert.Equal (foregroundColor, attribute.Foreground);
|
||||
Assert.Equal (backgroundColor, attribute.Background);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
public void ColorAndColorNamesConstructor ()
|
||||
{
|
||||
// Arrange & Act
|
||||
var foregroundColor = new Color (0, 0, 255);
|
||||
var backgroundColorName = ColorName.Black;
|
||||
var attribute = new Attribute (foregroundColor, backgroundColorName);
|
||||
|
||||
// Assert
|
||||
Assert.Equal (foregroundColor, attribute.Foreground);
|
||||
Assert.Equal (new Color (backgroundColorName), attribute.Background);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ColorNamesAndColorConstructor ()
|
||||
{
|
||||
// Arrange & Act
|
||||
var foregroundColorName = ColorName.BrightYellow;
|
||||
var backgroundColor = new Color (128, 128, 128);
|
||||
var attribute = new Attribute (foregroundColorName, backgroundColor);
|
||||
|
||||
// Assert
|
||||
Assert.Equal (new Color (foregroundColorName), attribute.Foreground);
|
||||
Assert.Equal (backgroundColor, attribute.Background);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructors_Construct ()
|
||||
{
|
||||
var driver = new FakeDriver ();
|
||||
driver.Init ();
|
||||
|
||||
// Test parameterless constructor
|
||||
var attr = new Attribute ();
|
||||
|
||||
Assert.Equal (-1, attr.PlatformColor);
|
||||
Assert.Equal (new Color (Color.White), attr.Foreground);
|
||||
Assert.Equal (new Color (Color.Black), attr.Background);
|
||||
|
||||
// Test foreground, background
|
||||
var fg = new Color ();
|
||||
fg = new Color (Color.Red);
|
||||
|
||||
var bg = new Color ();
|
||||
bg = new Color (Color.Blue);
|
||||
|
||||
attr = new Attribute (fg, bg);
|
||||
|
||||
//Assert.True (attr.Initialized);
|
||||
//Assert.True (attr.HasValidColors);
|
||||
Assert.Equal (fg, attr.Foreground);
|
||||
Assert.Equal (bg, attr.Background);
|
||||
|
||||
attr = new Attribute (fg);
|
||||
//Assert.True (attr.Initialized);
|
||||
//Assert.True (attr.HasValidColors);
|
||||
Assert.Equal (fg, attr.Foreground);
|
||||
Assert.Equal (fg, attr.Background);
|
||||
|
||||
attr = new Attribute (bg);
|
||||
//Assert.True (attr.Initialized);
|
||||
//Assert.True (attr.HasValidColors);
|
||||
Assert.Equal (bg, attr.Foreground);
|
||||
Assert.Equal (bg, attr.Background);
|
||||
|
||||
driver.End ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MakeColorAndColor_ForegroundAndBackgroundShouldMatchInput ()
|
||||
{
|
||||
// Arrange
|
||||
var foregroundColor = new Color (0, 0, 255);
|
||||
var backgroundColor = new Color (255, 255, 255);
|
||||
|
||||
// Act
|
||||
var attribute = new Attribute (foregroundColor, backgroundColor);
|
||||
|
||||
// Assert
|
||||
Assert.Equal (foregroundColor, attribute.Foreground);
|
||||
Assert.Equal (backgroundColor, attribute.Background);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MakeColorNamesAndColorNames_ForegroundAndBackgroundShouldMatchInput ()
|
||||
{
|
||||
// Arrange
|
||||
var foregroundColorName = ColorName.BrightYellow;
|
||||
var backgroundColorName = ColorName.Black;
|
||||
|
||||
// Act
|
||||
var attribute = new Attribute (foregroundColorName, backgroundColorName);
|
||||
|
||||
// Assert
|
||||
Assert.Equal (new Color (foregroundColorName), attribute.Foreground);
|
||||
Assert.Equal (new Color (backgroundColorName), attribute.Background);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MakeColorNamesAndColor_ForegroundAndBackgroundShouldMatchInput ()
|
||||
{
|
||||
// Arrange
|
||||
var foregroundColorName = ColorName.Green;
|
||||
var backgroundColor = new Color (128, 128, 128);
|
||||
|
||||
// Act
|
||||
var attribute = new Attribute (foregroundColorName, backgroundColor);
|
||||
|
||||
// Assert
|
||||
Assert.Equal (new Color (foregroundColorName), attribute.Foreground);
|
||||
Assert.Equal (backgroundColor, attribute.Background);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MakeColorAndColorNames_ForegroundAndBackgroundShouldMatchInput ()
|
||||
{
|
||||
// Arrange
|
||||
var foregroundColor = new Color (255, 0, 0);
|
||||
var backgroundColorName = ColorName.White;
|
||||
|
||||
// Act
|
||||
var attribute = new Attribute (foregroundColor, backgroundColorName);
|
||||
|
||||
// Assert
|
||||
Assert.Equal (foregroundColor, attribute.Foreground);
|
||||
Assert.Equal (new Color (backgroundColorName), attribute.Background);
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Fact]
|
||||
public void Implicit_Assign ()
|
||||
{
|
||||
var driver = new FakeDriver ();
|
||||
driver.Init ();
|
||||
|
||||
var attr = new Attribute ();
|
||||
|
||||
var value = 42;
|
||||
var fg = new Color ();
|
||||
fg = new Color (Color.Red);
|
||||
|
||||
var bg = new Color ();
|
||||
bg = new Color (Color.Blue);
|
||||
|
||||
// Test conversion to int
|
||||
attr = new Attribute (value, fg, bg);
|
||||
var value_implicit = attr.PlatformColor;
|
||||
Assert.Equal (value, value_implicit);
|
||||
|
||||
Assert.Equal (value, attr.PlatformColor);
|
||||
|
||||
driver.End ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Make_SetsNotInitialized_NoDriver ()
|
||||
{
|
||||
var fg = new Color ();
|
||||
fg = new Color (Color.Red);
|
||||
|
||||
var bg = new Color ();
|
||||
bg = new Color (Color.Blue);
|
||||
|
||||
var a = new Attribute (fg, bg);
|
||||
|
||||
//Assert.False (a.Initialized);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Make_Creates ()
|
||||
{
|
||||
var driver = new FakeDriver ();
|
||||
driver.Init ();
|
||||
|
||||
var fg = new Color ();
|
||||
fg = new Color (Color.Red);
|
||||
|
||||
var bg = new Color ();
|
||||
bg = new Color (Color.Blue);
|
||||
|
||||
var attr = new Attribute (fg, bg);
|
||||
//Assert.True (attr.Initialized);
|
||||
Assert.Equal (fg, attr.Foreground);
|
||||
Assert.Equal (bg, attr.Background);
|
||||
|
||||
driver.End ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Make_Creates_NoDriver ()
|
||||
{
|
||||
|
||||
var fg = new Color ();
|
||||
fg = new Color (Color.Red);
|
||||
|
||||
var bg = new Color ();
|
||||
bg = new Color (Color.Blue);
|
||||
|
||||
var attr = new Attribute (fg, bg);
|
||||
//Assert.False (attr.Initialized);
|
||||
Assert.Equal (fg, attr.Foreground);
|
||||
Assert.Equal (bg, attr.Background);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_NotInitialized ()
|
||||
{
|
||||
var attr1 = new Attribute (Color.Red, Color.Green);
|
||||
var attr2 = new Attribute (Color.Red, Color.Green);
|
||||
|
||||
Assert.True (attr1.Equals (attr2));
|
||||
Assert.True (attr2.Equals (attr1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NotEquals_NotInitialized ()
|
||||
{
|
||||
var attr1 = new Attribute (Color.Red, Color.Green);
|
||||
var attr2 = new Attribute (Color.Green, Color.Red);
|
||||
|
||||
Assert.False (attr1.Equals (attr2));
|
||||
Assert.False (attr2.Equals (attr1));
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void Equals_Initialized ()
|
||||
{
|
||||
Assert.NotNull (Application.Driver);
|
||||
|
||||
var attr1 = new Attribute (Color.Red, Color.Green);
|
||||
var attr2 = new Attribute (Color.Red, Color.Green);
|
||||
|
||||
Assert.True (attr1.Equals (attr2));
|
||||
Assert.True (attr2.Equals (attr1));
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void NotEquals_Initialized ()
|
||||
{
|
||||
var attr1 = new Attribute (Color.Red, Color.Green);
|
||||
var attr2 = new Attribute (Color.Green, Color.Red);
|
||||
|
||||
Assert.False (attr1.Equals (attr2));
|
||||
Assert.False (attr2.Equals (attr1));
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void EqualityOperator_ShouldReturnTrueForEqualAttributes ()
|
||||
{
|
||||
// Arrange
|
||||
var attribute1 = new Attribute (Color.Red, Color.Black);
|
||||
var attribute2 = new Attribute (Color.Red, Color.Black);
|
||||
|
||||
// Act & Assert
|
||||
Assert.True (attribute1 == attribute2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EqualityOperator_ShouldReturnFalseForDifferentAttributes ()
|
||||
{
|
||||
// Arrange
|
||||
var attribute1 = new Attribute (Color.Red, Color.Black);
|
||||
var attribute2 = new Attribute (Color.Blue, Color.Black);
|
||||
|
||||
// Act & Assert
|
||||
Assert.False (attribute1 == attribute2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InequalityOperator_ShouldReturnTrueForDifferentAttributes ()
|
||||
{
|
||||
// Arrange
|
||||
var attribute1 = new Attribute (Color.Red, Color.Black);
|
||||
var attribute2 = new Attribute (Color.Blue, Color.Black);
|
||||
|
||||
// Act & Assert
|
||||
Assert.True (attribute1 != attribute2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InequalityOperator_ShouldReturnFalseForEqualAttributes ()
|
||||
{
|
||||
// Arrange
|
||||
var attribute1 = new Attribute (Color.Red, Color.Black);
|
||||
var attribute2 = new Attribute (Color.Red, Color.Black);
|
||||
|
||||
// Act & Assert
|
||||
Assert.False (attribute1 != attribute2);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void ToString_ShouldReturnFormattedStringWithForegroundAndBackground ()
|
||||
{
|
||||
// Arrange
|
||||
var foregroundColor = new Color (0, 0, 255);
|
||||
var backgroundColor = new Color (255, 255, 255);
|
||||
var expectedString = $"[{foregroundColor},{backgroundColor}]";
|
||||
|
||||
// Act
|
||||
var attribute = new Attribute (foregroundColor, backgroundColor);
|
||||
var attributeString = attribute.ToString ();
|
||||
|
||||
// Assert
|
||||
Assert.Equal (expectedString, attributeString);
|
||||
}
|
||||
}
|
||||
public class AttributeTests
|
||||
{
|
||||
[Fact]
|
||||
public void Attribute_Is_Value_Type ()
|
||||
{
|
||||
// prove that Color is a value type
|
||||
Assert.True (typeof (Attribute).IsValueType);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
public void ColorAndColorNamesConstructor ()
|
||||
{
|
||||
// Arrange & Act
|
||||
var foregroundColor = new Color (0, 0, 255);
|
||||
var backgroundColorName = ColorName.Black;
|
||||
var attribute = new Attribute (foregroundColor, backgroundColorName);
|
||||
|
||||
// Assert
|
||||
Assert.Equal (foregroundColor, attribute.Foreground);
|
||||
Assert.Equal (new Color (backgroundColorName), attribute.Background);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
public void ColorConstructor ()
|
||||
{
|
||||
// Arrange & Act
|
||||
var foregroundColor = new Color (0, 0, 255);
|
||||
var backgroundColor = new Color (255, 255, 255);
|
||||
var attribute = new Attribute (foregroundColor, backgroundColor);
|
||||
|
||||
// Assert
|
||||
Assert.Equal (foregroundColor, attribute.Foreground);
|
||||
Assert.Equal (backgroundColor, attribute.Background);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ColorNamesAndColorConstructor ()
|
||||
{
|
||||
// Arrange & Act
|
||||
var foregroundColorName = ColorName.BrightYellow;
|
||||
var backgroundColor = new Color (128, 128, 128);
|
||||
var attribute = new Attribute (foregroundColorName, backgroundColor);
|
||||
|
||||
// Assert
|
||||
Assert.Equal (new Color (foregroundColorName), attribute.Foreground);
|
||||
Assert.Equal (backgroundColor, attribute.Background);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ColorNamesConstructor ()
|
||||
{
|
||||
// Arrange & Act
|
||||
var attribute = new Attribute (ColorName.Blue);
|
||||
|
||||
// Assert
|
||||
Assert.Equal (new Color (Color.Blue), attribute.Foreground);
|
||||
Assert.Equal (new Color (Color.Blue), attribute.Background);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructors_Construct ()
|
||||
{
|
||||
var driver = new FakeDriver ();
|
||||
driver.Init ();
|
||||
|
||||
// Test parameterless constructor
|
||||
var attr = new Attribute ();
|
||||
|
||||
Assert.Equal (-1, attr.PlatformColor);
|
||||
Assert.Equal (new Color (Color.White), attr.Foreground);
|
||||
Assert.Equal (new Color (Color.Black), attr.Background);
|
||||
|
||||
// Test foreground, background
|
||||
var fg = new Color ();
|
||||
fg = new Color (Color.Red);
|
||||
|
||||
var bg = new Color ();
|
||||
bg = new Color (Color.Blue);
|
||||
|
||||
attr = new Attribute (fg, bg);
|
||||
|
||||
//Assert.True (attr.Initialized);
|
||||
//Assert.True (attr.HasValidColors);
|
||||
Assert.Equal (fg, attr.Foreground);
|
||||
Assert.Equal (bg, attr.Background);
|
||||
|
||||
attr = new Attribute (fg);
|
||||
|
||||
//Assert.True (attr.Initialized);
|
||||
//Assert.True (attr.HasValidColors);
|
||||
Assert.Equal (fg, attr.Foreground);
|
||||
Assert.Equal (fg, attr.Background);
|
||||
|
||||
attr = new Attribute (bg);
|
||||
|
||||
//Assert.True (attr.Initialized);
|
||||
//Assert.True (attr.HasValidColors);
|
||||
Assert.Equal (bg, attr.Foreground);
|
||||
Assert.Equal (bg, attr.Background);
|
||||
|
||||
driver.End ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DefaultConstructor ()
|
||||
{
|
||||
// Arrange & Act
|
||||
var attribute = new Attribute ();
|
||||
|
||||
// Assert
|
||||
//Assert.False (attribute.Initialized);
|
||||
Assert.Equal (-1, attribute.PlatformColor);
|
||||
Assert.Equal (new Color (Color.White), attribute.Foreground);
|
||||
Assert.Equal (new Color (Color.Black), attribute.Background);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EqualityOperator_ShouldReturnFalseForDifferentAttributes ()
|
||||
{
|
||||
// Arrange
|
||||
var attribute1 = new Attribute (Color.Red, Color.Black);
|
||||
var attribute2 = new Attribute (Color.Blue, Color.Black);
|
||||
|
||||
// Act & Assert
|
||||
Assert.False (attribute1 == attribute2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EqualityOperator_ShouldReturnTrueForEqualAttributes ()
|
||||
{
|
||||
// Arrange
|
||||
var attribute1 = new Attribute (Color.Red, Color.Black);
|
||||
var attribute2 = new Attribute (Color.Red, Color.Black);
|
||||
|
||||
// Act & Assert
|
||||
Assert.True (attribute1 == attribute2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
public void Equals_Initialized ()
|
||||
{
|
||||
Assert.NotNull (Application.Driver);
|
||||
|
||||
var attr1 = new Attribute (Color.Red, Color.Green);
|
||||
var attr2 = new Attribute (Color.Red, Color.Green);
|
||||
|
||||
Assert.True (attr1.Equals (attr2));
|
||||
Assert.True (attr2.Equals (attr1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_NotInitialized ()
|
||||
{
|
||||
var attr1 = new Attribute (Color.Red, Color.Green);
|
||||
var attr2 = new Attribute (Color.Red, Color.Green);
|
||||
|
||||
Assert.True (attr1.Equals (attr2));
|
||||
Assert.True (attr2.Equals (attr1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Implicit_Assign ()
|
||||
{
|
||||
var driver = new FakeDriver ();
|
||||
driver.Init ();
|
||||
|
||||
var attr = new Attribute ();
|
||||
|
||||
var value = 42;
|
||||
var fg = new Color ();
|
||||
fg = new Color (Color.Red);
|
||||
|
||||
var bg = new Color ();
|
||||
bg = new Color (Color.Blue);
|
||||
|
||||
// Test conversion to int
|
||||
attr = new Attribute (value, fg, bg);
|
||||
int value_implicit = attr.PlatformColor;
|
||||
Assert.Equal (value, value_implicit);
|
||||
|
||||
Assert.Equal (value, attr.PlatformColor);
|
||||
|
||||
driver.End ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InequalityOperator_ShouldReturnFalseForEqualAttributes ()
|
||||
{
|
||||
// Arrange
|
||||
var attribute1 = new Attribute (Color.Red, Color.Black);
|
||||
var attribute2 = new Attribute (Color.Red, Color.Black);
|
||||
|
||||
// Act & Assert
|
||||
Assert.False (attribute1 != attribute2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InequalityOperator_ShouldReturnTrueForDifferentAttributes ()
|
||||
{
|
||||
// Arrange
|
||||
var attribute1 = new Attribute (Color.Red, Color.Black);
|
||||
var attribute2 = new Attribute (Color.Blue, Color.Black);
|
||||
|
||||
// Act & Assert
|
||||
Assert.True (attribute1 != attribute2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Make_Creates ()
|
||||
{
|
||||
var driver = new FakeDriver ();
|
||||
driver.Init ();
|
||||
|
||||
var fg = new Color ();
|
||||
fg = new Color (Color.Red);
|
||||
|
||||
var bg = new Color ();
|
||||
bg = new Color (Color.Blue);
|
||||
|
||||
var attr = new Attribute (fg, bg);
|
||||
|
||||
//Assert.True (attr.Initialized);
|
||||
Assert.Equal (fg, attr.Foreground);
|
||||
Assert.Equal (bg, attr.Background);
|
||||
|
||||
driver.End ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Make_Creates_NoDriver ()
|
||||
{
|
||||
var fg = new Color ();
|
||||
fg = new Color (Color.Red);
|
||||
|
||||
var bg = new Color ();
|
||||
bg = new Color (Color.Blue);
|
||||
|
||||
var attr = new Attribute (fg, bg);
|
||||
|
||||
//Assert.False (attr.Initialized);
|
||||
Assert.Equal (fg, attr.Foreground);
|
||||
Assert.Equal (bg, attr.Background);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Make_SetsNotInitialized_NoDriver ()
|
||||
{
|
||||
var fg = new Color ();
|
||||
fg = new Color (Color.Red);
|
||||
|
||||
var bg = new Color ();
|
||||
bg = new Color (Color.Blue);
|
||||
|
||||
var a = new Attribute (fg, bg);
|
||||
|
||||
//Assert.False (a.Initialized);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MakeColorAndColor_ForegroundAndBackgroundShouldMatchInput ()
|
||||
{
|
||||
// Arrange
|
||||
var foregroundColor = new Color (0, 0, 255);
|
||||
var backgroundColor = new Color (255, 255, 255);
|
||||
|
||||
// Act
|
||||
var attribute = new Attribute (foregroundColor, backgroundColor);
|
||||
|
||||
// Assert
|
||||
Assert.Equal (foregroundColor, attribute.Foreground);
|
||||
Assert.Equal (backgroundColor, attribute.Background);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MakeColorAndColorNames_ForegroundAndBackgroundShouldMatchInput ()
|
||||
{
|
||||
// Arrange
|
||||
var foregroundColor = new Color (255, 0);
|
||||
var backgroundColorName = ColorName.White;
|
||||
|
||||
// Act
|
||||
var attribute = new Attribute (foregroundColor, backgroundColorName);
|
||||
|
||||
// Assert
|
||||
Assert.Equal (foregroundColor, attribute.Foreground);
|
||||
Assert.Equal (new Color (backgroundColorName), attribute.Background);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MakeColorNamesAndColor_ForegroundAndBackgroundShouldMatchInput ()
|
||||
{
|
||||
// Arrange
|
||||
var foregroundColorName = ColorName.Green;
|
||||
var backgroundColor = new Color (128, 128, 128);
|
||||
|
||||
// Act
|
||||
var attribute = new Attribute (foregroundColorName, backgroundColor);
|
||||
|
||||
// Assert
|
||||
Assert.Equal (new Color (foregroundColorName), attribute.Foreground);
|
||||
Assert.Equal (backgroundColor, attribute.Background);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MakeColorNamesAndColorNames_ForegroundAndBackgroundShouldMatchInput ()
|
||||
{
|
||||
// Arrange
|
||||
var foregroundColorName = ColorName.BrightYellow;
|
||||
var backgroundColorName = ColorName.Black;
|
||||
|
||||
// Act
|
||||
var attribute = new Attribute (foregroundColorName, backgroundColorName);
|
||||
|
||||
// Assert
|
||||
Assert.Equal (new Color (foregroundColorName), attribute.Foreground);
|
||||
Assert.Equal (new Color (backgroundColorName), attribute.Background);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
public void NotEquals_Initialized ()
|
||||
{
|
||||
var attr1 = new Attribute (Color.Red, Color.Green);
|
||||
var attr2 = new Attribute (Color.Green, Color.Red);
|
||||
|
||||
Assert.False (attr1.Equals (attr2));
|
||||
Assert.False (attr2.Equals (attr1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NotEquals_NotInitialized ()
|
||||
{
|
||||
var attr1 = new Attribute (Color.Red, Color.Green);
|
||||
var attr2 = new Attribute (Color.Green, Color.Red);
|
||||
|
||||
Assert.False (attr1.Equals (attr2));
|
||||
Assert.False (attr2.Equals (attr1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PlatformColorConstructor ()
|
||||
{
|
||||
// Arrange & Act
|
||||
var attribute = new Attribute (42);
|
||||
|
||||
// Assert
|
||||
//Assert.True (attribute.Initialized);
|
||||
Assert.Equal (42, attribute.PlatformColor);
|
||||
Assert.Equal (new Color (Color.White), attribute.Foreground);
|
||||
Assert.Equal (new Color (Color.Black), attribute.Background);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToString_ShouldReturnFormattedStringWithForegroundAndBackground ()
|
||||
{
|
||||
// Arrange
|
||||
var foregroundColor = new Color (0, 0, 255);
|
||||
var backgroundColor = new Color (255, 255, 255);
|
||||
var expectedString = $"[{foregroundColor},{backgroundColor}]";
|
||||
|
||||
// Act
|
||||
var attribute = new Attribute (foregroundColor, backgroundColor);
|
||||
var attributeString = attribute.ToString ();
|
||||
|
||||
// Assert
|
||||
Assert.Equal (expectedString, attributeString);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,43 +1,41 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Terminal.Gui.DrawingTests;
|
||||
|
||||
public class ColorSchemeTests {
|
||||
[Fact]
|
||||
public void Colors_ColorSchemes_Property_Has_Private_Setter ()
|
||||
{
|
||||
// Resharper Code Cleanup likes to remove the `private set; `
|
||||
// from the ColorSchemes property. This test will fail if
|
||||
// that happens.
|
||||
var property = typeof (Colors).GetProperty ("ColorSchemes");
|
||||
Assert.NotNull (property);
|
||||
Assert.NotNull (property.SetMethod);
|
||||
Assert.True (property.GetSetMethod (true).IsPrivate);
|
||||
public class ColorSchemeTests
|
||||
{
|
||||
[Fact]
|
||||
public void Colors_ColorSchemes_Built_Ins ()
|
||||
{
|
||||
Colors.Reset ();
|
||||
Dictionary<string, ColorScheme> schemes = Colors.ColorSchemes;
|
||||
Assert.NotNull (schemes);
|
||||
Assert.Equal (5, schemes.Count);
|
||||
Assert.True (schemes.ContainsKey ("TopLevel"));
|
||||
Assert.True (schemes.ContainsKey ("Base"));
|
||||
Assert.True (schemes.ContainsKey ("Dialog"));
|
||||
Assert.True (schemes.ContainsKey ("Menu"));
|
||||
Assert.True (schemes.ContainsKey ("Error"));
|
||||
}
|
||||
|
||||
}
|
||||
[Fact]
|
||||
public void Colors_ColorSchemes_Property_Has_Private_Setter ()
|
||||
{
|
||||
// Resharper Code Cleanup likes to remove the `private set; `
|
||||
// from the ColorSchemes property. This test will fail if
|
||||
// that happens.
|
||||
PropertyInfo property = typeof (Colors).GetProperty ("ColorSchemes");
|
||||
Assert.NotNull (property);
|
||||
Assert.NotNull (property.SetMethod);
|
||||
Assert.True (property.GetSetMethod (true).IsPrivate);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ColorScheme_New ()
|
||||
{
|
||||
var scheme = new ColorScheme ();
|
||||
var lbl = new Label ();
|
||||
lbl.ColorScheme = scheme;
|
||||
lbl.Draw ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Colors_ColorSchemes_Built_Ins ()
|
||||
{
|
||||
Colors.Reset ();
|
||||
var schemes = Colors.ColorSchemes;
|
||||
Assert.NotNull (schemes);
|
||||
Assert.Equal (5, schemes.Count);
|
||||
Assert.True (schemes.ContainsKey ("TopLevel"));
|
||||
Assert.True (schemes.ContainsKey ("Base"));
|
||||
Assert.True (schemes.ContainsKey ("Dialog"));
|
||||
Assert.True (schemes.ContainsKey ("Menu"));
|
||||
Assert.True (schemes.ContainsKey ("Error"));
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void ColorScheme_New ()
|
||||
{
|
||||
var scheme = new ColorScheme ();
|
||||
var lbl = new Label ();
|
||||
lbl.ColorScheme = scheme;
|
||||
lbl.Draw ();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,173 +1,220 @@
|
||||
namespace Terminal.Gui.DrawingTests;
|
||||
|
||||
public partial class ColorTests {
|
||||
public partial class ColorTests
|
||||
{
|
||||
[Fact]
|
||||
public void Constructor_Empty_ReturnsColorWithZeroValue ()
|
||||
{
|
||||
Color color = new ();
|
||||
|
||||
[Fact]
|
||||
public void Constructor_Empty_ReturnsColorWithZeroValue ()
|
||||
{
|
||||
Color color = new ();
|
||||
Assert.Multiple (
|
||||
() => Assert.Equal (0, color.Rgba),
|
||||
() => Assert.Equal (0u, color.Argb),
|
||||
() => Assert.Equal (0, color.R),
|
||||
() => Assert.Equal (0, color.G),
|
||||
() => Assert.Equal (0, color.B),
|
||||
() => Assert.Equal (0, color.A)
|
||||
);
|
||||
}
|
||||
Assert.Multiple (
|
||||
() => Assert.Equal (0, color.Rgba),
|
||||
() => Assert.Equal (0u, color.Argb),
|
||||
() => Assert.Equal (0, color.R),
|
||||
() => Assert.Equal (0, color.G),
|
||||
() => Assert.Equal (0, color.B),
|
||||
() => Assert.Equal (0, color.A)
|
||||
);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[CombinatorialData]
|
||||
public void Constructor_WithByteRGBAValues_AllValuesCorrect ([CombinatorialValues (0, 1, 254)] byte r, [CombinatorialValues (0, 1, 253)] byte g, [CombinatorialValues (0, 1, 252)] byte b, [CombinatorialValues (0, 1, 251)] byte a)
|
||||
{
|
||||
var color = new Color (r, g, b, a);
|
||||
[Theory]
|
||||
[CombinatorialData]
|
||||
public void Constructor_WithByteRGBAValues_AllValuesCorrect (
|
||||
[CombinatorialValues (0, 1, 254)] byte r,
|
||||
[CombinatorialValues (0, 1, 253)] byte g,
|
||||
[CombinatorialValues (0, 1, 252)] byte b,
|
||||
[CombinatorialValues (0, 1, 251)] byte a
|
||||
)
|
||||
{
|
||||
var color = new Color (r, g, b, a);
|
||||
|
||||
ReadOnlySpan<byte> bytes = [b, g, r, a];
|
||||
int expectedRgba = BitConverter.ToInt32 (bytes);
|
||||
uint expectedArgb = BitConverter.ToUInt32 (bytes);
|
||||
ReadOnlySpan<byte> bytes = [b, g, r, a];
|
||||
var expectedRgba = BitConverter.ToInt32 (bytes);
|
||||
var expectedArgb = BitConverter.ToUInt32 (bytes);
|
||||
|
||||
Assert.Multiple (
|
||||
() => Assert.Equal (r, color.R),
|
||||
() => Assert.Equal (g, color.G),
|
||||
() => Assert.Equal (b, color.B),
|
||||
() => Assert.Equal (a, color.A),
|
||||
() => Assert.Equal (expectedRgba, color.Rgba),
|
||||
() => Assert.Equal (expectedArgb, color.Argb)
|
||||
);
|
||||
}
|
||||
[Theory]
|
||||
[CombinatorialData]
|
||||
public void Constructor_WithByteRGBValues_AllValuesCorrect ([CombinatorialValues (0, 1, 254)] byte r, [CombinatorialValues (0, 1, 253)] byte g, [CombinatorialValues (0, 1, 252)] byte b)
|
||||
{
|
||||
var color = new Color (r, g, b);
|
||||
Assert.Multiple (
|
||||
() => Assert.Equal (r, color.R),
|
||||
() => Assert.Equal (g, color.G),
|
||||
() => Assert.Equal (b, color.B),
|
||||
() => Assert.Equal (a, color.A),
|
||||
() => Assert.Equal (expectedRgba, color.Rgba),
|
||||
() => Assert.Equal (expectedArgb, color.Argb)
|
||||
);
|
||||
}
|
||||
|
||||
ReadOnlySpan<byte> bytes = [b, g, r, 255];
|
||||
int expectedRgba = BitConverter.ToInt32 (bytes);
|
||||
uint expectedArgb = BitConverter.ToUInt32 (bytes);
|
||||
[Theory]
|
||||
[CombinatorialData]
|
||||
public void Constructor_WithByteRGBValues_AllValuesCorrect (
|
||||
[CombinatorialValues (0, 1, 254)] byte r,
|
||||
[CombinatorialValues (0, 1, 253)] byte g,
|
||||
[CombinatorialValues (0, 1, 252)] byte b
|
||||
)
|
||||
{
|
||||
var color = new Color (r, g, b);
|
||||
|
||||
Assert.Multiple (
|
||||
() => Assert.Equal (r, color.R),
|
||||
() => Assert.Equal (g, color.G),
|
||||
() => Assert.Equal (b, color.B),
|
||||
() => Assert.Equal (byte.MaxValue, color.A),
|
||||
() => Assert.Equal (expectedRgba, color.Rgba),
|
||||
() => Assert.Equal (expectedArgb, color.Argb)
|
||||
);
|
||||
}
|
||||
ReadOnlySpan<byte> bytes = [b, g, r, 255];
|
||||
var expectedRgba = BitConverter.ToInt32 (bytes);
|
||||
var expectedArgb = BitConverter.ToUInt32 (bytes);
|
||||
|
||||
[Theory]
|
||||
[MemberData (nameof (ColorTestsTheoryDataGenerators.Constructor_WithColorName_AllChannelsCorrect), MemberType = typeof (ColorTestsTheoryDataGenerators))]
|
||||
public void Constructor_WithColorName_AllChannelsCorrect (ColorName cname, ValueTuple<byte, byte, byte> expectedColorValues)
|
||||
{
|
||||
var color = new Color (cname);
|
||||
Assert.Multiple (
|
||||
() => Assert.Equal (r, color.R),
|
||||
() => Assert.Equal (g, color.G),
|
||||
() => Assert.Equal (b, color.B),
|
||||
() => Assert.Equal (byte.MaxValue, color.A),
|
||||
() => Assert.Equal (expectedRgba, color.Rgba),
|
||||
() => Assert.Equal (expectedArgb, color.Argb)
|
||||
);
|
||||
}
|
||||
|
||||
(byte r, byte g, byte b) = expectedColorValues;
|
||||
Assert.Multiple (
|
||||
() => Assert.Equal (r, color.R),
|
||||
() => Assert.Equal (g, color.G),
|
||||
() => Assert.Equal (b, color.B),
|
||||
() => Assert.Equal (byte.MaxValue, color.A)
|
||||
);
|
||||
}
|
||||
[Theory]
|
||||
[MemberData (
|
||||
nameof (ColorTestsTheoryDataGenerators.Constructor_WithColorName_AllChannelsCorrect),
|
||||
MemberType = typeof (ColorTestsTheoryDataGenerators)
|
||||
)]
|
||||
public void Constructor_WithColorName_AllChannelsCorrect (
|
||||
ColorName cname,
|
||||
ValueTuple<byte, byte, byte> expectedColorValues
|
||||
)
|
||||
{
|
||||
var color = new Color (cname);
|
||||
|
||||
[Theory]
|
||||
[CombinatorialData]
|
||||
public void Constructor_WithInt32_AllValuesCorrect ([CombinatorialValues (0, 1, 254)] byte r, [CombinatorialValues (0, 1, 253)] byte g, [CombinatorialValues (0, 1, 252)] byte b, [CombinatorialValues (0, 1, 251)] byte a)
|
||||
{
|
||||
ReadOnlySpan<byte> bytes = [b, g, r, a];
|
||||
int expectedRgba = BitConverter.ToInt32 (bytes);
|
||||
uint expectedArgb = BitConverter.ToUInt32 (bytes);
|
||||
(byte r, byte g, byte b) = expectedColorValues;
|
||||
|
||||
var color = new Color (expectedRgba);
|
||||
Assert.Multiple (
|
||||
() => Assert.Equal (r, color.R),
|
||||
() => Assert.Equal (g, color.G),
|
||||
() => Assert.Equal (b, color.B),
|
||||
() => Assert.Equal (byte.MaxValue, color.A)
|
||||
);
|
||||
}
|
||||
|
||||
Assert.Multiple (
|
||||
() => Assert.Equal (r, color.R),
|
||||
() => Assert.Equal (g, color.G),
|
||||
() => Assert.Equal (b, color.B),
|
||||
() => Assert.Equal (a, color.A),
|
||||
() => Assert.Equal (expectedRgba, color.Rgba),
|
||||
() => Assert.Equal (expectedArgb, color.Argb)
|
||||
);
|
||||
}
|
||||
[Theory]
|
||||
[CombinatorialData]
|
||||
public void Constructor_WithInt32_AllValuesCorrect (
|
||||
[CombinatorialValues (0, 1, 254)] byte r,
|
||||
[CombinatorialValues (0, 1, 253)] byte g,
|
||||
[CombinatorialValues (0, 1, 252)] byte b,
|
||||
[CombinatorialValues (0, 1, 251)] byte a
|
||||
)
|
||||
{
|
||||
ReadOnlySpan<byte> bytes = [b, g, r, a];
|
||||
var expectedRgba = BitConverter.ToInt32 (bytes);
|
||||
var expectedArgb = BitConverter.ToUInt32 (bytes);
|
||||
|
||||
[Theory]
|
||||
[CombinatorialData]
|
||||
public void Constructor_WithInt32RGBAValues_AllValuesCorrect ([CombinatorialRandomData (Count = 4, Minimum = 0, Maximum = 255)] int r, [CombinatorialRandomData (Count = 4, Minimum = 0, Maximum = 255)] int g, [CombinatorialRandomData (Count = 4, Minimum = 0, Maximum = 255)] int b, [CombinatorialRandomData (Count = 4, Minimum = 0, Maximum = 255)] int a)
|
||||
{
|
||||
var color = new Color (r, g, b, a);
|
||||
var color = new Color (expectedRgba);
|
||||
|
||||
Assert.Multiple (
|
||||
() => Assert.Equal (r, color.R),
|
||||
() => Assert.Equal (g, color.G),
|
||||
() => Assert.Equal (b, color.B),
|
||||
() => Assert.Equal (a, color.A)
|
||||
);
|
||||
}
|
||||
Assert.Multiple (
|
||||
() => Assert.Equal (r, color.R),
|
||||
() => Assert.Equal (g, color.G),
|
||||
() => Assert.Equal (b, color.B),
|
||||
() => Assert.Equal (a, color.A),
|
||||
() => Assert.Equal (expectedRgba, color.Rgba),
|
||||
() => Assert.Equal (expectedArgb, color.Argb)
|
||||
);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[CombinatorialData]
|
||||
public void Constructor_WithInt32RGBValues_AllValuesCorrect ([CombinatorialRandomData (Count = 4, Minimum = 0, Maximum = 255)] int r, [CombinatorialRandomData (Count = 4, Minimum = 0, Maximum = 255)] int g, [CombinatorialRandomData (Count = 4, Minimum = 0, Maximum = 255)] int b)
|
||||
{
|
||||
var color = new Color (r, g, b);
|
||||
[Theory]
|
||||
[CombinatorialData]
|
||||
public void Constructor_WithInt32RGBAValues_AllValuesCorrect (
|
||||
[CombinatorialRandomData (Count = 4, Minimum = 0, Maximum = 255)]
|
||||
int r,
|
||||
[CombinatorialRandomData (Count = 4, Minimum = 0, Maximum = 255)]
|
||||
int g,
|
||||
[CombinatorialRandomData (Count = 4, Minimum = 0, Maximum = 255)]
|
||||
int b,
|
||||
[CombinatorialRandomData (Count = 4, Minimum = 0, Maximum = 255)]
|
||||
int a
|
||||
)
|
||||
{
|
||||
var color = new Color (r, g, b, a);
|
||||
|
||||
Assert.Multiple (
|
||||
() => Assert.Equal (r, color.R),
|
||||
() => Assert.Equal (g, color.G),
|
||||
() => Assert.Equal (b, color.B),
|
||||
() => Assert.Equal (byte.MaxValue, color.A)
|
||||
);
|
||||
}
|
||||
Assert.Multiple (
|
||||
() => Assert.Equal (r, color.R),
|
||||
() => Assert.Equal (g, color.G),
|
||||
() => Assert.Equal (b, color.B),
|
||||
() => Assert.Equal (a, color.A)
|
||||
);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[CombinatorialData]
|
||||
public void Constructor_WithString_EmptyOrWhitespace_ThrowsArgumentException ([CombinatorialValues ("", "\t", " ", "\r", "\r\n", "\n", " ")] string badString)
|
||||
{
|
||||
Assert.Throws<ArgumentException> (() => Color.Parse (badString));
|
||||
}
|
||||
[Theory]
|
||||
[CombinatorialData]
|
||||
public void Constructor_WithInt32RGBValues_AllValuesCorrect (
|
||||
[CombinatorialRandomData (Count = 4, Minimum = 0, Maximum = 255)]
|
||||
int r,
|
||||
[CombinatorialRandomData (Count = 4, Minimum = 0, Maximum = 255)]
|
||||
int g,
|
||||
[CombinatorialRandomData (Count = 4, Minimum = 0, Maximum = 255)]
|
||||
int b
|
||||
)
|
||||
{
|
||||
var color = new Color (r, g, b);
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WithString_Null_ThrowsArgumentNullException ()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException> (static () => Color.Parse (null));
|
||||
}
|
||||
Assert.Multiple (
|
||||
() => Assert.Equal (r, color.R),
|
||||
() => Assert.Equal (g, color.G),
|
||||
() => Assert.Equal (b, color.B),
|
||||
() => Assert.Equal (byte.MaxValue, color.A)
|
||||
);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[CombinatorialData]
|
||||
public void Constructor_WithUInt32_AllChannelsCorrect ([CombinatorialValues (0, 1, 254)] byte r, [CombinatorialValues (0, 1, 253)] byte g, [CombinatorialValues (0, 1, 252)] byte b, [CombinatorialValues (0, 1, 251)] byte a)
|
||||
{
|
||||
ReadOnlySpan<byte> bytes = [b, g, r, a];
|
||||
uint expectedArgb = BitConverter.ToUInt32 (bytes);
|
||||
[Theory]
|
||||
[CombinatorialData]
|
||||
public void Constructor_WithString_EmptyOrWhitespace_ThrowsArgumentException (
|
||||
[CombinatorialValues ("", "\t", " ", "\r", "\r\n", "\n", " ")]
|
||||
string badString
|
||||
)
|
||||
{
|
||||
Assert.Throws<ArgumentException> (() => Color.Parse (badString));
|
||||
}
|
||||
|
||||
var color = new Color (expectedArgb);
|
||||
[Fact]
|
||||
public void Constructor_WithString_Null_ThrowsArgumentNullException () { Assert.Throws<ArgumentNullException> (static () => Color.Parse (null)); }
|
||||
|
||||
Assert.Multiple (
|
||||
() => Assert.Equal (r, color.R),
|
||||
() => Assert.Equal (g, color.G),
|
||||
() => Assert.Equal (b, color.B),
|
||||
() => Assert.Equal (a, color.A)
|
||||
);
|
||||
}
|
||||
[Theory]
|
||||
[CombinatorialData]
|
||||
public void Constructor_WithUInt32_AllChannelsCorrect (
|
||||
[CombinatorialValues (0, 1, 254)] byte r,
|
||||
[CombinatorialValues (0, 1, 253)] byte g,
|
||||
[CombinatorialValues (0, 1, 252)] byte b,
|
||||
[CombinatorialValues (0, 1, 251)] byte a
|
||||
)
|
||||
{
|
||||
ReadOnlySpan<byte> bytes = [b, g, r, a];
|
||||
var expectedArgb = BitConverter.ToUInt32 (bytes);
|
||||
|
||||
var color = new Color (expectedArgb);
|
||||
|
||||
Assert.Multiple (
|
||||
() => Assert.Equal (r, color.R),
|
||||
() => Assert.Equal (g, color.G),
|
||||
() => Assert.Equal (b, color.B),
|
||||
() => Assert.Equal (a, color.A)
|
||||
);
|
||||
}
|
||||
}
|
||||
public static partial class ColorTestsTheoryDataGenerators {
|
||||
public static TheoryData<ColorName, ValueTuple<byte, byte, byte>> Constructor_WithColorName_AllChannelsCorrect ()
|
||||
{
|
||||
TheoryData<ColorName, ValueTuple<byte, byte, byte>> data = [];
|
||||
data.Add (ColorName.Black, new ValueTuple<byte, byte, byte> (12, 12, 12));
|
||||
data.Add (ColorName.Blue, new ValueTuple<byte, byte, byte> (0, 55, 218));
|
||||
data.Add (ColorName.Green, new ValueTuple<byte, byte, byte> (19, 161, 14));
|
||||
data.Add (ColorName.Cyan, new ValueTuple<byte, byte, byte> (58, 150, 221));
|
||||
data.Add (ColorName.Red, new ValueTuple<byte, byte, byte> (197, 15, 31));
|
||||
data.Add (ColorName.Magenta, new ValueTuple<byte, byte, byte> (136, 23, 152));
|
||||
data.Add (ColorName.Yellow, new ValueTuple<byte, byte, byte> (128, 64, 32));
|
||||
data.Add (ColorName.Gray, new ValueTuple<byte, byte, byte> (204, 204, 204));
|
||||
data.Add (ColorName.DarkGray, new ValueTuple<byte, byte, byte> (118, 118, 118));
|
||||
data.Add (ColorName.BrightBlue, new ValueTuple<byte, byte, byte> (59, 120, 255));
|
||||
data.Add (ColorName.BrightGreen, new ValueTuple<byte, byte, byte> (22, 198, 12));
|
||||
data.Add (ColorName.BrightCyan, new ValueTuple<byte, byte, byte> (97, 214, 214));
|
||||
data.Add (ColorName.BrightRed, new ValueTuple<byte, byte, byte> (231, 72, 86));
|
||||
data.Add (ColorName.BrightMagenta, new ValueTuple<byte, byte, byte> (180, 0, 158));
|
||||
data.Add (ColorName.BrightYellow, new ValueTuple<byte, byte, byte> (249, 241, 165));
|
||||
data.Add (ColorName.White, new ValueTuple<byte, byte, byte> (242, 242, 242));
|
||||
return data;
|
||||
}
|
||||
|
||||
public static partial class ColorTestsTheoryDataGenerators
|
||||
{
|
||||
public static TheoryData<ColorName, ValueTuple<byte, byte, byte>> Constructor_WithColorName_AllChannelsCorrect ()
|
||||
{
|
||||
TheoryData<ColorName, ValueTuple<byte, byte, byte>> data = [];
|
||||
data.Add (ColorName.Black, new ValueTuple<byte, byte, byte> (12, 12, 12));
|
||||
data.Add (ColorName.Blue, new ValueTuple<byte, byte, byte> (0, 55, 218));
|
||||
data.Add (ColorName.Green, new ValueTuple<byte, byte, byte> (19, 161, 14));
|
||||
data.Add (ColorName.Cyan, new ValueTuple<byte, byte, byte> (58, 150, 221));
|
||||
data.Add (ColorName.Red, new ValueTuple<byte, byte, byte> (197, 15, 31));
|
||||
data.Add (ColorName.Magenta, new ValueTuple<byte, byte, byte> (136, 23, 152));
|
||||
data.Add (ColorName.Yellow, new ValueTuple<byte, byte, byte> (128, 64, 32));
|
||||
data.Add (ColorName.Gray, new ValueTuple<byte, byte, byte> (204, 204, 204));
|
||||
data.Add (ColorName.DarkGray, new ValueTuple<byte, byte, byte> (118, 118, 118));
|
||||
data.Add (ColorName.BrightBlue, new ValueTuple<byte, byte, byte> (59, 120, 255));
|
||||
data.Add (ColorName.BrightGreen, new ValueTuple<byte, byte, byte> (22, 198, 12));
|
||||
data.Add (ColorName.BrightCyan, new ValueTuple<byte, byte, byte> (97, 214, 214));
|
||||
data.Add (ColorName.BrightRed, new ValueTuple<byte, byte, byte> (231, 72, 86));
|
||||
data.Add (ColorName.BrightMagenta, new ValueTuple<byte, byte, byte> (180, 0, 158));
|
||||
data.Add (ColorName.BrightYellow, new ValueTuple<byte, byte, byte> (249, 241, 165));
|
||||
data.Add (ColorName.White, new ValueTuple<byte, byte, byte> (242, 242, 242));
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,178 +3,262 @@ using System.Reflection;
|
||||
|
||||
namespace Terminal.Gui.DrawingTests;
|
||||
|
||||
public partial class ColorTests {
|
||||
public partial class ColorTests
|
||||
{
|
||||
[Theory]
|
||||
[Trait ("Category", "Operators")]
|
||||
[CombinatorialData]
|
||||
public void ExplicitOperator_ToVector3_ReturnsCorrectValue (
|
||||
[CombinatorialRange (0, 255, 51)] byte r,
|
||||
[CombinatorialRange (0, 255, 51)] byte g,
|
||||
[CombinatorialRange (0, 255, 51)] byte b,
|
||||
[CombinatorialValues (0, 255)] byte a
|
||||
)
|
||||
{
|
||||
Color color = new (r, g, b, a);
|
||||
|
||||
[Theory]
|
||||
[Trait ("Category", "Operators")]
|
||||
[CombinatorialData]
|
||||
public void ExplicitOperator_ToVector3_ReturnsCorrectValue ([CombinatorialRange (0, 255, 51)] byte r, [CombinatorialRange (0, 255, 51)] byte g, [CombinatorialRange (0, 255, 51)] byte b, [CombinatorialValues (0, 255)] byte a)
|
||||
{
|
||||
Color color = new (r, g, b, a);
|
||||
var vector = (Vector3)color;
|
||||
|
||||
Vector3 vector = (Vector3)color;
|
||||
Assert.Equal (color.R, vector.X);
|
||||
Assert.Equal (color.G, vector.Y);
|
||||
Assert.Equal (color.B, vector.Z);
|
||||
}
|
||||
|
||||
Assert.Equal (color.R, vector.X);
|
||||
Assert.Equal (color.G, vector.Y);
|
||||
Assert.Equal (color.B, vector.Z);
|
||||
}
|
||||
[Theory]
|
||||
[CombinatorialData]
|
||||
public void GeneratedEqualityOperators_BehaveAsExpected (
|
||||
[CombinatorialValues (0, short.MaxValue, int.MaxValue, uint.MaxValue)]
|
||||
uint u1,
|
||||
[CombinatorialValues (0, short.MaxValue, int.MaxValue, uint.MaxValue)]
|
||||
uint u2
|
||||
)
|
||||
{
|
||||
Color color1 = u1;
|
||||
Color color2 = u2;
|
||||
|
||||
[Theory]
|
||||
[CombinatorialData]
|
||||
public void GeneratedEqualityOperators_BehaveAsExpected ([CombinatorialValues (0, short.MaxValue, int.MaxValue, uint.MaxValue)] uint u1, [CombinatorialValues (0, short.MaxValue, int.MaxValue, uint.MaxValue)] uint u2)
|
||||
{
|
||||
Color color1 = u1;
|
||||
Color color2 = u2;
|
||||
if (u1 == u2)
|
||||
{
|
||||
Assert.True (color1 == color2);
|
||||
Assert.False (color1 != color2);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.True (color1 != color2);
|
||||
Assert.False (color1 == color2);
|
||||
}
|
||||
}
|
||||
|
||||
if ( u1 == u2 ) {
|
||||
Assert.True (color1 == color2);
|
||||
Assert.False (color1 != color2);
|
||||
}
|
||||
else {
|
||||
Assert.True (color1 != color2);
|
||||
Assert.False (color1 == color2);
|
||||
}
|
||||
}
|
||||
[Theory]
|
||||
[CombinatorialData]
|
||||
[Trait ("Category", "Operators")]
|
||||
public void GetHashCode_DelegatesTo_Rgba ([CombinatorialRandomData (Count = 16)] int rgba)
|
||||
{
|
||||
Color color = new (rgba);
|
||||
|
||||
[Theory]
|
||||
[CombinatorialData]
|
||||
[Trait ("Category", "Operators")]
|
||||
public void GetHashCode_DelegatesTo_Rgba ([CombinatorialRandomData (Count = 16)] int rgba)
|
||||
{
|
||||
Color color = new (rgba);
|
||||
Assert.Equal (rgba.GetHashCode (), color.GetHashCode ());
|
||||
}
|
||||
|
||||
Assert.Equal (rgba.GetHashCode (), color.GetHashCode ());
|
||||
}
|
||||
[Theory]
|
||||
[Trait ("Category", "Operators")]
|
||||
[MemberData (
|
||||
nameof (ColorTestsTheoryDataGenerators.ExplicitOperator_FromColorName_RoundTripsCorrectly),
|
||||
MemberType = typeof (ColorTestsTheoryDataGenerators)
|
||||
)]
|
||||
public void ImplicitOperator_FromColorName_ReturnsCorrectColorValue (ColorName cname, Color expectedColor)
|
||||
{
|
||||
Color color = cname;
|
||||
|
||||
[Theory]
|
||||
[Trait ("Category", "Operators")]
|
||||
[MemberData (nameof (ColorTestsTheoryDataGenerators.ExplicitOperator_FromColorName_RoundTripsCorrectly), MemberType = typeof (ColorTestsTheoryDataGenerators))]
|
||||
public void ImplicitOperator_FromColorName_ReturnsCorrectColorValue (ColorName cname, Color expectedColor)
|
||||
{
|
||||
Color color = cname;
|
||||
Assert.Equal (expectedColor, color);
|
||||
}
|
||||
|
||||
Assert.Equal (expectedColor, color);
|
||||
}
|
||||
[Theory]
|
||||
[CombinatorialData]
|
||||
[Trait ("Category", "Operators")]
|
||||
public void ImplicitOperator_FromInt32_ReturnsCorrectColorValue (
|
||||
[CombinatorialRandomData (Count = 16)] int expectedValue
|
||||
)
|
||||
{
|
||||
Color color = expectedValue;
|
||||
|
||||
[Theory]
|
||||
[CombinatorialData]
|
||||
[Trait ("Category", "Operators")]
|
||||
public void ImplicitOperator_FromInt32_ReturnsCorrectColorValue ([CombinatorialRandomData (Count = 16)] int expectedValue)
|
||||
{
|
||||
Color color = expectedValue;
|
||||
Assert.Equal (expectedValue, color.Rgba);
|
||||
}
|
||||
|
||||
Assert.Equal (expectedValue, color.Rgba);
|
||||
}
|
||||
[Theory]
|
||||
[CombinatorialData]
|
||||
[Trait ("Category", "Operators")]
|
||||
public void ImplicitOperator_FromUInt32_ReturnsCorrectColorValue (
|
||||
[CombinatorialRandomData (Count = 16)] uint expectedValue
|
||||
)
|
||||
{
|
||||
Color color = expectedValue;
|
||||
|
||||
[Theory]
|
||||
[CombinatorialData]
|
||||
[Trait ("Category", "Operators")]
|
||||
public void ImplicitOperator_FromUInt32_ReturnsCorrectColorValue ([CombinatorialRandomData (Count = 16)] uint expectedValue)
|
||||
{
|
||||
Color color = expectedValue;
|
||||
Assert.Equal (expectedValue, color.Argb);
|
||||
}
|
||||
|
||||
Assert.Equal (expectedValue, color.Argb);
|
||||
}
|
||||
[Theory]
|
||||
[CombinatorialData]
|
||||
[Trait ("Category", "Operators")]
|
||||
public void ImplicitOperator_FromVector3_ReturnsCorrectColorValue (
|
||||
[CombinatorialRange (0, 255, 51)] byte r,
|
||||
[CombinatorialRange (0, 255, 51)] byte g,
|
||||
[CombinatorialRange (0, 255, 51)] byte b
|
||||
)
|
||||
{
|
||||
Vector3 vector = new (r, g, b);
|
||||
Color color = vector;
|
||||
|
||||
[Theory]
|
||||
[CombinatorialData]
|
||||
[Trait ("Category", "Operators")]
|
||||
public void ImplicitOperator_FromVector3_ReturnsCorrectColorValue ([CombinatorialRange (0, 255, 51)] byte r, [CombinatorialRange (0, 255, 51)] byte g, [CombinatorialRange (0, 255, 51)] byte b)
|
||||
{
|
||||
Vector3 vector = new (r, g, b);
|
||||
Color color = vector;
|
||||
Assert.Equal (r, color.R);
|
||||
Assert.Equal (g, color.G);
|
||||
Assert.Equal (b, color.B);
|
||||
Assert.Equal (byte.MaxValue, color.A);
|
||||
}
|
||||
|
||||
Assert.Equal (r, color.R);
|
||||
Assert.Equal (g, color.G);
|
||||
Assert.Equal (b, color.B);
|
||||
Assert.Equal (byte.MaxValue, color.A);
|
||||
}
|
||||
[Theory]
|
||||
[CombinatorialData]
|
||||
[Trait ("Category", "Operators")]
|
||||
public void ImplicitOperator_FromVector4_ReturnsCorrectColorValue (
|
||||
[CombinatorialRange (0, 255, 51)] byte r,
|
||||
[CombinatorialRange (0, 255, 51)] byte g,
|
||||
[CombinatorialRange (0, 255, 51)] byte b,
|
||||
[CombinatorialValues (0, 255)] byte a
|
||||
)
|
||||
{
|
||||
Vector4 vector = new (r, g, b, a);
|
||||
Color color = vector;
|
||||
|
||||
[Theory]
|
||||
[CombinatorialData]
|
||||
[Trait ("Category", "Operators")]
|
||||
public void ImplicitOperator_FromVector4_ReturnsCorrectColorValue ([CombinatorialRange (0, 255, 51)] byte r, [CombinatorialRange (0, 255, 51)] byte g, [CombinatorialRange (0, 255, 51)] byte b, [CombinatorialValues (0, 255)] byte a)
|
||||
{
|
||||
Vector4 vector = new (r, g, b, a);
|
||||
Color color = vector;
|
||||
Assert.Equal (r, color.R);
|
||||
Assert.Equal (g, color.G);
|
||||
Assert.Equal (b, color.B);
|
||||
Assert.Equal (a, color.A);
|
||||
}
|
||||
|
||||
Assert.Equal (r, color.R);
|
||||
Assert.Equal (g, color.G);
|
||||
Assert.Equal (b, color.B);
|
||||
Assert.Equal (a, color.A);
|
||||
}
|
||||
[Theory]
|
||||
[CombinatorialData]
|
||||
[Trait ("Category", "Operators")]
|
||||
public void ImplicitOperator_ToInt32_ReturnsCorrectInt32Value (
|
||||
[CombinatorialRandomData (Count = 16)] int expectedValue
|
||||
)
|
||||
{
|
||||
Color color = new (expectedValue);
|
||||
|
||||
[Theory]
|
||||
[CombinatorialData]
|
||||
[Trait ("Category", "Operators")]
|
||||
public void ImplicitOperator_ToInt32_ReturnsCorrectInt32Value ([CombinatorialRandomData (Count = 16)] int expectedValue)
|
||||
{
|
||||
Color color = new (expectedValue);
|
||||
int colorAsInt32 = color;
|
||||
|
||||
int colorAsInt32 = color;
|
||||
Assert.Equal (expectedValue, colorAsInt32);
|
||||
}
|
||||
|
||||
Assert.Equal (expectedValue, colorAsInt32);
|
||||
}
|
||||
[Theory]
|
||||
[CombinatorialData]
|
||||
[Trait ("Category", "Operators")]
|
||||
public void ImplicitOperator_ToUInt32_ReturnsCorrectUInt32Value (
|
||||
[CombinatorialRandomData (Count = 16)] uint expectedValue
|
||||
)
|
||||
{
|
||||
Color color = new (expectedValue);
|
||||
|
||||
[Theory]
|
||||
[CombinatorialData]
|
||||
[Trait ("Category", "Operators")]
|
||||
public void ImplicitOperator_ToUInt32_ReturnsCorrectUInt32Value ([CombinatorialRandomData (Count = 16)] uint expectedValue)
|
||||
{
|
||||
Color color = new (expectedValue);
|
||||
uint colorAsInt32 = color;
|
||||
|
||||
uint colorAsInt32 = color;
|
||||
Assert.Equal (expectedValue, colorAsInt32);
|
||||
}
|
||||
|
||||
Assert.Equal (expectedValue, colorAsInt32);
|
||||
}
|
||||
[Theory]
|
||||
[CombinatorialData]
|
||||
[Trait ("Category", "Operators")]
|
||||
public void ImplicitOperator_ToVector4_ReturnsCorrectVector4Value (
|
||||
[CombinatorialRange (0, 255, 51)] byte r,
|
||||
[CombinatorialRange (0, 255, 51)] byte g,
|
||||
[CombinatorialRange (0, 255, 51)] byte b,
|
||||
[CombinatorialValues (0, 255)] byte a
|
||||
)
|
||||
{
|
||||
Color color = new (r, g, b, a);
|
||||
Vector4 vector = color;
|
||||
|
||||
[Theory]
|
||||
[CombinatorialData]
|
||||
[Trait ("Category", "Operators")]
|
||||
public void ImplicitOperator_ToVector4_ReturnsCorrectVector4Value ([CombinatorialRange (0, 255, 51)] byte r, [CombinatorialRange (0, 255, 51)] byte g, [CombinatorialRange (0, 255, 51)] byte b, [CombinatorialValues (0, 255)] byte a)
|
||||
{
|
||||
Color color = new (r, g, b, a);
|
||||
Vector4 vector = color;
|
||||
|
||||
Assert.Equal (r, vector.X);
|
||||
Assert.Equal (g, vector.Y);
|
||||
Assert.Equal (b, vector.Z);
|
||||
Assert.Equal (a, vector.W);
|
||||
}
|
||||
Assert.Equal (r, vector.X);
|
||||
Assert.Equal (g, vector.Y);
|
||||
Assert.Equal (b, vector.Z);
|
||||
Assert.Equal (a, vector.W);
|
||||
}
|
||||
}
|
||||
public static partial class ColorTestsTheoryDataGenerators {
|
||||
|
||||
public static TheoryData<ColorName, Color> ExplicitOperator_FromColorName_RoundTripsCorrectly ()
|
||||
{
|
||||
TheoryData<ColorName, Color> data = [];
|
||||
data.Add (ColorName.Black, new Color (12, 12, 12));
|
||||
data.Add (ColorName.Blue, new Color (0, 55, 218));
|
||||
data.Add (ColorName.Green, new Color (19, 161, 14));
|
||||
data.Add (ColorName.Cyan, new Color (58, 150, 221));
|
||||
data.Add (ColorName.Red, new Color (197, 15, 31));
|
||||
data.Add (ColorName.Magenta, new Color (136, 23, 152));
|
||||
data.Add (ColorName.Yellow, new Color (128, 64, 32));
|
||||
data.Add (ColorName.Gray, new Color (204, 204, 204));
|
||||
data.Add (ColorName.DarkGray, new Color (118, 118, 118));
|
||||
data.Add (ColorName.BrightBlue, new Color (59, 120, 255));
|
||||
data.Add (ColorName.BrightGreen, new Color (22, 198, 12));
|
||||
data.Add (ColorName.BrightCyan, new Color (97, 214, 214));
|
||||
data.Add (ColorName.BrightRed, new Color (231, 72, 86));
|
||||
data.Add (ColorName.BrightMagenta, new Color (180, 0, 158));
|
||||
data.Add (ColorName.BrightYellow, new Color (249, 241, 165));
|
||||
data.Add (ColorName.White, new Color (242, 242, 242));
|
||||
return data;
|
||||
}
|
||||
public static partial class ColorTestsTheoryDataGenerators
|
||||
{
|
||||
public static TheoryData<ColorName, Color> ExplicitOperator_FromColorName_RoundTripsCorrectly ()
|
||||
{
|
||||
TheoryData<ColorName, Color> data = []
|
||||
;
|
||||
data.Add (ColorName.Black, new Color (12, 12, 12));
|
||||
data.Add (ColorName.Blue, new Color (0, 55, 218));
|
||||
data.Add (ColorName.Green, new Color (19, 161, 14));
|
||||
data.Add (ColorName.Cyan, new Color (58, 150, 221));
|
||||
data.Add (ColorName.Red, new Color (197, 15, 31));
|
||||
data.Add (ColorName.Magenta, new Color (136, 23, 152));
|
||||
data.Add (ColorName.Yellow, new Color (128, 64, 32));
|
||||
data.Add (ColorName.Gray, new Color (204, 204, 204));
|
||||
data.Add (ColorName.DarkGray, new Color (118, 118, 118));
|
||||
data.Add (ColorName.BrightBlue, new Color (59, 120, 255));
|
||||
data.Add (ColorName.BrightGreen, new Color (22, 198, 12));
|
||||
data.Add (ColorName.BrightCyan, new Color (97, 214, 214));
|
||||
data.Add (ColorName.BrightRed, new Color (231, 72, 86));
|
||||
data.Add (ColorName.BrightMagenta, new Color (180, 0, 158));
|
||||
data.Add (ColorName.BrightYellow, new Color (249, 241, 165));
|
||||
data.Add (ColorName.White, new Color (242, 242, 242));
|
||||
|
||||
public static TheoryData<FieldInfo, int> Fields_At_Expected_Offsets ()
|
||||
{
|
||||
TheoryData<FieldInfo, int> data = [];
|
||||
data.Add (typeof (Color).GetField ("Argb", BindingFlags.Instance | BindingFlags.Public | BindingFlags.ExactBinding), 0);
|
||||
data.Add (typeof (Color).GetField ("Rgba", BindingFlags.Instance | BindingFlags.Public | BindingFlags.ExactBinding), 0);
|
||||
data.Add (typeof (Color).GetField ("B", BindingFlags.Instance | BindingFlags.Public | BindingFlags.ExactBinding), 0);
|
||||
data.Add (typeof (Color).GetField ("G", BindingFlags.Instance | BindingFlags.Public | BindingFlags.ExactBinding), 1);
|
||||
data.Add (typeof (Color).GetField ("R", BindingFlags.Instance | BindingFlags.Public | BindingFlags.ExactBinding), 2);
|
||||
data.Add (typeof (Color).GetField ("A", BindingFlags.Instance | BindingFlags.Public | BindingFlags.ExactBinding), 3);
|
||||
return data;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public static TheoryData<FieldInfo, int> Fields_At_Expected_Offsets ()
|
||||
{
|
||||
TheoryData<FieldInfo, int> data = []
|
||||
;
|
||||
|
||||
data.Add (
|
||||
typeof (Color).GetField (
|
||||
"Argb",
|
||||
BindingFlags.Instance | BindingFlags.Public | BindingFlags.ExactBinding
|
||||
),
|
||||
0
|
||||
);
|
||||
|
||||
data.Add (
|
||||
typeof (Color).GetField (
|
||||
"Rgba",
|
||||
BindingFlags.Instance | BindingFlags.Public | BindingFlags.ExactBinding
|
||||
),
|
||||
0
|
||||
);
|
||||
|
||||
data.Add (
|
||||
typeof (Color).GetField (
|
||||
"B",
|
||||
BindingFlags.Instance | BindingFlags.Public | BindingFlags.ExactBinding
|
||||
),
|
||||
0
|
||||
);
|
||||
|
||||
data.Add (
|
||||
typeof (Color).GetField (
|
||||
"G",
|
||||
BindingFlags.Instance | BindingFlags.Public | BindingFlags.ExactBinding
|
||||
),
|
||||
1
|
||||
);
|
||||
|
||||
data.Add (
|
||||
typeof (Color).GetField (
|
||||
"R",
|
||||
BindingFlags.Instance | BindingFlags.Public | BindingFlags.ExactBinding
|
||||
),
|
||||
2
|
||||
);
|
||||
|
||||
data.Add (
|
||||
typeof (Color).GetField (
|
||||
"A",
|
||||
BindingFlags.Instance | BindingFlags.Public | BindingFlags.ExactBinding
|
||||
),
|
||||
3
|
||||
);
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,145 +4,187 @@ using System.Globalization;
|
||||
|
||||
namespace Terminal.Gui.DrawingTests;
|
||||
|
||||
public partial class ColorTests {
|
||||
[Fact]
|
||||
public void Color_ToString_WithNamedColor ()
|
||||
{
|
||||
// Arrange
|
||||
var color = new Color (0, 55, 218); // Blue
|
||||
public partial class ColorTests
|
||||
{
|
||||
[Fact]
|
||||
public void Color_ToString_WithNamedColor ()
|
||||
{
|
||||
// Arrange
|
||||
var color = new Color (0, 55, 218); // Blue
|
||||
|
||||
// Act
|
||||
var colorString = color.ToString ();
|
||||
// Act
|
||||
var colorString = color.ToString ();
|
||||
|
||||
// Assert
|
||||
Assert.Equal ("Blue", colorString);
|
||||
}
|
||||
// Assert
|
||||
Assert.Equal ("Blue", colorString);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Color_ToString_WithRGBColor ()
|
||||
{
|
||||
// Arrange
|
||||
var color = new Color (1, 64, 32); // Custom RGB color
|
||||
[Fact]
|
||||
public void Color_ToString_WithRGBColor ()
|
||||
{
|
||||
// Arrange
|
||||
var color = new Color (1, 64, 32); // Custom RGB color
|
||||
|
||||
// Act
|
||||
var colorString = color.ToString ();
|
||||
// Act
|
||||
var colorString = color.ToString ();
|
||||
|
||||
// Assert
|
||||
Assert.Equal ("#014020", colorString);
|
||||
}
|
||||
// Assert
|
||||
Assert.Equal ("#014020", colorString);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[CombinatorialData]
|
||||
public void Parse_And_ToString_RoundTrip_For_Known_FormatStrings ([CombinatorialValues (null, "", "g", "G", "d", "D")] string formatString, [CombinatorialValues (0, 64, 255)] byte r, [CombinatorialValues (0, 64, 255)] byte g, [CombinatorialValues (0, 64, 255)] byte b)
|
||||
{
|
||||
Color constructedColor = new (r, g, b, 255);
|
||||
[Theory]
|
||||
[CombinatorialData]
|
||||
public void Parse_And_ToString_RoundTrip_For_Known_FormatStrings (
|
||||
[CombinatorialValues (null, "", "g", "G", "d", "D")] string formatString,
|
||||
[CombinatorialValues (0, 64, 255)] byte r,
|
||||
[CombinatorialValues (0, 64, 255)] byte g,
|
||||
[CombinatorialValues (0, 64, 255)] byte b
|
||||
)
|
||||
{
|
||||
Color constructedColor = new (r, g, b, 255);
|
||||
|
||||
// Pre-conditions for the rest of the test to be valid
|
||||
Assert.Equal (r, constructedColor.R);
|
||||
Assert.Equal (g, constructedColor.G);
|
||||
Assert.Equal (b, constructedColor.B);
|
||||
Assert.Equal (255, constructedColor.A);
|
||||
// Pre-conditions for the rest of the test to be valid
|
||||
Assert.Equal (r, constructedColor.R);
|
||||
Assert.Equal (g, constructedColor.G);
|
||||
Assert.Equal (b, constructedColor.B);
|
||||
Assert.Equal (255, constructedColor.A);
|
||||
|
||||
//Get the ToString result with the specified format string
|
||||
string formattedColorString = constructedColor.ToString (formatString);
|
||||
//Get the ToString result with the specified format string
|
||||
var formattedColorString = constructedColor.ToString (formatString);
|
||||
|
||||
// Now parse that string
|
||||
Color parsedColor = Color.Parse (formattedColorString);
|
||||
// Now parse that string
|
||||
Color parsedColor = Color.Parse (formattedColorString);
|
||||
|
||||
// They should have identical underlying values
|
||||
Assert.Equal (constructedColor.Argb, parsedColor.Argb);
|
||||
}
|
||||
// They should have identical underlying values
|
||||
Assert.Equal (constructedColor.Argb, parsedColor.Argb);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[CombinatorialData]
|
||||
public void ToString_WithInvariantCultureAndNullString_IsSameAsParameterless ([CombinatorialValues (0, 64, 128, 255)] byte r, [CombinatorialValues (0, 64, 128, 255)] byte g, [CombinatorialValues (0, 64, 128, 255)] byte b)
|
||||
{
|
||||
string expected = $"#{r:X2}{g:X2}{b:X2}";
|
||||
Color testColor = new (r, g, b);
|
||||
[Theory]
|
||||
[CombinatorialData]
|
||||
public void ToString_WithInvariantCultureAndNullString_IsSameAsParameterless (
|
||||
[CombinatorialValues (0, 64, 128, 255)] byte r,
|
||||
[CombinatorialValues (0, 64, 128, 255)] byte g,
|
||||
[CombinatorialValues (0, 64, 128, 255)] byte b
|
||||
)
|
||||
{
|
||||
var expected = $"#{r:X2}{g:X2}{b:X2}";
|
||||
Color testColor = new (r, g, b);
|
||||
|
||||
string testStringWithExplicitInvariantCulture = testColor.ToString (null, CultureInfo.InvariantCulture);
|
||||
Assert.Equal (expected, testStringWithExplicitInvariantCulture);
|
||||
var testStringWithExplicitInvariantCulture = testColor.ToString (null, CultureInfo.InvariantCulture);
|
||||
Assert.Equal (expected, testStringWithExplicitInvariantCulture);
|
||||
|
||||
var parameterlessToStringValue = testColor.ToString ();
|
||||
Assert.Equal (parameterlessToStringValue, testStringWithExplicitInvariantCulture);
|
||||
}
|
||||
|
||||
string parameterlessToStringValue = testColor.ToString ();
|
||||
Assert.Equal (parameterlessToStringValue, testStringWithExplicitInvariantCulture);
|
||||
}
|
||||
[Theory]
|
||||
[MemberData (
|
||||
nameof (ColorTestsTheoryDataGenerators.TryParse_string_Returns_False_For_Invalid_Inputs),
|
||||
MemberType = typeof (ColorTestsTheoryDataGenerators)
|
||||
)]
|
||||
public void TryParse_string_Returns_False_For_Invalid_Inputs (string? input)
|
||||
{
|
||||
bool tryParseStatus = Color.TryParse (input, out Color? color);
|
||||
Assert.False (tryParseStatus);
|
||||
Assert.Null (color);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData (nameof (ColorTestsTheoryDataGenerators.TryParse_string_Returns_False_For_Invalid_Inputs), MemberType = typeof (ColorTestsTheoryDataGenerators))]
|
||||
public void TryParse_string_Returns_False_For_Invalid_Inputs (string input)
|
||||
{
|
||||
bool tryParseStatus = Color.TryParse (input, out Color? color);
|
||||
Assert.False (tryParseStatus);
|
||||
Assert.Null (color);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData (nameof (ColorTestsTheoryDataGenerators.TryParse_string_Returns_True_For_Valid_Inputs), MemberType = typeof (ColorTestsTheoryDataGenerators))]
|
||||
public void TryParse_string_Returns_True_For_Valid_Inputs (string input, int expectedColorArgb)
|
||||
{
|
||||
bool tryParseStatus = Color.TryParse (input, out Color? color);
|
||||
Assert.True (tryParseStatus);
|
||||
Assert.NotNull (color);
|
||||
Assert.IsType<Color> (color);
|
||||
Assert.Equal (expectedColorArgb, color.Value.Rgba);
|
||||
}
|
||||
[Theory]
|
||||
[MemberData (
|
||||
nameof (ColorTestsTheoryDataGenerators.TryParse_string_Returns_True_For_Valid_Inputs),
|
||||
MemberType = typeof (ColorTestsTheoryDataGenerators)
|
||||
)]
|
||||
public void TryParse_string_Returns_True_For_Valid_Inputs (string input, int expectedColorArgb)
|
||||
{
|
||||
bool tryParseStatus = Color.TryParse (input, out Color? color);
|
||||
Assert.True (tryParseStatus);
|
||||
Assert.NotNull (color);
|
||||
Assert.IsType<Color> (color);
|
||||
Assert.Equal (expectedColorArgb, color.Value.Rgba);
|
||||
}
|
||||
}
|
||||
public static partial class ColorTestsTheoryDataGenerators {
|
||||
public static TheoryData<string?> TryParse_string_Returns_False_For_Invalid_Inputs ()
|
||||
{
|
||||
TheoryData<string?> values = [
|
||||
null
|
||||
];
|
||||
for ( char i = char.MinValue; i < 255; i++ ) {
|
||||
if ( !char.IsAsciiDigit (i) ) {
|
||||
values.Add ($"rgb({i},{i},{i})");
|
||||
values.Add ($"rgba({i},{i},{i})");
|
||||
}
|
||||
if ( !char.IsAsciiHexDigit (i) ) {
|
||||
values.Add ($"#{i}{i}{i}{i}{i}{i}");
|
||||
values.Add ($"#{i}{i}{i}{i}{i}{i}{i}{i}");
|
||||
}
|
||||
}
|
||||
//Also throw in a couple of just badly formatted strings
|
||||
values.Add ("rgbaa(1,2,3,4))");
|
||||
values.Add ("#rgb(1,FF,3,4)");
|
||||
values.Add ("rgb(1,FF,3,4");
|
||||
values.Add ("rgb(1,2,3,4.5))");
|
||||
return values;
|
||||
}
|
||||
public static TheoryData<string?, int> TryParse_string_Returns_True_For_Valid_Inputs ()
|
||||
{
|
||||
TheoryData<string?, int> values = [];
|
||||
for ( byte i = 16; i < 224; i += 32 ) {
|
||||
// Using this so the span only has to be written one way.
|
||||
int expectedRgb = BinaryPrimitives.ReadInt32LittleEndian ([(byte)(i + 16), i, (byte)(i - 16), 255]);
|
||||
int expectedRgba = BinaryPrimitives.ReadInt32LittleEndian ([(byte)(i + 16), i, (byte)(i - 16), i]);
|
||||
values.Add ($"rgb({i - 16:D},{i:D},{i + 16:D})", expectedRgb);
|
||||
values.Add ($"rgb({i - 16:D},{i:D},{i + 16:D},{i:D})", expectedRgba);
|
||||
values.Add ($"rgb({i - 16:D},{i:D},{i + 16:D})", expectedRgb);
|
||||
values.Add ($"rgba({i - 16:D},{i:D},{i + 16:D},{i:D})", expectedRgba);
|
||||
values.Add ($"#{i - 16:X2}{i:X2}{i + 16:X2}", expectedRgb);
|
||||
values.Add ($"#{i:X2}{i - 16:X2}{i:X2}{i + 16:X2}", expectedRgba);
|
||||
}
|
||||
for ( byte i = 1; i < 0xE; i++ ) {
|
||||
values.Add ($"#{i - 1:X0}{i:X0}{i + 1:X0}", BinaryPrimitives.ReadInt32LittleEndian (
|
||||
[
|
||||
// Have to stick the least significant 4 bits in the most significant 4 bits to duplicate the hex values
|
||||
// Breaking this out just so it's easier to see.
|
||||
(byte)(i + 1 | i + 1 << 4),
|
||||
(byte)(i | i << 4),
|
||||
(byte)(i - 1 | i - 1 << 4),
|
||||
255
|
||||
]));
|
||||
values.Add ($"#{i:X0}{i - 1:X0}{i:X0}{i + 1:X0}", BinaryPrimitives.ReadInt32LittleEndian (
|
||||
[
|
||||
(byte)(i + 1 | i + 1 << 4),
|
||||
(byte)(i | i << 4),
|
||||
(byte)(i - 1 | i - 1 << 4),
|
||||
(byte)(i | i << 4)
|
||||
]));
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
public static partial class ColorTestsTheoryDataGenerators
|
||||
{
|
||||
public static TheoryData<string?> TryParse_string_Returns_False_For_Invalid_Inputs ()
|
||||
{
|
||||
TheoryData<string?> values =
|
||||
[
|
||||
null
|
||||
]
|
||||
;
|
||||
|
||||
for (var i = char.MinValue; i < 255; i++)
|
||||
{
|
||||
if (!char.IsAsciiDigit (i))
|
||||
{
|
||||
values.Add ($"rgb({i},{i},{i})");
|
||||
values.Add ($"rgba({i},{i},{i})");
|
||||
}
|
||||
|
||||
if (!char.IsAsciiHexDigit (i))
|
||||
{
|
||||
values.Add ($"#{i}{i}{i}{i}{i}{i}");
|
||||
values.Add ($"#{i}{i}{i}{i}{i}{i}{i}{i}");
|
||||
}
|
||||
}
|
||||
|
||||
//Also throw in a couple of just badly formatted strings
|
||||
values.Add ("rgbaa(1,2,3,4))");
|
||||
values.Add ("#rgb(1,FF,3,4)");
|
||||
values.Add ("rgb(1,FF,3,4");
|
||||
values.Add ("rgb(1,2,3,4.5))");
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
public static TheoryData<string?, int> TryParse_string_Returns_True_For_Valid_Inputs ()
|
||||
{
|
||||
TheoryData<string?, int> values = []
|
||||
;
|
||||
|
||||
for (byte i = 16; i < 224; i += 32)
|
||||
{
|
||||
// Using this so the span only has to be written one way.
|
||||
int expectedRgb = BinaryPrimitives.ReadInt32LittleEndian ([(byte)(i + 16), i, (byte)(i - 16), 255]);
|
||||
int expectedRgba = BinaryPrimitives.ReadInt32LittleEndian ([(byte)(i + 16), i, (byte)(i - 16), i]);
|
||||
values.Add ($"rgb({i - 16:D},{i:D},{i + 16:D})", expectedRgb);
|
||||
values.Add ($"rgb({i - 16:D},{i:D},{i + 16:D},{i:D})", expectedRgba);
|
||||
values.Add ($"rgb({i - 16:D},{i:D},{i + 16:D})", expectedRgb);
|
||||
values.Add ($"rgba({i - 16:D},{i:D},{i + 16:D},{i:D})", expectedRgba);
|
||||
values.Add ($"#{i - 16:X2}{i:X2}{i + 16:X2}", expectedRgb);
|
||||
values.Add ($"#{i:X2}{i - 16:X2}{i:X2}{i + 16:X2}", expectedRgba);
|
||||
}
|
||||
|
||||
for (byte i = 1; i < 0xE; i++)
|
||||
{
|
||||
values.Add (
|
||||
$"#{i - 1:X0}{i:X0}{i + 1:X0}",
|
||||
BinaryPrimitives.ReadInt32LittleEndian (
|
||||
[
|
||||
// Have to stick the least significant 4 bits in the most significant 4 bits to duplicate the hex values
|
||||
// Breaking this out just so it's easier to see.
|
||||
(byte)((i + 1) | ((i + 1) << 4)),
|
||||
(byte)(i | (i << 4)),
|
||||
(byte)((i - 1) | ((i - 1) << 4)),
|
||||
255
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
values.Add (
|
||||
$"#{i:X0}{i - 1:X0}{i:X0}{i + 1:X0}",
|
||||
BinaryPrimitives.ReadInt32LittleEndian (
|
||||
[
|
||||
(byte)((i + 1) | ((i + 1) << 4)),
|
||||
(byte)(i | (i << 4)),
|
||||
(byte)((i - 1) | ((i - 1) << 4)),
|
||||
(byte)(i | (i << 4))
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,133 +3,141 @@ using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Terminal.Gui.DrawingTests;
|
||||
|
||||
public partial class ColorTests {
|
||||
public partial class ColorTests
|
||||
{
|
||||
[Fact]
|
||||
[Trait ("Category", "Type Checks")]
|
||||
[Trait ("Category", "Change Control")]
|
||||
public void ColorName_Has_Exactly_16_Defined_Values () { Assert.Equal (16, Enum.GetValues<ColorName> ().DistinctBy (static cname => (int)cname).Count ()); }
|
||||
|
||||
[Fact]
|
||||
[Trait ("Category", "Type Checks")]
|
||||
[Trait ("Category", "Change Control")]
|
||||
public void ColorName_Has_Exactly_16_Defined_Values () => Assert.Equal (16, Enum.GetValues<ColorName> ().DistinctBy (static cname => (int)cname).Count ());
|
||||
[Theory]
|
||||
[Trait ("Category", "Type Checks")]
|
||||
[Trait ("Category", "Change Control")]
|
||||
[MemberData (
|
||||
nameof (ColorTestsTheoryDataGenerators.ColorName_HasCorrectOrdinals),
|
||||
MemberType = typeof (ColorTestsTheoryDataGenerators)
|
||||
)]
|
||||
public void ColorName_HasCorrectOrdinals (ColorName cname, int ordinal) { Assert.Equal ((int)cname, ordinal); }
|
||||
|
||||
[Theory]
|
||||
[Trait ("Category", "Type Checks")]
|
||||
[Trait ("Category", "Change Control")]
|
||||
[MemberData (nameof (ColorTestsTheoryDataGenerators.ColorName_HasCorrectOrdinals), MemberType = typeof (ColorTestsTheoryDataGenerators))]
|
||||
public void ColorName_HasCorrectOrdinals (ColorName cname, int ordinal)
|
||||
{
|
||||
Assert.Equal ((int)cname, ordinal);
|
||||
}
|
||||
[Fact]
|
||||
[Trait ("Category", "Type Checks")]
|
||||
[Trait ("Category", "Change Control")]
|
||||
[SkipLocalsInit]
|
||||
public unsafe void Fields_At_Expected_Offsets ()
|
||||
{
|
||||
// Raw write to the stack and read-back as a Color
|
||||
// Byte order is little endian
|
||||
Color* c = stackalloc Color [1];
|
||||
var rgba = (int*)c;
|
||||
*rgba = 0;
|
||||
|
||||
[Fact]
|
||||
[Trait ("Category", "Type Checks")]
|
||||
[Trait ("Category", "Change Control")]
|
||||
[SkipLocalsInit]
|
||||
public unsafe void Fields_At_Expected_Offsets ()
|
||||
{
|
||||
// Raw write to the stack and read-back as a Color
|
||||
// Byte order is little endian
|
||||
Color* c = stackalloc Color [1];
|
||||
int* rgba = (int*)c;
|
||||
*rgba = 0;
|
||||
// Pre-conditions. Ensure everything is zero;
|
||||
Assert.Equal (0, c->Rgba);
|
||||
Assert.Equal (0u, c->Argb);
|
||||
Assert.Equal ((byte)0, c->R);
|
||||
Assert.Equal ((byte)0, c->G);
|
||||
Assert.Equal ((byte)0, c->B);
|
||||
Assert.Equal ((byte)0, c->A);
|
||||
|
||||
// Pre-conditions. Ensure everything is zero;
|
||||
Assert.Equal (0, c->Rgba);
|
||||
Assert.Equal (0u, c->Argb);
|
||||
Assert.Equal ((byte)0, c->R);
|
||||
Assert.Equal ((byte)0, c->G);
|
||||
Assert.Equal ((byte)0, c->B);
|
||||
Assert.Equal ((byte)0, c->A);
|
||||
var bytePointer = (byte*)c;
|
||||
|
||||
byte* bytePointer = (byte*)c;
|
||||
// Write value to first byte and read it back in B
|
||||
*bytePointer = 239;
|
||||
Assert.Equal (239, c->Rgba);
|
||||
Assert.Equal (239u, c->Argb);
|
||||
Assert.Equal ((byte)239, c->B);
|
||||
Assert.Equal ((byte)0, c->G);
|
||||
Assert.Equal ((byte)0, c->R);
|
||||
Assert.Equal ((byte)0, c->A);
|
||||
// Write value to first byte and read it back in B
|
||||
*bytePointer = 239;
|
||||
Assert.Equal (239, c->Rgba);
|
||||
Assert.Equal (239u, c->Argb);
|
||||
Assert.Equal ((byte)239, c->B);
|
||||
Assert.Equal ((byte)0, c->G);
|
||||
Assert.Equal ((byte)0, c->R);
|
||||
Assert.Equal ((byte)0, c->A);
|
||||
|
||||
// Move to offset 1, write the next value, and check everything again.
|
||||
bytePointer++;
|
||||
*bytePointer = 190;
|
||||
Assert.Equal (48879, c->Rgba);
|
||||
Assert.Equal (48879u, c->Argb);
|
||||
Assert.Equal ((byte)239, c->B);
|
||||
Assert.Equal ((byte)190, c->G);
|
||||
Assert.Equal ((byte)0, c->R);
|
||||
Assert.Equal ((byte)0, c->A);
|
||||
// Move to offset 1, write the next value, and check everything again.
|
||||
bytePointer++;
|
||||
*bytePointer = 190;
|
||||
Assert.Equal (48879, c->Rgba);
|
||||
Assert.Equal (48879u, c->Argb);
|
||||
Assert.Equal ((byte)239, c->B);
|
||||
Assert.Equal ((byte)190, c->G);
|
||||
Assert.Equal ((byte)0, c->R);
|
||||
Assert.Equal ((byte)0, c->A);
|
||||
|
||||
// Move to offset 2, write the next value, and check everything again.
|
||||
bytePointer++;
|
||||
*bytePointer = 173;
|
||||
Assert.Equal (11386607, c->Rgba);
|
||||
Assert.Equal (11386607u, c->Argb);
|
||||
Assert.Equal ((byte)239, c->B);
|
||||
Assert.Equal ((byte)190, c->G);
|
||||
Assert.Equal ((byte)173, c->R);
|
||||
Assert.Equal ((byte)0, c->A);
|
||||
// Move to offset 2, write the next value, and check everything again.
|
||||
bytePointer++;
|
||||
*bytePointer = 173;
|
||||
Assert.Equal (11386607, c->Rgba);
|
||||
Assert.Equal (11386607u, c->Argb);
|
||||
Assert.Equal ((byte)239, c->B);
|
||||
Assert.Equal ((byte)190, c->G);
|
||||
Assert.Equal ((byte)173, c->R);
|
||||
Assert.Equal ((byte)0, c->A);
|
||||
|
||||
// Move to offset 3, write the next value, and check everything again.
|
||||
bytePointer++;
|
||||
*bytePointer = 222;
|
||||
Assert.Equal (-559038737, c->Rgba);
|
||||
Assert.Equal (0x_DEAD_BEEF, c->Argb);
|
||||
Assert.Equal ((byte)239, c->B);
|
||||
Assert.Equal ((byte)190, c->G);
|
||||
Assert.Equal ((byte)173, c->R);
|
||||
Assert.Equal ((byte)222, c->A);
|
||||
}
|
||||
// Move to offset 3, write the next value, and check everything again.
|
||||
bytePointer++;
|
||||
*bytePointer = 222;
|
||||
Assert.Equal (-559038737, c->Rgba);
|
||||
Assert.Equal (0x_DEAD_BEEF, c->Argb);
|
||||
Assert.Equal ((byte)239, c->B);
|
||||
Assert.Equal ((byte)190, c->G);
|
||||
Assert.Equal ((byte)173, c->R);
|
||||
Assert.Equal ((byte)222, c->A);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[Trait ("Category", "Type Checks")]
|
||||
[Trait ("Category", "Change Control")]
|
||||
[CombinatorialData]
|
||||
public void Implements_Expected_Interfaces (
|
||||
[CombinatorialValues (
|
||||
typeof (IEquatable<Color>),
|
||||
typeof (ISpanParsable<Color>),
|
||||
typeof (IUtf8SpanParsable<Color>),
|
||||
typeof (ISpanFormattable),
|
||||
typeof (IUtf8SpanFormattable),
|
||||
typeof (IMinMaxValue<Color>))]
|
||||
Type expectedInterface)
|
||||
{
|
||||
Assert.Contains (expectedInterface, typeof (Color).GetInterfaces ());
|
||||
}
|
||||
[Fact]
|
||||
[Trait ("Category", "Type Checks")]
|
||||
[Trait ("Category", "Change Control")]
|
||||
public void Is_Explicit_LayoutKind ()
|
||||
{
|
||||
Assert.True (typeof (Color).IsExplicitLayout);
|
||||
}
|
||||
[Fact]
|
||||
[Trait ("Category", "Type Checks")]
|
||||
[Trait ("Category", "Change Control")]
|
||||
public void Is_Value_Type () =>
|
||||
// prove that Color is a value type
|
||||
Assert.True (typeof (Color).IsValueType);
|
||||
[Theory]
|
||||
[Trait ("Category", "Type Checks")]
|
||||
[Trait ("Category", "Change Control")]
|
||||
[CombinatorialData]
|
||||
public void Implements_Expected_Interfaces (
|
||||
[CombinatorialValues (
|
||||
typeof (IEquatable<Color>),
|
||||
typeof (ISpanParsable<Color>),
|
||||
typeof (IUtf8SpanParsable<Color>),
|
||||
typeof (ISpanFormattable),
|
||||
typeof (IUtf8SpanFormattable),
|
||||
typeof (IMinMaxValue<Color>)
|
||||
)]
|
||||
Type expectedInterface
|
||||
)
|
||||
{
|
||||
Assert.Contains (expectedInterface, typeof (Color).GetInterfaces ());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait ("Category", "Type Checks")]
|
||||
[Trait ("Category", "Change Control")]
|
||||
public void Is_Explicit_LayoutKind () { Assert.True (typeof (Color).IsExplicitLayout); }
|
||||
|
||||
[Fact]
|
||||
[Trait ("Category", "Type Checks")]
|
||||
[Trait ("Category", "Change Control")]
|
||||
public void Is_Value_Type ()
|
||||
{
|
||||
// prove that Color is a value type
|
||||
Assert.True (typeof (Color).IsValueType);
|
||||
}
|
||||
}
|
||||
public static partial class ColorTestsTheoryDataGenerators {
|
||||
public static TheoryData<ColorName, int> ColorName_HasCorrectOrdinals ()
|
||||
{
|
||||
TheoryData<ColorName, int> data = [];
|
||||
data.Add (ColorName.Black, 0);
|
||||
data.Add (ColorName.Blue, 1);
|
||||
data.Add (ColorName.Green, 2);
|
||||
data.Add (ColorName.Cyan, 3);
|
||||
data.Add (ColorName.Red, 4);
|
||||
data.Add (ColorName.Magenta, 5);
|
||||
data.Add (ColorName.Yellow, 6);
|
||||
data.Add (ColorName.Gray, 7);
|
||||
data.Add (ColorName.DarkGray, 8);
|
||||
data.Add (ColorName.BrightBlue, 9);
|
||||
data.Add (ColorName.BrightGreen, 10);
|
||||
data.Add (ColorName.BrightCyan, 11);
|
||||
data.Add (ColorName.BrightRed, 12);
|
||||
data.Add (ColorName.BrightMagenta, 13);
|
||||
data.Add (ColorName.BrightYellow, 14);
|
||||
data.Add (ColorName.White, 15);
|
||||
return data;
|
||||
}
|
||||
|
||||
public static partial class ColorTestsTheoryDataGenerators
|
||||
{
|
||||
public static TheoryData<ColorName, int> ColorName_HasCorrectOrdinals ()
|
||||
{
|
||||
TheoryData<ColorName, int> data = []
|
||||
;
|
||||
data.Add (ColorName.Black, 0);
|
||||
data.Add (ColorName.Blue, 1);
|
||||
data.Add (ColorName.Green, 2);
|
||||
data.Add (ColorName.Cyan, 3);
|
||||
data.Add (ColorName.Red, 4);
|
||||
data.Add (ColorName.Magenta, 5);
|
||||
data.Add (ColorName.Yellow, 6);
|
||||
data.Add (ColorName.Gray, 7);
|
||||
data.Add (ColorName.DarkGray, 8);
|
||||
data.Add (ColorName.BrightBlue, 9);
|
||||
data.Add (ColorName.BrightGreen, 10);
|
||||
data.Add (ColorName.BrightCyan, 11);
|
||||
data.Add (ColorName.BrightRed, 12);
|
||||
data.Add (ColorName.BrightMagenta, 13);
|
||||
data.Add (ColorName.BrightYellow, 14);
|
||||
data.Add (ColorName.White, 15);
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,77 +2,94 @@
|
||||
|
||||
namespace Terminal.Gui.DrawingTests;
|
||||
|
||||
public partial class ColorTests {
|
||||
public partial class ColorTests
|
||||
{
|
||||
[Theory]
|
||||
[CombinatorialData]
|
||||
public void Argb_Returns_Expected_Value (
|
||||
[CombinatorialValues (0, 255)] byte a,
|
||||
[CombinatorialRange (0, 255, 51)] byte r,
|
||||
[CombinatorialRange (0, 153, 51)] byte g,
|
||||
[CombinatorialRange (0, 128, 32)] byte b
|
||||
)
|
||||
{
|
||||
Color color = new (r, g, b, a);
|
||||
|
||||
[Theory]
|
||||
[CombinatorialData]
|
||||
public void Argb_Returns_Expected_Value ([CombinatorialValues (0, 255)] byte a, [CombinatorialRange (0, 255, 51)] byte r, [CombinatorialRange (0, 153, 51)] byte g, [CombinatorialRange (0, 128, 32)] byte b)
|
||||
{
|
||||
Color color = new (r, g, b, a);
|
||||
// Color.Rgba is expected to be a signed int32 in little endian order (a,b,g,r)
|
||||
ReadOnlySpan<byte> littleEndianBytes = [b, g, r, a];
|
||||
uint expectedArgb = BitConverter.ToUInt32 (littleEndianBytes);
|
||||
Assert.Equal (expectedArgb, color.Argb);
|
||||
}
|
||||
// Color.Rgba is expected to be a signed int32 in little endian order (a,b,g,r)
|
||||
ReadOnlySpan<byte> littleEndianBytes = [b, g, r, a];
|
||||
var expectedArgb = BitConverter.ToUInt32 (littleEndianBytes);
|
||||
Assert.Equal (expectedArgb, color.Argb);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Color_ColorName_Get_ReturnsClosestColorName ()
|
||||
{
|
||||
// Arrange
|
||||
var color = new Color (128, 64, 40); // Custom RGB color, closest to Yellow
|
||||
var expectedColorName = ColorName.Yellow;
|
||||
[Fact]
|
||||
public void Color_ColorName_Get_ReturnsClosestColorName ()
|
||||
{
|
||||
// Arrange
|
||||
var color = new Color (128, 64, 40); // Custom RGB color, closest to Yellow
|
||||
var expectedColorName = ColorName.Yellow;
|
||||
|
||||
// Act
|
||||
var colorName = color.GetClosestNamedColor ();
|
||||
// Act
|
||||
ColorName colorName = color.GetClosestNamedColor ();
|
||||
|
||||
// Assert
|
||||
Assert.Equal (expectedColorName, colorName);
|
||||
}
|
||||
[Fact]
|
||||
public void Color_IsClosestToNamedColor_ReturnsExpectedValue ()
|
||||
{
|
||||
// Arrange
|
||||
var color1 = new Color (ColorName.Red);
|
||||
var color2 = new Color (197, 15, 31); // Red in RGB
|
||||
// Assert
|
||||
Assert.Equal (expectedColorName, colorName);
|
||||
}
|
||||
|
||||
Assert.True (color1.IsClosestToNamedColor (ColorName.Red));
|
||||
[Fact]
|
||||
public void Color_IsClosestToNamedColor_ReturnsExpectedValue ()
|
||||
{
|
||||
// Arrange
|
||||
var color1 = new Color (ColorName.Red);
|
||||
var color2 = new Color (197, 15, 31); // Red in RGB
|
||||
|
||||
Assert.True (color2.IsClosestToNamedColor (ColorName.Red));
|
||||
}
|
||||
Assert.True (color1.IsClosestToNamedColor (ColorName.Red));
|
||||
|
||||
[Theory]
|
||||
[MemberData (nameof (ColorTestsTheoryDataGenerators.FindClosestColor_ReturnsClosestColor), MemberType = typeof (ColorTestsTheoryDataGenerators))]
|
||||
public void FindClosestColor_ReturnsClosestColor (Color inputColor, ColorName expectedColorName)
|
||||
{
|
||||
var actualColorName = Color.GetClosestNamedColor (inputColor);
|
||||
Assert.True (color2.IsClosestToNamedColor (ColorName.Red));
|
||||
}
|
||||
|
||||
Assert.Equal (expectedColorName, actualColorName);
|
||||
}
|
||||
[Theory]
|
||||
[MemberData (
|
||||
nameof (ColorTestsTheoryDataGenerators.FindClosestColor_ReturnsClosestColor),
|
||||
MemberType = typeof (ColorTestsTheoryDataGenerators)
|
||||
)]
|
||||
public void FindClosestColor_ReturnsClosestColor (Color inputColor, ColorName expectedColorName)
|
||||
{
|
||||
ColorName actualColorName = Color.GetClosestNamedColor (inputColor);
|
||||
|
||||
Assert.Equal (expectedColorName, actualColorName);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[CombinatorialData]
|
||||
public void Rgba_Returns_Expected_Value ([CombinatorialValues (0, 255)] byte a, [CombinatorialRange (0, 255, 51)] byte r, [CombinatorialRange (0, 153, 51)] byte g, [CombinatorialRange (0, 128, 32)] byte b)
|
||||
{
|
||||
Color color = new (r, g, b, a);
|
||||
// Color.Rgba is expected to be a signed int32 in little endian order (a,b,g,r)
|
||||
ReadOnlySpan<byte> littleEndianBytes = [b, g, r, a];
|
||||
int expectedRgba = BitConverter.ToInt32 (littleEndianBytes);
|
||||
Assert.Equal (expectedRgba, color.Rgba);
|
||||
}
|
||||
[Theory]
|
||||
[CombinatorialData]
|
||||
public void Rgba_Returns_Expected_Value (
|
||||
[CombinatorialValues (0, 255)] byte a,
|
||||
[CombinatorialRange (0, 255, 51)] byte r,
|
||||
[CombinatorialRange (0, 153, 51)] byte g,
|
||||
[CombinatorialRange (0, 128, 32)] byte b
|
||||
)
|
||||
{
|
||||
Color color = new (r, g, b, a);
|
||||
|
||||
// Color.Rgba is expected to be a signed int32 in little endian order (a,b,g,r)
|
||||
ReadOnlySpan<byte> littleEndianBytes = [b, g, r, a];
|
||||
var expectedRgba = BitConverter.ToInt32 (littleEndianBytes);
|
||||
Assert.Equal (expectedRgba, color.Rgba);
|
||||
}
|
||||
}
|
||||
public static partial class ColorTestsTheoryDataGenerators {
|
||||
|
||||
public static TheoryData<Color, ColorName> FindClosestColor_ReturnsClosestColor ()
|
||||
{
|
||||
TheoryData<Color, ColorName> data = [];
|
||||
data.Add (new Color (0, 0), ColorName.Black);
|
||||
data.Add (new Color (255, 255, 255), ColorName.White);
|
||||
data.Add (new Color (5, 100, 255), ColorName.BrightBlue);
|
||||
data.Add (new Color (0, 255), ColorName.BrightGreen);
|
||||
data.Add (new Color (255, 70, 8), ColorName.BrightRed);
|
||||
data.Add (new Color (0, 128, 128), ColorName.Cyan);
|
||||
data.Add (new Color (128, 64, 32), ColorName.Yellow);
|
||||
return data;
|
||||
}
|
||||
public static partial class ColorTestsTheoryDataGenerators
|
||||
{
|
||||
public static TheoryData<Color, ColorName> FindClosestColor_ReturnsClosestColor ()
|
||||
{
|
||||
TheoryData<Color, ColorName> data = [];
|
||||
data.Add (new Color (0, 0), ColorName.Black);
|
||||
data.Add (new Color (255, 255, 255), ColorName.White);
|
||||
data.Add (new Color (5, 100, 255), ColorName.BrightBlue);
|
||||
data.Add (new Color (0, 255), ColorName.BrightGreen);
|
||||
data.Add (new Color (255, 70, 8), ColorName.BrightRed);
|
||||
data.Add (new Color (0, 128, 128), ColorName.Cyan);
|
||||
data.Add (new Color (128, 64, 32), ColorName.Yellow);
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,33 +1,29 @@
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using Xunit;
|
||||
|
||||
namespace Terminal.Gui.DrawingTests;
|
||||
|
||||
public class GlyphTests {
|
||||
[Fact]
|
||||
public void Default_GlyphDefinitions_Deserialize ()
|
||||
{
|
||||
var defs = new GlyphDefinitions ();
|
||||
// enumerate all properties in GlyphDefinitions
|
||||
foreach (var prop in typeof (GlyphDefinitions).GetProperties ()) {
|
||||
if (prop.PropertyType == typeof (Rune)) {
|
||||
public class GlyphTests
|
||||
{
|
||||
[Fact]
|
||||
public void Default_GlyphDefinitions_Deserialize ()
|
||||
{
|
||||
var defs = new GlyphDefinitions ();
|
||||
|
||||
// Act
|
||||
var rune = (Rune)prop.GetValue (defs);
|
||||
var json = JsonSerializer.Serialize (rune, ConfigurationManager._serializerOptions);
|
||||
var deserialized = JsonSerializer.Deserialize<Rune> (json, ConfigurationManager._serializerOptions);
|
||||
// enumerate all properties in GlyphDefinitions
|
||||
foreach (PropertyInfo prop in typeof (GlyphDefinitions).GetProperties ())
|
||||
{
|
||||
if (prop.PropertyType == typeof (Rune))
|
||||
{
|
||||
// Act
|
||||
var rune = (Rune)prop.GetValue (defs);
|
||||
string json = JsonSerializer.Serialize (rune, ConfigurationManager._serializerOptions);
|
||||
var deserialized = JsonSerializer.Deserialize<Rune> (json, ConfigurationManager._serializerOptions);
|
||||
|
||||
// Assert
|
||||
Assert.Equal (((Rune)prop.GetValue (defs)).Value, deserialized.Value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// Assert
|
||||
Assert.Equal (((Rune)prop.GetValue (defs)).Value, deserialized.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,194 +1,182 @@
|
||||
using Terminal.Gui;
|
||||
using System.Text;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Linq;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
//using GraphViewTests = Terminal.Gui.Views.GraphViewTests;
|
||||
|
||||
// Alias Console to MockConsole so we don't accidentally use Console
|
||||
using Console = Terminal.Gui.FakeConsole;
|
||||
|
||||
namespace Terminal.Gui.DrawingTests {
|
||||
public class RulerTests {
|
||||
namespace Terminal.Gui.DrawingTests;
|
||||
|
||||
readonly ITestOutputHelper output;
|
||||
|
||||
public RulerTests (ITestOutputHelper output)
|
||||
{
|
||||
this.output = output;
|
||||
}
|
||||
public class RulerTests
|
||||
{
|
||||
private readonly ITestOutputHelper _output;
|
||||
public RulerTests (ITestOutputHelper output) { _output = output; }
|
||||
|
||||
[Fact ()]
|
||||
public void Constructor_Defaults ()
|
||||
{
|
||||
var r = new Ruler ();
|
||||
Assert.Equal (0, r.Length);
|
||||
Assert.Equal (Orientation.Horizontal, r.Orientation);
|
||||
}
|
||||
[Fact]
|
||||
public void Attribute_set ()
|
||||
{
|
||||
var newAttribute = new Attribute (Color.Red, Color.Green);
|
||||
|
||||
[Fact ()]
|
||||
public void Orientation_set ()
|
||||
{
|
||||
var r = new Ruler ();
|
||||
Assert.Equal (Orientation.Horizontal, r.Orientation);
|
||||
r.Orientation = Orientation.Vertical;
|
||||
Assert.Equal (Orientation.Vertical, r.Orientation);
|
||||
}
|
||||
var r = new Ruler ();
|
||||
r.Attribute = newAttribute;
|
||||
Assert.Equal (newAttribute, r.Attribute);
|
||||
}
|
||||
|
||||
[Fact ()]
|
||||
public void Length_set ()
|
||||
{
|
||||
var r = new Ruler ();
|
||||
Assert.Equal (0, r.Length);
|
||||
r.Length = 42;
|
||||
Assert.Equal (42, r.Length);
|
||||
}
|
||||
[Fact]
|
||||
public void Constructor_Defaults ()
|
||||
{
|
||||
var r = new Ruler ();
|
||||
Assert.Equal (0, r.Length);
|
||||
Assert.Equal (Orientation.Horizontal, r.Orientation);
|
||||
}
|
||||
|
||||
[Fact ()]
|
||||
public void Attribute_set ()
|
||||
{
|
||||
var newAttribute = new Attribute (Color.Red, Color.Green);
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
public void Draw_Default ()
|
||||
{
|
||||
((FakeDriver)Application.Driver).SetBufferSize (25, 25);
|
||||
|
||||
var r = new Ruler ();
|
||||
r.Attribute = newAttribute;
|
||||
Assert.Equal (newAttribute, r.Attribute);
|
||||
}
|
||||
var r = new Ruler ();
|
||||
r.Draw (new Point (0, 0));
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"", _output);
|
||||
}
|
||||
|
||||
[Fact (), AutoInitShutdown]
|
||||
public void Draw_Default ()
|
||||
{
|
||||
((FakeDriver)Application.Driver).SetBufferSize (25, 25);
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
public void Draw_Horizontal ()
|
||||
{
|
||||
var len = 15;
|
||||
|
||||
var r = new Ruler ();
|
||||
r.Draw (new Point (0, 0));
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"", output);
|
||||
}
|
||||
// Add a frame so we can see the ruler
|
||||
var f = new FrameView { X = 0, Y = 0, Width = Dim.Fill (), Height = Dim.Fill () };
|
||||
Application.Top.Add (f);
|
||||
Application.Begin (Application.Top);
|
||||
((FakeDriver)Application.Driver).SetBufferSize (len + 5, 5);
|
||||
Assert.Equal (new Rect (0, 0, len + 5, 5), f.Frame);
|
||||
|
||||
[Fact (), AutoInitShutdown]
|
||||
public void Draw_Horizontal ()
|
||||
{
|
||||
var len = 15;
|
||||
var r = new Ruler ();
|
||||
Assert.Equal (Orientation.Horizontal, r.Orientation);
|
||||
|
||||
// Add a frame so we can see the ruler
|
||||
var f = new FrameView () {
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = Dim.Fill (),
|
||||
Height = Dim.Fill (),
|
||||
};
|
||||
Application.Top.Add (f);
|
||||
Application.Begin (Application.Top);
|
||||
((FakeDriver)Application.Driver).SetBufferSize (len + 5, 5);
|
||||
Assert.Equal (new Rect (0, 0, len + 5, 5), f.Frame);
|
||||
r.Length = len;
|
||||
r.Draw (new Point (0, 0));
|
||||
|
||||
var r = new Ruler ();
|
||||
Assert.Equal (Orientation.Horizontal, r.Orientation);
|
||||
|
||||
r.Length = len;
|
||||
r.Draw (new Point (0, 0));
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (
|
||||
@"
|
||||
|123456789|1234────┐
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
└──────────────────┘", output);
|
||||
└──────────────────┘",
|
||||
_output
|
||||
);
|
||||
|
||||
// Postive offset
|
||||
Application.Refresh ();
|
||||
r.Draw (new Point (1, 1));
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
// Postive offset
|
||||
Application.Refresh ();
|
||||
r.Draw (new Point (1, 1));
|
||||
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (
|
||||
@"
|
||||
┌──────────────────┐
|
||||
│|123456789|1234 │
|
||||
│ │
|
||||
│ │
|
||||
└──────────────────┘", output);
|
||||
└──────────────────┘",
|
||||
_output
|
||||
);
|
||||
|
||||
// Negative offset
|
||||
Application.Refresh ();
|
||||
r.Draw (new Point (-1, 1));
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
// Negative offset
|
||||
Application.Refresh ();
|
||||
r.Draw (new Point (-1, 1));
|
||||
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (
|
||||
@"
|
||||
┌──────────────────┐
|
||||
123456789|1234 │
|
||||
│ │
|
||||
│ │
|
||||
└──────────────────┘", output);
|
||||
└──────────────────┘",
|
||||
_output
|
||||
);
|
||||
|
||||
// Clip
|
||||
Application.Refresh ();
|
||||
r.Draw (new Point (10, 1));
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
// Clip
|
||||
Application.Refresh ();
|
||||
r.Draw (new Point (10, 1));
|
||||
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (
|
||||
@"
|
||||
┌──────────────────┐
|
||||
│ |123456789
|
||||
│ │
|
||||
│ │
|
||||
└──────────────────┘", output);
|
||||
}
|
||||
└──────────────────┘",
|
||||
_output
|
||||
);
|
||||
}
|
||||
|
||||
[Fact (), AutoInitShutdown]
|
||||
public void Draw_Horizontal_Start ()
|
||||
{
|
||||
var len = 15;
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
public void Draw_Horizontal_Start ()
|
||||
{
|
||||
var len = 15;
|
||||
|
||||
// Add a frame so we can see the ruler
|
||||
var f = new FrameView () {
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = Dim.Fill (),
|
||||
Height = Dim.Fill (),
|
||||
};
|
||||
Application.Top.Add (f);
|
||||
Application.Begin (Application.Top);
|
||||
((FakeDriver)Application.Driver).SetBufferSize (len + 5, 5);
|
||||
Assert.Equal (new Rect (0, 0, len + 5, 5), f.Frame);
|
||||
// Add a frame so we can see the ruler
|
||||
var f = new FrameView { X = 0, Y = 0, Width = Dim.Fill (), Height = Dim.Fill () };
|
||||
Application.Top.Add (f);
|
||||
Application.Begin (Application.Top);
|
||||
((FakeDriver)Application.Driver).SetBufferSize (len + 5, 5);
|
||||
Assert.Equal (new Rect (0, 0, len + 5, 5), f.Frame);
|
||||
|
||||
var r = new Ruler ();
|
||||
Assert.Equal (Orientation.Horizontal, r.Orientation);
|
||||
var r = new Ruler ();
|
||||
Assert.Equal (Orientation.Horizontal, r.Orientation);
|
||||
|
||||
r.Length = len;
|
||||
r.Draw (new Point (0, 0), 1);
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
r.Length = len;
|
||||
r.Draw (new Point (0, 0), 1);
|
||||
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (
|
||||
@"
|
||||
123456789|12345────┐
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
└──────────────────┘", output);
|
||||
└──────────────────┘",
|
||||
_output
|
||||
);
|
||||
|
||||
Application.Refresh ();
|
||||
r.Length = len;
|
||||
r.Draw (new Point (1, 0), 1);
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
Application.Refresh ();
|
||||
r.Length = len;
|
||||
r.Draw (new Point (1, 0), 1);
|
||||
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (
|
||||
@"
|
||||
┌123456789|12345───┐
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
└──────────────────┘", output);
|
||||
}
|
||||
└──────────────────┘",
|
||||
_output
|
||||
);
|
||||
}
|
||||
|
||||
[Fact (), AutoInitShutdown]
|
||||
public void Draw_Vertical ()
|
||||
{
|
||||
var len = 15;
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
public void Draw_Vertical ()
|
||||
{
|
||||
var len = 15;
|
||||
|
||||
// Add a frame so we can see the ruler
|
||||
var f = new FrameView () {
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = Dim.Fill (),
|
||||
Height = Dim.Fill (),
|
||||
};
|
||||
// Add a frame so we can see the ruler
|
||||
var f = new FrameView { X = 0, Y = 0, Width = Dim.Fill (), Height = Dim.Fill () };
|
||||
|
||||
Application.Top.Add (f);
|
||||
Application.Begin (Application.Top);
|
||||
((FakeDriver)Application.Driver).SetBufferSize (5, len + 5);
|
||||
Assert.Equal (new Rect (0, 0, 5, len + 5), f.Frame);
|
||||
Application.Top.Add (f);
|
||||
Application.Begin (Application.Top);
|
||||
((FakeDriver)Application.Driver).SetBufferSize (5, len + 5);
|
||||
Assert.Equal (new Rect (0, 0, 5, len + 5), f.Frame);
|
||||
|
||||
var r = new Ruler ();
|
||||
r.Orientation = Orientation.Vertical;
|
||||
r.Length = len;
|
||||
r.Draw (new Point (0, 0));
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
var r = new Ruler ();
|
||||
r.Orientation = Orientation.Vertical;
|
||||
r.Length = len;
|
||||
r.Draw (new Point (0, 0));
|
||||
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (
|
||||
@"
|
||||
-───┐
|
||||
1 │
|
||||
2 │
|
||||
@@ -208,12 +196,16 @@ namespace Terminal.Gui.DrawingTests {
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
└───┘", output);
|
||||
└───┘",
|
||||
_output
|
||||
);
|
||||
|
||||
// Postive offset
|
||||
Application.Refresh ();
|
||||
r.Draw (new Point (1, 1));
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
// Postive offset
|
||||
Application.Refresh ();
|
||||
r.Draw (new Point (1, 1));
|
||||
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (
|
||||
@"
|
||||
┌───┐
|
||||
│- │
|
||||
│1 │
|
||||
@@ -233,12 +225,16 @@ namespace Terminal.Gui.DrawingTests {
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
└───┘", output);
|
||||
└───┘",
|
||||
_output
|
||||
);
|
||||
|
||||
// Negative offset
|
||||
Application.Refresh ();
|
||||
r.Draw (new Point (1, -1));
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
// Negative offset
|
||||
Application.Refresh ();
|
||||
r.Draw (new Point (1, -1));
|
||||
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (
|
||||
@"
|
||||
┌1──┐
|
||||
│2 │
|
||||
│3 │
|
||||
@@ -258,12 +254,16 @@ namespace Terminal.Gui.DrawingTests {
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
└───┘", output);
|
||||
└───┘",
|
||||
_output
|
||||
);
|
||||
|
||||
// Clip
|
||||
Application.Refresh ();
|
||||
r.Draw (new Point (1, 10));
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
// Clip
|
||||
Application.Refresh ();
|
||||
r.Draw (new Point (1, 10));
|
||||
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (
|
||||
@"
|
||||
┌───┐
|
||||
│ │
|
||||
│ │
|
||||
@@ -283,32 +283,32 @@ namespace Terminal.Gui.DrawingTests {
|
||||
│6 │
|
||||
│7 │
|
||||
│8 │
|
||||
└9──┘", output);
|
||||
}
|
||||
└9──┘",
|
||||
_output
|
||||
);
|
||||
}
|
||||
|
||||
[Fact (), AutoInitShutdown]
|
||||
public void Draw_Vertical_Start ()
|
||||
{
|
||||
var len = 15;
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
public void Draw_Vertical_Start ()
|
||||
{
|
||||
var len = 15;
|
||||
|
||||
// Add a frame so we can see the ruler
|
||||
var f = new FrameView () {
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = Dim.Fill (),
|
||||
Height = Dim.Fill (),
|
||||
};
|
||||
// Add a frame so we can see the ruler
|
||||
var f = new FrameView { X = 0, Y = 0, Width = Dim.Fill (), Height = Dim.Fill () };
|
||||
|
||||
Application.Top.Add (f);
|
||||
Application.Begin (Application.Top);
|
||||
((FakeDriver)Application.Driver).SetBufferSize (5, len + 5);
|
||||
Assert.Equal (new Rect (0, 0, 5, len + 5), f.Frame);
|
||||
Application.Top.Add (f);
|
||||
Application.Begin (Application.Top);
|
||||
((FakeDriver)Application.Driver).SetBufferSize (5, len + 5);
|
||||
Assert.Equal (new Rect (0, 0, 5, len + 5), f.Frame);
|
||||
|
||||
var r = new Ruler ();
|
||||
r.Orientation = Orientation.Vertical;
|
||||
r.Length = len;
|
||||
r.Draw (new Point (0, 0), 1);
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
var r = new Ruler ();
|
||||
r.Orientation = Orientation.Vertical;
|
||||
r.Length = len;
|
||||
r.Draw (new Point (0, 0), 1);
|
||||
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (
|
||||
@"
|
||||
1───┐
|
||||
2 │
|
||||
3 │
|
||||
@@ -328,12 +328,16 @@ namespace Terminal.Gui.DrawingTests {
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
└───┘", output);
|
||||
└───┘",
|
||||
_output
|
||||
);
|
||||
|
||||
Application.Refresh ();
|
||||
r.Length = len;
|
||||
r.Draw (new Point (0, 1), 1);
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
Application.Refresh ();
|
||||
r.Length = len;
|
||||
r.Draw (new Point (0, 1), 1);
|
||||
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (
|
||||
@"
|
||||
┌───┐
|
||||
1 │
|
||||
2 │
|
||||
@@ -353,9 +357,26 @@ namespace Terminal.Gui.DrawingTests {
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
└───┘", output);
|
||||
└───┘",
|
||||
_output
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void Length_set ()
|
||||
{
|
||||
var r = new Ruler ();
|
||||
Assert.Equal (0, r.Length);
|
||||
r.Length = 42;
|
||||
Assert.Equal (42, r.Length);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Orientation_set ()
|
||||
{
|
||||
var r = new Ruler ();
|
||||
Assert.Equal (Orientation.Horizontal, r.Orientation);
|
||||
r.Orientation = Orientation.Vertical;
|
||||
Assert.Equal (Orientation.Vertical, r.Orientation);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,415 +1,499 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Terminal.Gui.DrawingTests {
|
||||
public class StraightLineExtensionsTests
|
||||
{
|
||||
private ITestOutputHelper _output;
|
||||
namespace Terminal.Gui.DrawingTests;
|
||||
|
||||
public class StraightLineExtensionsTests
|
||||
{
|
||||
private readonly ITestOutputHelper _output;
|
||||
public StraightLineExtensionsTests (ITestOutputHelper output) { _output = output; }
|
||||
|
||||
public StraightLineExtensionsTests(ITestOutputHelper output)
|
||||
{
|
||||
this._output = output;
|
||||
}
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
public void LineCanvasIntegrationTest ()
|
||||
{
|
||||
var lc = new LineCanvas ();
|
||||
lc.AddLine (new Point (0, 0), 10, Orientation.Horizontal, LineStyle.Single);
|
||||
lc.AddLine (new Point (9, 0), 5, Orientation.Vertical, LineStyle.Single);
|
||||
lc.AddLine (new Point (9, 4), -10, Orientation.Horizontal, LineStyle.Single);
|
||||
lc.AddLine (new Point (0, 4), -5, Orientation.Vertical, LineStyle.Single);
|
||||
|
||||
#region Parallel Tests
|
||||
[Fact, AutoInitShutdown]
|
||||
public void TestExcludeParallel_HorizontalLines_LeftOnly ()
|
||||
{
|
||||
// x=1 to x=10
|
||||
var l1 = new StraightLine (new Point (1, 2), 10, Orientation.Horizontal, LineStyle.Single);
|
||||
var after = new StraightLine [] { l1 }
|
||||
// exclude x=3 to x=103
|
||||
.Exclude (new Point (3, 2), 100, Orientation.Horizontal)
|
||||
.ToArray ();
|
||||
// x=1 to x=2
|
||||
var afterLine = Assert.Single (after);
|
||||
Assert.Equal (l1.Start, afterLine.Start);
|
||||
Assert.Equal (2, afterLine.Length);
|
||||
}
|
||||
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void TestExcludeParallel_HorizontalLines_RightOnly ()
|
||||
{
|
||||
// x=1 to x=10
|
||||
var l1 = new StraightLine (new Point (1, 2), 10, Orientation.Horizontal, LineStyle.Single);
|
||||
var after = new StraightLine [] { l1 }
|
||||
// exclude x=0 to x=2
|
||||
.Exclude (new Point (0, 2), 3, Orientation.Horizontal)
|
||||
.ToArray ();
|
||||
// x=3 to x=10
|
||||
var afterLine = Assert.Single (after);
|
||||
Assert.Equal (3, afterLine.Start.X);
|
||||
Assert.Equal (2, afterLine.Start.Y);
|
||||
Assert.Equal (8, afterLine.Length);
|
||||
}
|
||||
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void TestExcludeParallel_HorizontalLines_HorizontalSplit ()
|
||||
{
|
||||
// x=1 to x=10
|
||||
var l1 = new StraightLine (new Point (1, 2), 10, Orientation.Horizontal, LineStyle.Single);
|
||||
var after = new StraightLine [] { l1 }
|
||||
// exclude x=4 to x=5
|
||||
.Exclude (new Point (4, 2), 2, Orientation.Horizontal)
|
||||
.ToArray ();
|
||||
// x=1 to x=3,
|
||||
// x=6 to x=10
|
||||
Assert.Equal (2, after.Length);
|
||||
var afterLeft = after [0];
|
||||
var afterRight = after [1];
|
||||
|
||||
Assert.Equal (1, afterLeft.Start.X);
|
||||
Assert.Equal (2, afterLeft.Start.Y);
|
||||
Assert.Equal (3, afterLeft.Length);
|
||||
|
||||
Assert.Equal (6, afterRight.Start.X);
|
||||
Assert.Equal (2, afterRight.Start.Y);
|
||||
Assert.Equal (5, afterRight.Length);
|
||||
}
|
||||
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void TestExcludeParallel_HorizontalLines_CoverCompletely ()
|
||||
{
|
||||
// x=1 to x=10
|
||||
var l1 = new StraightLine (new Point (1, 2), 10, Orientation.Horizontal, LineStyle.Single);
|
||||
var after = new StraightLine [] { l1 }
|
||||
// exclude x=4 to x=5
|
||||
.Exclude (new Point (1, 2), 10, Orientation.Horizontal)
|
||||
.ToArray ();
|
||||
Assert.Empty (after);
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void TestExcludeParallel_VerticalLines_TopOnly ()
|
||||
{
|
||||
// y=1 to y=10
|
||||
var l1 = new StraightLine (new Point (2, 1), 10, Orientation.Vertical, LineStyle.Single);
|
||||
var after = new StraightLine [] { l1 }
|
||||
// exclude y=3 to y=103
|
||||
.Exclude (new Point (2, 3), 100, Orientation.Vertical)
|
||||
.ToArray ();
|
||||
// y=1 to y=2
|
||||
var afterLine = Assert.Single (after);
|
||||
Assert.Equal (l1.Start, afterLine.Start);
|
||||
Assert.Equal (2, afterLine.Length);
|
||||
}
|
||||
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void TestExcludeParallel_HorizontalLines_BottomOnly ()
|
||||
{
|
||||
// y=1 to y=10
|
||||
var l1 = new StraightLine (new Point (2, 1), 10, Orientation.Vertical, LineStyle.Single);
|
||||
var after = new StraightLine [] { l1 }
|
||||
// exclude y=0 to y=2
|
||||
.Exclude (new Point (2,0), 3, Orientation.Vertical)
|
||||
.ToArray ();
|
||||
// y=3 to y=10
|
||||
var afterLine = Assert.Single (after);
|
||||
Assert.Equal (3, afterLine.Start.Y);
|
||||
Assert.Equal (2, afterLine.Start.X);
|
||||
Assert.Equal (8, afterLine.Length);
|
||||
}
|
||||
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void TestExcludeParallel_VerticalLines_VerticalSplit ()
|
||||
{
|
||||
// y=1 to y=10
|
||||
var l1 = new StraightLine (new Point (2,1), 10, Orientation.Vertical, LineStyle.Single);
|
||||
var after = new StraightLine [] { l1 }
|
||||
// exclude y=4 to y=5
|
||||
.Exclude (new Point (2, 4), 2, Orientation.Vertical)
|
||||
.ToArray ();
|
||||
// y=1 to y=3,
|
||||
// y=6 to y=10
|
||||
Assert.Equal (2, after.Length);
|
||||
var afterLeft = after [0];
|
||||
var afterRight = after [1];
|
||||
|
||||
Assert.Equal (1, afterLeft.Start.Y);
|
||||
Assert.Equal (2, afterLeft.Start.X);
|
||||
Assert.Equal (3, afterLeft.Length);
|
||||
|
||||
Assert.Equal (6, afterRight.Start.Y);
|
||||
Assert.Equal (2, afterRight.Start.X);
|
||||
Assert.Equal (5, afterRight.Length);
|
||||
}
|
||||
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void TestExcludeParallel_VerticalLines_CoverCompletely ()
|
||||
{
|
||||
// y=1 to y=10
|
||||
var l1 = new StraightLine (new Point (2,1), 10, Orientation.Vertical, LineStyle.Single);
|
||||
var after = new StraightLine [] { l1 }
|
||||
// exclude y=4 to y=5
|
||||
.Exclude (new Point (2,1), 10, Orientation.Vertical)
|
||||
.ToArray ();
|
||||
Assert.Empty (after);
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Perpendicular Intersection Tests
|
||||
[Fact, AutoInitShutdown]
|
||||
public void TestExcludePerpendicular_HorizontalLine_VerticalExclusion_Splits ()
|
||||
{
|
||||
// x=1 to x=10
|
||||
var l1 = new StraightLine (new Point (1, 2), 10, Orientation.Horizontal, LineStyle.Single);
|
||||
var after = new StraightLine [] { l1 }
|
||||
// exclude x=3 y=0-10
|
||||
.Exclude (new Point (3, 0), 10, Orientation.Vertical)
|
||||
.ToArray ();
|
||||
// x=1 to x=2,
|
||||
// x=4 to x=10
|
||||
Assert.Equal (2, after.Length);
|
||||
var afterLeft = after [0];
|
||||
var afterRight = after [1];
|
||||
|
||||
Assert.Equal (1, afterLeft.Start.X);
|
||||
Assert.Equal (2, afterLeft.Start.Y);
|
||||
Assert.Equal (2, afterLeft.Length);
|
||||
|
||||
Assert.Equal (4, afterRight.Start.X);
|
||||
Assert.Equal (2, afterRight.Start.Y);
|
||||
Assert.Equal (7, afterRight.Length);
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void TestExcludePerpendicular_HorizontalLine_VerticalExclusion_ClipLeft ()
|
||||
{
|
||||
// x=1 to x=10
|
||||
var l1 = new StraightLine (new Point (1, 2), 10, Orientation.Horizontal, LineStyle.Single);
|
||||
var after = new StraightLine [] { l1 }
|
||||
// exclude x=1 y=0-10
|
||||
.Exclude (new Point (1, 0), 10, Orientation.Vertical)
|
||||
.ToArray ();
|
||||
// x=2 to x=10,
|
||||
var lineAfter = Assert.Single(after);
|
||||
|
||||
Assert.Equal (2, lineAfter.Start.X);
|
||||
Assert.Equal (2, lineAfter.Start.Y);
|
||||
Assert.Equal (9, lineAfter.Length);
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void TestExcludePerpendicular_HorizontalLine_VerticalExclusion_ClipRight ()
|
||||
{
|
||||
// x=1 to x=10
|
||||
var l1 = new StraightLine (new Point (1, 2), 10, Orientation.Horizontal, LineStyle.Single);
|
||||
var after = new StraightLine [] { l1 }
|
||||
// exclude x=10 y=0-10
|
||||
.Exclude (new Point (10, 0), 10, Orientation.Vertical)
|
||||
.ToArray ();
|
||||
// x=1 to x=9,
|
||||
var lineAfter = Assert.Single (after);
|
||||
|
||||
Assert.Equal (1, lineAfter.Start.X);
|
||||
Assert.Equal (2, lineAfter.Start.Y);
|
||||
Assert.Equal (9, lineAfter.Length);
|
||||
}
|
||||
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void TestExcludePerpendicular_HorizontalLine_VerticalExclusion_MissLeft ()
|
||||
{
|
||||
// x=1 to x=10
|
||||
var l1 = new StraightLine (new Point (1, 2), 10, Orientation.Horizontal, LineStyle.Single);
|
||||
var after = new StraightLine [] { l1 }
|
||||
// exclude x=0 y=0-10
|
||||
.Exclude (new Point (0, 0), 10, Orientation.Vertical)
|
||||
.ToArray ();
|
||||
// Exclusion line is too far to the left so hits nothing
|
||||
Assert.Same(Assert.Single (after),l1);
|
||||
}
|
||||
[Fact, AutoInitShutdown]
|
||||
public void TestExcludePerpendicular_HorizontalLine_VerticalExclusion_MissRight ()
|
||||
{
|
||||
// x=1 to x=10
|
||||
var l1 = new StraightLine (new Point (1, 2), 10, Orientation.Horizontal, LineStyle.Single);
|
||||
var after = new StraightLine [] { l1 }
|
||||
// exclude x=11 y=0-10
|
||||
.Exclude (new Point (11, 0), 10, Orientation.Vertical)
|
||||
.ToArray ();
|
||||
// Exclusion line is too far to the right so hits nothing
|
||||
Assert.Same (Assert.Single (after), l1);
|
||||
}
|
||||
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void TestExcludePerpendicular_VerticalLine_HorizontalExclusion_ClipTop ()
|
||||
{
|
||||
// y=1 to y=10
|
||||
var l1 = new StraightLine (new Point (2,1), 10, Orientation.Vertical, LineStyle.Single);
|
||||
var after = new StraightLine [] { l1 }
|
||||
// exclude y=1 x=0-10
|
||||
.Exclude (new Point (0,1), 10, Orientation.Horizontal)
|
||||
.ToArray ();
|
||||
// y=2 to y=10,
|
||||
var lineAfter = Assert.Single(after);
|
||||
|
||||
Assert.Equal (2, lineAfter.Start.Y);
|
||||
Assert.Equal (2, lineAfter.Start.X);
|
||||
Assert.Equal (9, lineAfter.Length);
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void TestExcludePerpendicular_VerticalLine_HorizontalExclusion_ClipBottom ()
|
||||
{
|
||||
// y=1 to y=10
|
||||
var l1 = new StraightLine (new Point (2,1), 10, Orientation.Vertical, LineStyle.Single);
|
||||
var after = new StraightLine [] { l1 }
|
||||
// exclude y=10 x=0-10
|
||||
.Exclude (new Point (0,10), 10, Orientation.Horizontal)
|
||||
.ToArray ();
|
||||
// y=1 to y=9,
|
||||
var lineAfter = Assert.Single (after);
|
||||
|
||||
Assert.Equal (1, lineAfter.Start.Y);
|
||||
Assert.Equal (2, lineAfter.Start.X);
|
||||
Assert.Equal (9, lineAfter.Length);
|
||||
}
|
||||
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void TestExcludePerpendicular_VerticalLine_HorizontalExclusion_MissTop ()
|
||||
{
|
||||
// y=1 to y=10
|
||||
var l1 = new StraightLine (new Point (2,1), 10, Orientation.Vertical, LineStyle.Single);
|
||||
var after = new StraightLine [] { l1 }
|
||||
// exclude y=0 x=0-10
|
||||
.Exclude (new Point (0, 0), 10, Orientation.Horizontal)
|
||||
.ToArray ();
|
||||
// Exclusion line is too far above so hits nothing
|
||||
Assert.Same(Assert.Single (after),l1);
|
||||
}
|
||||
[Fact, AutoInitShutdown]
|
||||
public void TestExcludePerpendicular_VerticalLine_HorizontalExclusion_MissBottom ()
|
||||
{
|
||||
// y=1 to y=10
|
||||
var l1 = new StraightLine (new Point (2,1), 10, Orientation.Vertical, LineStyle.Single);
|
||||
var after = new StraightLine [] { l1 }
|
||||
// exclude y=11 x=0-10
|
||||
.Exclude (new Point (0,11), 10, Orientation.Horizontal)
|
||||
.ToArray ();
|
||||
// Exclusion line is too far to the right so hits nothing
|
||||
Assert.Same (Assert.Single (after), l1);
|
||||
}
|
||||
|
||||
#endregion Perpendicular Intersection Tests
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void LineCanvasIntegrationTest()
|
||||
{
|
||||
var lc = new LineCanvas();
|
||||
lc.AddLine(new Point(0,0),10,Orientation.Horizontal,LineStyle.Single);
|
||||
lc.AddLine(new Point(9,0),5,Orientation.Vertical,LineStyle.Single);
|
||||
lc.AddLine(new Point(9,4),-10,Orientation.Horizontal,LineStyle.Single);
|
||||
lc.AddLine(new Point(0,4),-5,Orientation.Vertical,LineStyle.Single);
|
||||
|
||||
|
||||
TestHelpers.AssertEqual (this._output,
|
||||
@"
|
||||
TestHelpers.AssertEqual (
|
||||
_output,
|
||||
@"
|
||||
┌────────┐
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
└────────┘",$"{Environment.NewLine}{lc}");
|
||||
var origLines = lc.Lines;
|
||||
└────────┘",
|
||||
$"{Environment.NewLine}{lc}"
|
||||
);
|
||||
IReadOnlyCollection<StraightLine> origLines = lc.Lines;
|
||||
|
||||
lc = new LineCanvas(origLines.Exclude(new Point(0,0),10,Orientation.Horizontal));
|
||||
lc = new LineCanvas (origLines.Exclude (new Point (0, 0), 10, Orientation.Horizontal));
|
||||
|
||||
TestHelpers.AssertEqual (this._output,
|
||||
@"
|
||||
TestHelpers.AssertEqual (
|
||||
_output,
|
||||
@"
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
└────────┘",$"{Environment.NewLine}{lc}");
|
||||
└────────┘",
|
||||
$"{Environment.NewLine}{lc}"
|
||||
);
|
||||
|
||||
lc = new LineCanvas(origLines.Exclude(new Point(0,1),10,Orientation.Horizontal));
|
||||
TestHelpers.AssertEqual (this._output,
|
||||
@"
|
||||
lc = new LineCanvas (origLines.Exclude (new Point (0, 1), 10, Orientation.Horizontal));
|
||||
|
||||
TestHelpers.AssertEqual (
|
||||
_output,
|
||||
@"
|
||||
┌────────┐
|
||||
|
||||
│ │
|
||||
│ │
|
||||
└────────┘",$"{Environment.NewLine}{lc}");
|
||||
└────────┘",
|
||||
$"{Environment.NewLine}{lc}"
|
||||
);
|
||||
|
||||
lc = new LineCanvas(origLines.Exclude(new Point(0,2),10,Orientation.Horizontal));
|
||||
TestHelpers.AssertEqual (this._output,
|
||||
@"
|
||||
lc = new LineCanvas (origLines.Exclude (new Point (0, 2), 10, Orientation.Horizontal));
|
||||
|
||||
TestHelpers.AssertEqual (
|
||||
_output,
|
||||
@"
|
||||
┌────────┐
|
||||
│ │
|
||||
|
||||
│ │
|
||||
└────────┘",$"{Environment.NewLine}{lc}");
|
||||
└────────┘",
|
||||
$"{Environment.NewLine}{lc}"
|
||||
);
|
||||
|
||||
lc = new LineCanvas(origLines.Exclude(new Point(0,3),10,Orientation.Horizontal));
|
||||
TestHelpers.AssertEqual (this._output,
|
||||
@"
|
||||
lc = new LineCanvas (origLines.Exclude (new Point (0, 3), 10, Orientation.Horizontal));
|
||||
|
||||
TestHelpers.AssertEqual (
|
||||
_output,
|
||||
@"
|
||||
┌────────┐
|
||||
│ │
|
||||
│ │
|
||||
|
||||
└────────┘",$"{Environment.NewLine}{lc}");
|
||||
└────────┘",
|
||||
$"{Environment.NewLine}{lc}"
|
||||
);
|
||||
|
||||
lc = new LineCanvas(origLines.Exclude(new Point(0,4),10,Orientation.Horizontal));
|
||||
TestHelpers.AssertEqual (this._output,
|
||||
@"
|
||||
lc = new LineCanvas (origLines.Exclude (new Point (0, 4), 10, Orientation.Horizontal));
|
||||
|
||||
TestHelpers.AssertEqual (
|
||||
_output,
|
||||
@"
|
||||
┌────────┐
|
||||
│ │
|
||||
│ │
|
||||
│ │",$"{Environment.NewLine}{lc}");
|
||||
│ │",
|
||||
$"{Environment.NewLine}{lc}"
|
||||
);
|
||||
|
||||
lc = new LineCanvas (origLines.Exclude (new Point (0, 0), 10, Orientation.Vertical));
|
||||
|
||||
lc = new LineCanvas(origLines.Exclude(new Point(0,0),10,Orientation.Vertical));
|
||||
|
||||
TestHelpers.AssertEqual (this._output,
|
||||
@"
|
||||
TestHelpers.AssertEqual (
|
||||
_output,
|
||||
@"
|
||||
────────┐
|
||||
│
|
||||
│
|
||||
│
|
||||
────────┘",$"{Environment.NewLine}{lc}");
|
||||
────────┘",
|
||||
$"{Environment.NewLine}{lc}"
|
||||
);
|
||||
|
||||
lc = new LineCanvas(origLines.Exclude(new Point(1,0),10,Orientation.Vertical));
|
||||
lc = new LineCanvas (origLines.Exclude (new Point (1, 0), 10, Orientation.Vertical));
|
||||
|
||||
TestHelpers.AssertEqual (this._output,
|
||||
@"
|
||||
TestHelpers.AssertEqual (
|
||||
_output,
|
||||
@"
|
||||
┌ ───────┐
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
└ ───────┘",$"{Environment.NewLine}{lc}");
|
||||
└ ───────┘",
|
||||
$"{Environment.NewLine}{lc}"
|
||||
);
|
||||
|
||||
lc = new LineCanvas(origLines.Exclude(new Point(8,0),10,Orientation.Vertical));
|
||||
lc = new LineCanvas (origLines.Exclude (new Point (8, 0), 10, Orientation.Vertical));
|
||||
|
||||
TestHelpers.AssertEqual (this._output,
|
||||
@"
|
||||
TestHelpers.AssertEqual (
|
||||
_output,
|
||||
@"
|
||||
┌─────── ┐
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
└─────── ┘",$"{Environment.NewLine}{lc}");
|
||||
└─────── ┘",
|
||||
$"{Environment.NewLine}{lc}"
|
||||
);
|
||||
|
||||
lc = new LineCanvas(origLines.Exclude(new Point(9,0),10,Orientation.Vertical));
|
||||
lc = new LineCanvas (origLines.Exclude (new Point (9, 0), 10, Orientation.Vertical));
|
||||
|
||||
TestHelpers.AssertEqual (this._output,
|
||||
@"
|
||||
TestHelpers.AssertEqual (
|
||||
_output,
|
||||
@"
|
||||
┌────────
|
||||
│
|
||||
│
|
||||
│
|
||||
└────────",$"{Environment.NewLine}{lc}");
|
||||
└────────",
|
||||
$"{Environment.NewLine}{lc}"
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
#region Parallel Tests
|
||||
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
public void TestExcludeParallel_HorizontalLines_LeftOnly ()
|
||||
{
|
||||
// x=1 to x=10
|
||||
var l1 = new StraightLine (new Point (1, 2), 10, Orientation.Horizontal, LineStyle.Single);
|
||||
|
||||
StraightLine [] after = new [] { l1 }
|
||||
|
||||
// exclude x=3 to x=103
|
||||
.Exclude (new Point (3, 2), 100, Orientation.Horizontal)
|
||||
.ToArray ();
|
||||
|
||||
// x=1 to x=2
|
||||
StraightLine afterLine = Assert.Single (after);
|
||||
Assert.Equal (l1.Start, afterLine.Start);
|
||||
Assert.Equal (2, afterLine.Length);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
public void TestExcludeParallel_HorizontalLines_RightOnly ()
|
||||
{
|
||||
// x=1 to x=10
|
||||
var l1 = new StraightLine (new Point (1, 2), 10, Orientation.Horizontal, LineStyle.Single);
|
||||
|
||||
StraightLine [] after = new [] { l1 }
|
||||
|
||||
// exclude x=0 to x=2
|
||||
.Exclude (new Point (0, 2), 3, Orientation.Horizontal)
|
||||
.ToArray ();
|
||||
|
||||
// x=3 to x=10
|
||||
StraightLine afterLine = Assert.Single (after);
|
||||
Assert.Equal (3, afterLine.Start.X);
|
||||
Assert.Equal (2, afterLine.Start.Y);
|
||||
Assert.Equal (8, afterLine.Length);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
public void TestExcludeParallel_HorizontalLines_HorizontalSplit ()
|
||||
{
|
||||
// x=1 to x=10
|
||||
var l1 = new StraightLine (new Point (1, 2), 10, Orientation.Horizontal, LineStyle.Single);
|
||||
|
||||
StraightLine [] after = new [] { l1 }
|
||||
|
||||
// exclude x=4 to x=5
|
||||
.Exclude (new Point (4, 2), 2, Orientation.Horizontal)
|
||||
.ToArray ();
|
||||
|
||||
// x=1 to x=3,
|
||||
// x=6 to x=10
|
||||
Assert.Equal (2, after.Length);
|
||||
StraightLine afterLeft = after [0];
|
||||
StraightLine afterRight = after [1];
|
||||
|
||||
Assert.Equal (1, afterLeft.Start.X);
|
||||
Assert.Equal (2, afterLeft.Start.Y);
|
||||
Assert.Equal (3, afterLeft.Length);
|
||||
|
||||
Assert.Equal (6, afterRight.Start.X);
|
||||
Assert.Equal (2, afterRight.Start.Y);
|
||||
Assert.Equal (5, afterRight.Length);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
public void TestExcludeParallel_HorizontalLines_CoverCompletely ()
|
||||
{
|
||||
// x=1 to x=10
|
||||
var l1 = new StraightLine (new Point (1, 2), 10, Orientation.Horizontal, LineStyle.Single);
|
||||
|
||||
StraightLine [] after = new [] { l1 }
|
||||
|
||||
// exclude x=4 to x=5
|
||||
.Exclude (new Point (1, 2), 10, Orientation.Horizontal)
|
||||
.ToArray ();
|
||||
Assert.Empty (after);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
public void TestExcludeParallel_VerticalLines_TopOnly ()
|
||||
{
|
||||
// y=1 to y=10
|
||||
var l1 = new StraightLine (new Point (2, 1), 10, Orientation.Vertical, LineStyle.Single);
|
||||
|
||||
StraightLine [] after = new [] { l1 }
|
||||
|
||||
// exclude y=3 to y=103
|
||||
.Exclude (new Point (2, 3), 100, Orientation.Vertical)
|
||||
.ToArray ();
|
||||
|
||||
// y=1 to y=2
|
||||
StraightLine afterLine = Assert.Single (after);
|
||||
Assert.Equal (l1.Start, afterLine.Start);
|
||||
Assert.Equal (2, afterLine.Length);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
public void TestExcludeParallel_HorizontalLines_BottomOnly ()
|
||||
{
|
||||
// y=1 to y=10
|
||||
var l1 = new StraightLine (new Point (2, 1), 10, Orientation.Vertical, LineStyle.Single);
|
||||
|
||||
StraightLine [] after = new [] { l1 }
|
||||
|
||||
// exclude y=0 to y=2
|
||||
.Exclude (new Point (2, 0), 3, Orientation.Vertical)
|
||||
.ToArray ();
|
||||
|
||||
// y=3 to y=10
|
||||
StraightLine afterLine = Assert.Single (after);
|
||||
Assert.Equal (3, afterLine.Start.Y);
|
||||
Assert.Equal (2, afterLine.Start.X);
|
||||
Assert.Equal (8, afterLine.Length);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
public void TestExcludeParallel_VerticalLines_VerticalSplit ()
|
||||
{
|
||||
// y=1 to y=10
|
||||
var l1 = new StraightLine (new Point (2, 1), 10, Orientation.Vertical, LineStyle.Single);
|
||||
|
||||
StraightLine [] after = new [] { l1 }
|
||||
|
||||
// exclude y=4 to y=5
|
||||
.Exclude (new Point (2, 4), 2, Orientation.Vertical)
|
||||
.ToArray ();
|
||||
|
||||
// y=1 to y=3,
|
||||
// y=6 to y=10
|
||||
Assert.Equal (2, after.Length);
|
||||
StraightLine afterLeft = after [0];
|
||||
StraightLine afterRight = after [1];
|
||||
|
||||
Assert.Equal (1, afterLeft.Start.Y);
|
||||
Assert.Equal (2, afterLeft.Start.X);
|
||||
Assert.Equal (3, afterLeft.Length);
|
||||
|
||||
Assert.Equal (6, afterRight.Start.Y);
|
||||
Assert.Equal (2, afterRight.Start.X);
|
||||
Assert.Equal (5, afterRight.Length);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
public void TestExcludeParallel_VerticalLines_CoverCompletely ()
|
||||
{
|
||||
// y=1 to y=10
|
||||
var l1 = new StraightLine (new Point (2, 1), 10, Orientation.Vertical, LineStyle.Single);
|
||||
|
||||
StraightLine [] after = new [] { l1 }
|
||||
|
||||
// exclude y=4 to y=5
|
||||
.Exclude (new Point (2, 1), 10, Orientation.Vertical)
|
||||
.ToArray ();
|
||||
Assert.Empty (after);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Perpendicular Intersection Tests
|
||||
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
public void TestExcludePerpendicular_HorizontalLine_VerticalExclusion_Splits ()
|
||||
{
|
||||
// x=1 to x=10
|
||||
var l1 = new StraightLine (new Point (1, 2), 10, Orientation.Horizontal, LineStyle.Single);
|
||||
|
||||
StraightLine [] after = new [] { l1 }
|
||||
|
||||
// exclude x=3 y=0-10
|
||||
.Exclude (new Point (3, 0), 10, Orientation.Vertical)
|
||||
.ToArray ();
|
||||
|
||||
// x=1 to x=2,
|
||||
// x=4 to x=10
|
||||
Assert.Equal (2, after.Length);
|
||||
StraightLine afterLeft = after [0];
|
||||
StraightLine afterRight = after [1];
|
||||
|
||||
Assert.Equal (1, afterLeft.Start.X);
|
||||
Assert.Equal (2, afterLeft.Start.Y);
|
||||
Assert.Equal (2, afterLeft.Length);
|
||||
|
||||
Assert.Equal (4, afterRight.Start.X);
|
||||
Assert.Equal (2, afterRight.Start.Y);
|
||||
Assert.Equal (7, afterRight.Length);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
public void TestExcludePerpendicular_HorizontalLine_VerticalExclusion_ClipLeft ()
|
||||
{
|
||||
// x=1 to x=10
|
||||
var l1 = new StraightLine (new Point (1, 2), 10, Orientation.Horizontal, LineStyle.Single);
|
||||
|
||||
StraightLine [] after = new [] { l1 }
|
||||
|
||||
// exclude x=1 y=0-10
|
||||
.Exclude (new Point (1, 0), 10, Orientation.Vertical)
|
||||
.ToArray ();
|
||||
|
||||
// x=2 to x=10,
|
||||
StraightLine lineAfter = Assert.Single (after);
|
||||
|
||||
Assert.Equal (2, lineAfter.Start.X);
|
||||
Assert.Equal (2, lineAfter.Start.Y);
|
||||
Assert.Equal (9, lineAfter.Length);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
public void TestExcludePerpendicular_HorizontalLine_VerticalExclusion_ClipRight ()
|
||||
{
|
||||
// x=1 to x=10
|
||||
var l1 = new StraightLine (new Point (1, 2), 10, Orientation.Horizontal, LineStyle.Single);
|
||||
|
||||
StraightLine [] after = new [] { l1 }
|
||||
|
||||
// exclude x=10 y=0-10
|
||||
.Exclude (new Point (10, 0), 10, Orientation.Vertical)
|
||||
.ToArray ();
|
||||
|
||||
// x=1 to x=9,
|
||||
StraightLine lineAfter = Assert.Single (after);
|
||||
|
||||
Assert.Equal (1, lineAfter.Start.X);
|
||||
Assert.Equal (2, lineAfter.Start.Y);
|
||||
Assert.Equal (9, lineAfter.Length);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
public void TestExcludePerpendicular_HorizontalLine_VerticalExclusion_MissLeft ()
|
||||
{
|
||||
// x=1 to x=10
|
||||
var l1 = new StraightLine (new Point (1, 2), 10, Orientation.Horizontal, LineStyle.Single);
|
||||
|
||||
StraightLine [] after = new [] { l1 }
|
||||
|
||||
// exclude x=0 y=0-10
|
||||
.Exclude (new Point (0, 0), 10, Orientation.Vertical)
|
||||
.ToArray ();
|
||||
|
||||
// Exclusion line is too far to the left so hits nothing
|
||||
Assert.Same (Assert.Single (after), l1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
public void TestExcludePerpendicular_HorizontalLine_VerticalExclusion_MissRight ()
|
||||
{
|
||||
// x=1 to x=10
|
||||
var l1 = new StraightLine (new Point (1, 2), 10, Orientation.Horizontal, LineStyle.Single);
|
||||
|
||||
StraightLine [] after = new [] { l1 }
|
||||
|
||||
// exclude x=11 y=0-10
|
||||
.Exclude (new Point (11, 0), 10, Orientation.Vertical)
|
||||
.ToArray ();
|
||||
|
||||
// Exclusion line is too far to the right so hits nothing
|
||||
Assert.Same (Assert.Single (after), l1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
public void TestExcludePerpendicular_VerticalLine_HorizontalExclusion_ClipTop ()
|
||||
{
|
||||
// y=1 to y=10
|
||||
var l1 = new StraightLine (new Point (2, 1), 10, Orientation.Vertical, LineStyle.Single);
|
||||
|
||||
StraightLine [] after = new [] { l1 }
|
||||
|
||||
// exclude y=1 x=0-10
|
||||
.Exclude (new Point (0, 1), 10, Orientation.Horizontal)
|
||||
.ToArray ();
|
||||
|
||||
// y=2 to y=10,
|
||||
StraightLine lineAfter = Assert.Single (after);
|
||||
|
||||
Assert.Equal (2, lineAfter.Start.Y);
|
||||
Assert.Equal (2, lineAfter.Start.X);
|
||||
Assert.Equal (9, lineAfter.Length);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
public void TestExcludePerpendicular_VerticalLine_HorizontalExclusion_ClipBottom ()
|
||||
{
|
||||
// y=1 to y=10
|
||||
var l1 = new StraightLine (new Point (2, 1), 10, Orientation.Vertical, LineStyle.Single);
|
||||
|
||||
StraightLine [] after = new [] { l1 }
|
||||
|
||||
// exclude y=10 x=0-10
|
||||
.Exclude (new Point (0, 10), 10, Orientation.Horizontal)
|
||||
.ToArray ();
|
||||
|
||||
// y=1 to y=9,
|
||||
StraightLine lineAfter = Assert.Single (after);
|
||||
|
||||
Assert.Equal (1, lineAfter.Start.Y);
|
||||
Assert.Equal (2, lineAfter.Start.X);
|
||||
Assert.Equal (9, lineAfter.Length);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
public void TestExcludePerpendicular_VerticalLine_HorizontalExclusion_MissTop ()
|
||||
{
|
||||
// y=1 to y=10
|
||||
var l1 = new StraightLine (new Point (2, 1), 10, Orientation.Vertical, LineStyle.Single);
|
||||
|
||||
StraightLine [] after = new [] { l1 }
|
||||
|
||||
// exclude y=0 x=0-10
|
||||
.Exclude (new Point (0, 0), 10, Orientation.Horizontal)
|
||||
.ToArray ();
|
||||
|
||||
// Exclusion line is too far above so hits nothing
|
||||
Assert.Same (Assert.Single (after), l1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
public void TestExcludePerpendicular_VerticalLine_HorizontalExclusion_MissBottom ()
|
||||
{
|
||||
// y=1 to y=10
|
||||
var l1 = new StraightLine (new Point (2, 1), 10, Orientation.Vertical, LineStyle.Single);
|
||||
|
||||
StraightLine [] after = new [] { l1 }
|
||||
|
||||
// exclude y=11 x=0-10
|
||||
.Exclude (new Point (0, 11), 10, Orientation.Horizontal)
|
||||
.ToArray ();
|
||||
|
||||
// Exclusion line is too far to the right so hits nothing
|
||||
Assert.Same (Assert.Single (after), l1);
|
||||
}
|
||||
|
||||
#endregion Perpendicular Intersection Tests
|
||||
}
|
||||
|
||||
@@ -1,90 +1,327 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Terminal.Gui.DrawingTests {
|
||||
public class StraightLineTests {
|
||||
namespace Terminal.Gui.DrawingTests;
|
||||
|
||||
readonly ITestOutputHelper output;
|
||||
public class StraightLineTests
|
||||
{
|
||||
private readonly ITestOutputHelper output;
|
||||
public StraightLineTests (ITestOutputHelper output) { this.output = output; }
|
||||
|
||||
public StraightLineTests (ITestOutputHelper output)
|
||||
{
|
||||
this.output = output;
|
||||
}
|
||||
[InlineData (
|
||||
Orientation.Horizontal,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1
|
||||
)]
|
||||
[InlineData (
|
||||
Orientation.Horizontal,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1
|
||||
)]
|
||||
[InlineData (
|
||||
Orientation.Horizontal,
|
||||
0,
|
||||
0,
|
||||
2,
|
||||
0,
|
||||
0,
|
||||
2,
|
||||
1
|
||||
)]
|
||||
[InlineData (
|
||||
Orientation.Horizontal,
|
||||
0,
|
||||
0,
|
||||
3,
|
||||
0,
|
||||
0,
|
||||
3,
|
||||
1
|
||||
)]
|
||||
[InlineData (
|
||||
Orientation.Horizontal,
|
||||
0,
|
||||
0,
|
||||
-1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1
|
||||
)]
|
||||
[InlineData (
|
||||
Orientation.Horizontal,
|
||||
0,
|
||||
0,
|
||||
-2,
|
||||
-1,
|
||||
0,
|
||||
2,
|
||||
1
|
||||
)]
|
||||
[InlineData (
|
||||
Orientation.Horizontal,
|
||||
0,
|
||||
0,
|
||||
-3,
|
||||
-2,
|
||||
0,
|
||||
3,
|
||||
1
|
||||
)]
|
||||
[InlineData (
|
||||
Orientation.Horizontal,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
1
|
||||
)]
|
||||
[InlineData (
|
||||
Orientation.Horizontal,
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
1
|
||||
)]
|
||||
[InlineData (
|
||||
Orientation.Horizontal,
|
||||
1,
|
||||
0,
|
||||
2,
|
||||
1,
|
||||
0,
|
||||
2,
|
||||
1
|
||||
)]
|
||||
[InlineData (
|
||||
Orientation.Horizontal,
|
||||
1,
|
||||
0,
|
||||
3,
|
||||
1,
|
||||
0,
|
||||
3,
|
||||
1
|
||||
)]
|
||||
[InlineData (
|
||||
Orientation.Horizontal,
|
||||
1,
|
||||
0,
|
||||
-1,
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
1
|
||||
)]
|
||||
[InlineData (
|
||||
Orientation.Horizontal,
|
||||
1,
|
||||
0,
|
||||
-2,
|
||||
0,
|
||||
0,
|
||||
2,
|
||||
1
|
||||
)]
|
||||
[InlineData (
|
||||
Orientation.Horizontal,
|
||||
1,
|
||||
0,
|
||||
-3,
|
||||
-1,
|
||||
0,
|
||||
3,
|
||||
1
|
||||
)]
|
||||
[InlineData (
|
||||
Orientation.Horizontal,
|
||||
-1,
|
||||
0,
|
||||
0,
|
||||
-1,
|
||||
0,
|
||||
1,
|
||||
1
|
||||
)]
|
||||
[InlineData (
|
||||
Orientation.Horizontal,
|
||||
0,
|
||||
-1,
|
||||
1,
|
||||
0,
|
||||
-1,
|
||||
1,
|
||||
1
|
||||
)]
|
||||
[InlineData (
|
||||
Orientation.Horizontal,
|
||||
-1,
|
||||
-1,
|
||||
1,
|
||||
-1,
|
||||
-1,
|
||||
1,
|
||||
1
|
||||
)]
|
||||
[InlineData (
|
||||
Orientation.Horizontal,
|
||||
-1,
|
||||
-1,
|
||||
2,
|
||||
-1,
|
||||
-1,
|
||||
2,
|
||||
1
|
||||
)]
|
||||
[InlineData (
|
||||
Orientation.Horizontal,
|
||||
-10,
|
||||
-10,
|
||||
10,
|
||||
-10,
|
||||
-10,
|
||||
10,
|
||||
1
|
||||
)]
|
||||
[InlineData (
|
||||
Orientation.Horizontal,
|
||||
0,
|
||||
-1,
|
||||
-1,
|
||||
0,
|
||||
-1,
|
||||
1,
|
||||
1
|
||||
)]
|
||||
[InlineData (
|
||||
Orientation.Horizontal,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
1,
|
||||
1
|
||||
)]
|
||||
[InlineData (
|
||||
Orientation.Horizontal,
|
||||
-1,
|
||||
-1,
|
||||
-2,
|
||||
-2,
|
||||
-1,
|
||||
2,
|
||||
1
|
||||
)]
|
||||
[InlineData (
|
||||
Orientation.Horizontal,
|
||||
-10,
|
||||
-10,
|
||||
-10,
|
||||
-19,
|
||||
-10,
|
||||
10,
|
||||
1
|
||||
)]
|
||||
[InlineData (
|
||||
Orientation.Vertical,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1
|
||||
)]
|
||||
[InlineData (
|
||||
Orientation.Vertical,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1
|
||||
)]
|
||||
[InlineData (
|
||||
Orientation.Vertical,
|
||||
0,
|
||||
0,
|
||||
2,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
2
|
||||
)]
|
||||
[InlineData (
|
||||
Orientation.Vertical,
|
||||
0,
|
||||
0,
|
||||
3,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
3
|
||||
)]
|
||||
[InlineData (
|
||||
Orientation.Vertical,
|
||||
0,
|
||||
0,
|
||||
-1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1
|
||||
)]
|
||||
[InlineData (
|
||||
Orientation.Vertical,
|
||||
0,
|
||||
0,
|
||||
-2,
|
||||
0,
|
||||
-1,
|
||||
1,
|
||||
2
|
||||
)]
|
||||
[InlineData (
|
||||
Orientation.Vertical,
|
||||
0,
|
||||
0,
|
||||
-3,
|
||||
0,
|
||||
-2,
|
||||
1,
|
||||
3
|
||||
)]
|
||||
[Theory]
|
||||
[SetupFakeDriver]
|
||||
public void Bounds (
|
||||
Orientation orientation,
|
||||
int x,
|
||||
int y,
|
||||
int length,
|
||||
int expectedX,
|
||||
int expectedY,
|
||||
int expectedWidth,
|
||||
int expectedHeight
|
||||
)
|
||||
{
|
||||
var sl = new StraightLine (new Point (x, y), length, orientation, LineStyle.Single);
|
||||
|
||||
[InlineData (Orientation.Horizontal, 0, 0, 0,
|
||||
0, 0, 1, 1)]
|
||||
[InlineData (Orientation.Horizontal, 0, 0, 1,
|
||||
0, 0, 1, 1)]
|
||||
[InlineData (Orientation.Horizontal, 0, 0, 2,
|
||||
0, 0, 2, 1)]
|
||||
[InlineData (Orientation.Horizontal, 0, 0, 3,
|
||||
0, 0, 3, 1)]
|
||||
[InlineData (Orientation.Horizontal, 0, 0, -1,
|
||||
0, 0, 1, 1)]
|
||||
[InlineData (Orientation.Horizontal, 0, 0, -2,
|
||||
-1, 0, 2, 1)]
|
||||
[InlineData (Orientation.Horizontal, 0, 0, -3,
|
||||
-2, 0, 3, 1)]
|
||||
|
||||
[InlineData (Orientation.Horizontal, 1, 0, 0,
|
||||
1, 0, 1, 1)]
|
||||
[InlineData (Orientation.Horizontal, 1, 0, 1,
|
||||
1, 0, 1, 1)]
|
||||
[InlineData (Orientation.Horizontal, 1, 0, 2,
|
||||
1, 0, 2, 1)]
|
||||
[InlineData (Orientation.Horizontal, 1, 0, 3,
|
||||
1, 0, 3, 1)]
|
||||
[InlineData (Orientation.Horizontal, 1, 0, -1,
|
||||
1, 0, 1, 1)]
|
||||
[InlineData (Orientation.Horizontal, 1, 0, -2,
|
||||
0, 0, 2, 1)]
|
||||
[InlineData (Orientation.Horizontal, 1, 0, -3,
|
||||
-1, 0, 3, 1)]
|
||||
|
||||
[InlineData (Orientation.Horizontal, -1, 0, 0,
|
||||
-1, 0, 1, 1)]
|
||||
[InlineData (Orientation.Horizontal, 0, -1, 1,
|
||||
0, -1, 1, 1)]
|
||||
[InlineData (Orientation.Horizontal, -1, -1, 1,
|
||||
-1, -1, 1, 1)]
|
||||
[InlineData (Orientation.Horizontal, -1, -1, 2,
|
||||
-1, -1, 2, 1)]
|
||||
[InlineData (Orientation.Horizontal, -10, -10, 10,
|
||||
-10, -10, 10, 1)]
|
||||
|
||||
[InlineData (Orientation.Horizontal, 0, -1, -1,
|
||||
0, -1, 1, 1)]
|
||||
[InlineData (Orientation.Horizontal, -1, -1, -1,
|
||||
-1, -1, 1, 1)]
|
||||
[InlineData (Orientation.Horizontal, -1, -1, -2,
|
||||
-2, -1, 2, 1)]
|
||||
[InlineData (Orientation.Horizontal, -10, -10, -10,
|
||||
-19, -10, 10, 1)]
|
||||
|
||||
[InlineData (Orientation.Vertical, 0, 0, 0,
|
||||
0, 0, 1, 1)]
|
||||
[InlineData (Orientation.Vertical, 0, 0, 1,
|
||||
0, 0, 1, 1)]
|
||||
[InlineData (Orientation.Vertical, 0, 0, 2,
|
||||
0, 0, 1, 2)]
|
||||
[InlineData (Orientation.Vertical, 0, 0, 3,
|
||||
0, 0, 1, 3)]
|
||||
[InlineData (Orientation.Vertical, 0, 0, -1,
|
||||
0, 0, 1, 1)]
|
||||
[InlineData (Orientation.Vertical, 0, 0, -2,
|
||||
0, -1, 1, 2)]
|
||||
[InlineData (Orientation.Vertical, 0, 0, -3,
|
||||
0, -2, 1, 3)]
|
||||
[Theory, SetupFakeDriver]
|
||||
public void Bounds (Orientation orientation, int x, int y, int length, int expectedX, int expectedY, int expectedWidth, int expectedHeight)
|
||||
{
|
||||
var sl = new StraightLine (new Point (x, y), length, orientation, LineStyle.Single);
|
||||
|
||||
Assert.Equal (new Rect (expectedX, expectedY, expectedWidth, expectedHeight), sl.Bounds);
|
||||
}
|
||||
|
||||
}
|
||||
Assert.Equal (new Rect (expectedX, expectedY, expectedWidth, expectedHeight), sl.Bounds);
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user