Skip to content

Adding primitive types to improve drawing #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions Tests/ColorTests/Properties/AssemblyInfo.cs

This file was deleted.

31 changes: 31 additions & 0 deletions nanoFramework.Graphics.Core.UnitTests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyCopyright("Copyright (c) 2021 nanoFramework contributors")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
// Portions Copyright (c) Microsoft Corporation. All rights reserved.
// See LICENSE file in the project root for full license information.

using nanoFramework.TestFramework;
using System.Drawing;
using nanoFramework.TestFramework;

namespace nanoFramework.UI
namespace nanoFramework.Graphics.Core.UnitTests.System.Drawing
{
[TestClass]
public class ColorTests
public class Color_UnitTests
{
[TestMethod]
public void ColorTestBasicSerialization()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
using System.Drawing;
using nanoFramework.TestFramework;

namespace nanoFramework.Graphics.Core.UnitTests.System.Drawing
{
[TestClass]
public class Point_UnitTests
{
[TestMethod]
public void Add_should_move_Point()
{
var size = new Size(456, 123);
var sut = new Point(123, 456);

var actual = sut + size;

Assert.AreEqual(579, actual.X);
Assert.AreEqual(579, actual.Y);
}

[TestMethod]
public void Equals_should_return_false()
{
var pointA = new Point(123, 456);
var pointB = new Point(789, 012);

Assert.IsFalse(pointA.Equals(pointB));
Assert.IsFalse(pointA.Equals((object)pointB));
Assert.IsFalse(pointA == pointB);
Assert.IsTrue(pointA != pointB);
}

[TestMethod]
public void Equals_should_return_true()
{
var pointA = new Point(123, 456);
var pointB = new Point(123, 456);

Assert.IsTrue(pointA.Equals(pointB));
Assert.IsTrue(pointA.Equals((object) pointB));
Assert.IsTrue(pointA == pointB);
Assert.IsFalse(pointA != pointB);
}

[TestMethod]
public void Empty_should_have_correct_properties()
{
var sut = Point.Empty;

Assert.AreEqual(0, sut.X);
Assert.AreEqual(0, sut.Y);
}

[TestMethod]
public void IsEmpty_should_return_false()
{
var sut = new Point(1, 1);

Assert.IsFalse(sut.IsEmpty);
}

[TestMethod]
public void IsEmpty_should_return_true()
{
var sut = new Point(0, 0);

Assert.IsTrue(sut.IsEmpty);
}

[TestMethod]
public void Offset_should_move_Point()
{
var sut = new Point(123, 456);
sut.Offset(new Point(456, 123));

Assert.AreEqual(579, sut.X);
Assert.AreEqual(579, sut.Y);
}

[TestMethod]
public void Should_cast_to_Size()
{
var sut = new Point(123, 456);
var actual = (Size) sut;

Assert.AreEqual(sut.X, actual.Width);
Assert.AreEqual(sut.Y, actual.Height);
}

[TestMethod]
public void Subtract_should_move_Point()
{
var size = new Size(456, 123);
var sut = new Point(123, 456);

var actual = sut - size;

Assert.AreEqual(-333, actual.X);
Assert.AreEqual(333, actual.Y);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
using System;
using System.Drawing;
using nanoFramework.TestFramework;

namespace nanoFramework.Graphics.Core.UnitTests.System.Drawing
{
[TestClass]
public class Rectangle_UnitTests
{
[TestMethod]
public void Contains_Point_should_return_false()
{
var point = new Point(123, 123);
var sut = new Rectangle(Point.Empty, new Size(100, 100));

Assert.IsFalse(sut.Contains(point));
}

[TestMethod]
public void Contains_Point_should_return_true()
{
var point = new Point(50, 50);
var sut = new Rectangle(Point.Empty, new Size(100, 100));

Assert.IsTrue(sut.Contains(point));
}

[TestMethod]
public void Contains_Rectangle_should_return_false()
{
var rectangle = new Rectangle(Point.Empty, new Size(200, 200));
var sut = new Rectangle(Point.Empty, new Size(100, 100));

Assert.IsFalse(sut.Contains(rectangle));
}

[TestMethod]
public void Contains_Rectangle_should_return_true()
{
var rectangle = new Rectangle(Point.Empty, new Size(50, 50));
var sut = new Rectangle(Point.Empty, new Size(100, 100));

Assert.IsTrue(sut.Contains(rectangle));
}

[TestMethod]
public void Empty_should_have_correct_properties()
{
var sut = Rectangle.Empty;

Assert.AreEqual(0, sut.X);
Assert.AreEqual(0, sut.Y);
Assert.AreEqual(0, sut.Width);
Assert.AreEqual(0, sut.Height);
}

[TestMethod]
public void FromLRTB_should_return_correct_Rectangle()
{
var expect = new Rectangle(10, 20, 30, 30);
var actual = Rectangle.FromLTRB(10, 20, 40, 50);

Assert.AreEqual(expect, actual);
}

[TestMethod]
public void Inflate_should_inflate_the_Rectangle()
{
var sut = new Rectangle(10, 10, 10, 10);
sut.Inflate(10, 10);

Assert.AreEqual(0, sut.X);
Assert.AreEqual(0, sut.Y);
Assert.AreEqual(30, sut.Width);
Assert.AreEqual(30, sut.Height);
}

[TestMethod]
public void Intersect_should_create_correct_Rectangle()
{
var rectangleA = new Rectangle(Point.Empty, new Size(100, 100));
var rectangleB = new Rectangle(new Point(50, 50), new Size(100, 100));

var expect = new Rectangle(new Point(50, 50), new Size(50, 50));

rectangleA.Intersect(rectangleB);

Assert.AreEqual(expect, rectangleA);
}

[TestMethod]
public void IntersectsWith_should_return_false()
{
var rectangleA = new Rectangle(Point.Empty, new Size(100, 100));
var rectangleB = new Rectangle(new Point(100, 100), new Size(100, 100));

var actual = rectangleA.IntersectsWith(rectangleB);

Assert.IsFalse(actual);
}

[TestMethod]
public void IntersectsWith_should_return_true()
{
var rectangleA = new Rectangle(Point.Empty, new Size(100, 100));
var rectangleB = new Rectangle(new Point(50, 50), new Size(100, 100));

var actual = rectangleA.IntersectsWith(rectangleB);

Assert.IsTrue(actual);
}

[TestMethod]
public void IsEmpty_should_return_false()
{
var sut = new Rectangle(1, 1, 1, 1);

Assert.IsFalse(sut.IsEmpty);
}

[TestMethod]
public void IsEmpty_should_return_true()
{
var sut = new Rectangle(0, 0, 0, 0);

Assert.IsTrue(sut.IsEmpty);
}

[TestMethod]
public void Left_should_be_correct()
{
var sut = new Rectangle(1, 2, 3, 4);

Assert.AreEqual(sut.X, sut.Left);
}

[TestMethod]
public void Location_should_be_correct()
{
var sut = new Rectangle(1, 2, 3, 4);
var expect = new Point(1, 2);

Assert.AreEqual(expect, sut.Location);
}

[TestMethod]
public void Offset_should_move_rectangle()
{
var sut = new Rectangle(Point.Empty, new Size(50, 50));
var offset = new Point(10, 10);

var expect = new Rectangle(offset, sut.Size);

sut.Offset(offset);

Assert.AreEqual(expect, sut);
}

[TestMethod]
public void Right_should_be_correct()
{
var sut = new Rectangle(1, 2, 3, 4);

Assert.AreEqual(sut.X + sut.Width, sut.Right);
}

[TestMethod]
public void Size_should_be_correct()
{
var sut = new Rectangle(1, 2, 3, 4);
var expect = new Size(3, 4);

Assert.AreEqual(expect, sut.Size);
}

[TestMethod]
public void Union_should_create_correct_Rectangle()
{
var rectangleA = new Rectangle(Point.Empty, new Size(100, 100));
var rectangleB = new Rectangle(new Point(50, 50), new Size(100, 100));

var expect = new Rectangle(new Point(50, 50), new Size(50, 50));

var actual = Rectangle.Union(rectangleA, rectangleB);

Assert.AreEqual(expect, actual);
}
}
}
Loading