diff --git a/UnicodeInformation.Tests/UnicodeCodePointRangeTests.cs b/UnicodeInformation.Tests/UnicodeCodePointRangeTests.cs new file mode 100644 index 0000000..c9139ee --- /dev/null +++ b/UnicodeInformation.Tests/UnicodeCodePointRangeTests.cs @@ -0,0 +1,84 @@ +using System; +using System.Collections; +using System.Unicode; +using Xunit; + +namespace UnicodeInformation.Tests +{ + public class UnicodeCodePointRangeTests + { + [Theory] + [InlineData(0, 0x10FFFF)] + public void MultiCodePointRangeShouldHaveExpectedResults(int firstCodePoint, int lastCodePoint) + { + var range = new UnicodeCodePointRange(firstCodePoint, lastCodePoint); + + Assert.Equal(firstCodePoint, range.FirstCodePoint); + Assert.Equal(lastCodePoint, range.LastCodePoint); + Assert.False(range.IsSingleCodePoint); + } + + [Theory] + [InlineData((int)'A')] + [InlineData(0x0)] + [InlineData(0x10FFFF)] + public void SingleCodePointRangeShouldHaveExpectedResults(int codePoint) + { + var range = new UnicodeCodePointRange(codePoint); + + Assert.Equal(codePoint, range.FirstCodePoint); + Assert.Equal(codePoint, range.LastCodePoint); + Assert.True(range.IsSingleCodePoint); + } + + [Theory] + [InlineData(-1)] + [InlineData(0x110000)] + [InlineData(int.MaxValue)] + public void ConstructorShouldFailForInvalidCodePoint(int codePoint) + { + Assert.Throws(() => new UnicodeCodePointRange(codePoint)); + } + + [Theory] + [InlineData(-1, 10)] + [InlineData(10, 0x110000)] + [InlineData(-1, 0x110000)] + public void ConstructorShouldFailForInvalidCodePoints(int firstCodePoint, int lastCodePoint) + { + Assert.Throws(() => new UnicodeCodePointRange(firstCodePoint, lastCodePoint)); + } + + [Theory] + [InlineData(0xA3F, 0x105F)] + public void EnumerationShouldHaveExpectedResults(int firstCodePoint, int lastCodePoint) + { + // Generic test + { + int i = firstCodePoint; + + foreach (int n in new UnicodeCodePointRange(firstCodePoint, lastCodePoint)) + { + Assert.Equal(i++, n); + } + } + + // Nongeneric test + { + int i = firstCodePoint; + + var enumerator = (IEnumerator)new UnicodeCodePointRange(firstCodePoint, lastCodePoint).GetEnumerator(); + + while (enumerator.MoveNext()) + { + Assert.Equal(i++, enumerator.Current); + } + + enumerator.Reset(); + + Assert.True(enumerator.MoveNext()); + Assert.Equal(firstCodePoint, enumerator.Current); + } + } + } +} diff --git a/UnicodeInformation.Tests/UnicodeInfoTests.cs b/UnicodeInformation.Tests/UnicodeInfoTests.cs index 58dab54..e46b4bb 100644 --- a/UnicodeInformation.Tests/UnicodeInfoTests.cs +++ b/UnicodeInformation.Tests/UnicodeInfoTests.cs @@ -1,10 +1,7 @@ using System; using System.Unicode; using System.Globalization; -using System.Collections.Generic; -using System.Collections; using Xunit; -using System.Linq; namespace UnicodeInformation.Tests { @@ -99,7 +96,7 @@ namespace UnicodeInformation.Tests } [Fact] - public void TestRadicalStrokeCount() + public void RadicalStrokeCountShouldHaveExpectedResults() { var char5E7A = UnicodeInfo.GetCharInfo(0x5E7A); @@ -117,7 +114,7 @@ namespace UnicodeInformation.Tests } [Fact] - public void TestRadicalInfo() + public void RadicalInfoShouldHaveExpectedResults() { var radical1 = UnicodeInfo.GetCjkRadicalInfo(1); @@ -141,74 +138,6 @@ namespace UnicodeInformation.Tests Assert.Throws(() => UnicodeInfo.GetCjkRadicalInfo(215)); } - [Fact] - public void TestCodePointRange() - { - var fullRange = new UnicodeCodePointRange(0, 0x10FFFF); - - Assert.Equal(0, fullRange.FirstCodePoint); - Assert.Equal(0x10FFFF, fullRange.LastCodePoint); - Assert.False(fullRange.IsSingleCodePoint); - - var letterA = new UnicodeCodePointRange('A'); - - Assert.Equal('A', letterA.FirstCodePoint); - Assert.Equal('A', letterA.LastCodePoint); - Assert.True(letterA.IsSingleCodePoint); - } - - [Theory] - [InlineData(-1)] - [InlineData(0x110000)] - [InlineData(int.MaxValue)] - public void TestInvalidSingleCodePointRanges(int codePoint) - { - Assert.Throws(() => new UnicodeCodePointRange(codePoint)); - } - - [Theory] - [InlineData(-1, 10)] - [InlineData(10, 0x110000)] - [InlineData(-1, 0x110000)] - public void TestInvalidCodePointRanges(int firstCodePoint, int lastCodePoint) - { - Assert.Throws(() => new UnicodeCodePointRange(firstCodePoint, lastCodePoint)); - } - - [Fact] - public void TestCodePointRangeEnumeration() - { - const int start = 0xA3F; - const int end = 0x105F; - - // Generic test - { - int i = start; - - foreach (int n in new UnicodeCodePointRange(start, end)) - { - Assert.Equal(i++, n); - } - } - - // Nongeneric test - { - int i = start; - - var enumerator = (IEnumerator)new UnicodeCodePointRange(start, end).GetEnumerator(); - - while (enumerator.MoveNext()) - { - Assert.Equal(i++, enumerator.Current); - } - - enumerator.Reset(); - - Assert.True(enumerator.MoveNext()); - Assert.Equal(start, enumerator.Current); - } - } - [Fact] public void MethodGetNameShouldNeverFail() { @@ -246,7 +175,7 @@ namespace UnicodeInformation.Tests } [Fact] - public void TestGetCharInfoCoherence() + public void MethodGetCharInfoShouldHaveCoherentResults() { for (int i = 0; i <= 0x10FFFF; i++) { @@ -260,7 +189,7 @@ namespace UnicodeInformation.Tests #if DEBUG [Fact] - public void TestUnihanCodePointPacking() + public void UnihanCodePointPackingShouldHaveExpectedResults() { for (int i = 0x3400; i < 0x4E00; ++i) Assert.Equal(i, UnihanCharacterData.UnpackCodePoint(UnihanCharacterData.PackCodePoint(i))); diff --git a/UnicodeInformation.Tests/UnicodeInformation.Tests.csproj b/UnicodeInformation.Tests/UnicodeInformation.Tests.csproj index 1291411..9f27439 100644 --- a/UnicodeInformation.Tests/UnicodeInformation.Tests.csproj +++ b/UnicodeInformation.Tests/UnicodeInformation.Tests.csproj @@ -72,6 +72,7 @@ +