123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- using System;
- using Xunit;
- namespace Terminal.Gui {
- public class RectTests {
- [Fact]
- public void Rect_New ()
- {
- var rect = new Rect ();
- Assert.True (rect.IsEmpty);
- rect = new Rect (new Point (), new Size ());
- Assert.True (rect.IsEmpty);
- rect = new Rect (1, 2, 3, 4);
- Assert.False (rect.IsEmpty);
- rect = new Rect (-1, -2, 3, 4);
- Assert.False (rect.IsEmpty);
- Action action = () => new Rect (1, 2, -3, 4);
- var ex = Assert.Throws<ArgumentException> (action);
- Assert.Equal ("Width must be greater or equal to 0.", ex.Message);
- action = () => new Rect (1, 2, 3, -4);
- ex = Assert.Throws<ArgumentException> (action);
- Assert.Equal ("Height must be greater or equal to 0.", ex.Message);
- action = () => new Rect (1, 2, -3, -4);
- ex = Assert.Throws<ArgumentException> (action);
- Assert.Equal ("Width must be greater or equal to 0.", ex.Message);
- }
- [Fact]
- public void Rect__SetsValue ()
- {
- var rect = new Rect () {
- X = 0,
- Y = 0
- };
- Assert.True (rect.IsEmpty);
- rect = new Rect () {
- X = -1,
- Y = -2
- };
- Assert.False (rect.IsEmpty);
- rect = new Rect () {
- Width = 3,
- Height = 4
- };
- Assert.False (rect.IsEmpty);
- rect = new Rect () {
- X = -1,
- Y = -2,
- Width = 3,
- Height = 4
- };
- Assert.False (rect.IsEmpty);
- Action action = () => {
- rect = new Rect () {
- X = -1,
- Y = -2,
- Width = -3,
- Height = 4
- };
- };
- var ex = Assert.Throws<ArgumentException> (action);
- Assert.Equal ("Width must be greater or equal to 0.", ex.Message);
- action = () => {
- rect = new Rect () {
- X = -1,
- Y = -2,
- Width = 3,
- Height = -4
- };
- };
- ex = Assert.Throws<ArgumentException> (action);
- Assert.Equal ("Height must be greater or equal to 0.", ex.Message);
- action = () => {
- rect = new Rect () {
- X = -1,
- Y = -2,
- Width = -3,
- Height = -4
- };
- };
- ex = Assert.Throws<ArgumentException> (action);
- Assert.Equal ("Width must be greater or equal to 0.", ex.Message);
- }
- [Fact]
- public void Rect_Equals ()
- {
- var rect1 = new Rect ();
- var rect2 = new Rect ();
- Assert.Equal (rect1, rect2);
- rect1 = new Rect (1, 2, 3, 4);
- rect2 = new Rect (1, 2, 3, 4);
- Assert.Equal (rect1, rect2);
- rect1 = new Rect (1, 2, 3, 4);
- rect2 = new Rect (-1, 2, 3, 4);
- Assert.NotEqual (rect1, rect2);
- }
- }
- }
|