Example #1
0
            public void ShouldReturnEmptyCollectionForEmptyString()
            {
                // Arrange
                var sut = new StringMeasurer();

                // Act
                var actual = sut.Measure(string.Empty, Font);

                // Assert
                Assert.Empty(actual.Rectangles);
            }
Example #2
0
            public void ShouldReturnMeasurementWithCorrectWord()
            {
                // Arrange
                var          sut      = new StringMeasurer();
                const string expected = "testword";

                // Act
                var actual = sut.Measure(expected, Font);

                // Assert
                Assert.Equal(expected, actual.Word);
            }
Example #3
0
            public void ShouldProduceRectangleBiggerThanRectSpacing()
            {
                // Arrange
                var sut = new StringMeasurer();

                // Act
                var actual = sut.Measure(".", Font);

                // Assert
                Assert.True(actual.Rectangles.First().Width > 2 * StringMeasurer.RectSpacing);
                Assert.True(actual.Rectangles.First().Height > 2 * StringMeasurer.RectSpacing);
            }
Example #4
0
            public void ShouldContainOneRectanglePerChar()
            {
                // Arrange
                var          sut  = new StringMeasurer();
                const string word = "testword";

                // Act
                var actual = sut.Measure(word, Font);

                // Assert
                Assert.Equal(word.Length, actual.Rectangles.Count);
            }
Example #5
0
            public void ShouldProduceRectanglesWithSameSize()
            {
                // Arrange
                var sut = new StringMeasurer();

                // Act
                var result = sut.Measure("xX", Font);

                // Assert
                var distinctSizes = result.Rectangles.Select(r => Tuple.Create(r.Width, r.Height)).Distinct().ToList();

                Assert.Single(distinctSizes);
            }
Example #6
0
            public void ShouldHaveOffsetThatAlignsRectToZero()
            {
                // Arrange
                var sut = new StringMeasurer();

                // Act
                var actual = sut.Measure("test", Font);

                // Assert
                var offset = actual.Offset;
                var rect   = actual.Rectangles.First();

                Assert.Equal(0, offset.X + rect.X, 4);
                Assert.Equal(0, offset.Y + rect.Y, 4);
            }