diff --git a/src/flatcollections-array/FlatArray.Tests/Tests.FlatArray.T/Factory/Factory.Explicit.From.Array.cs b/src/flatcollections-array/FlatArray.Tests/Tests.FlatArray.T/Factory/Factory.Explicit.From.Array.cs new file mode 100644 index 00000000..a3b93e6c --- /dev/null +++ b/src/flatcollections-array/FlatArray.Tests/Tests.FlatArray.T/Factory/Factory.Explicit.From.Array.cs @@ -0,0 +1,52 @@ +using System; +using PrimeFuncPack.UnitTest; +using Xunit; +using static PrimeFuncPack.UnitTest.TestData; + +namespace PrimeFuncPack.Core.Tests; + +partial class FlatArrayTest +{ + [Fact] + public void FromArray_SourceIsNull_ExpectInnerStateIsDefault() + { + object?[]? source = null; + var actual = FlatArray.From(source); + + actual.VerifyInnerState(default, default); + } + + [Fact] + public void FromArray_SourceIsEmpty_ExpectInnerStateIsDefault() + { + var source = Array.Empty(); + var actual = FlatArray.From(source); + + actual.VerifyInnerState(default, default); + } + + [Theory] + [InlineData(Zero)] + [InlineData(PlusFifteen, null, MinusFifteen, PlusFifteen)] + [InlineData(12, 15, 1, 91, 7, -95, null, 0, 5, 6, 7, 901, 98, -266, 78, 62, 21, 35, 75, 212, 51)] + public void FromArray_SourceIsNotEmpty_ExpectInnerStateIsSourceArray( + params int?[] source) + { + var coppied = source.GetCopy(); + var actual = FlatArray.From(source); + + actual.VerifyInnerState(coppied, coppied.Length); + } + + [Fact] + public void FromArray_ThenModifySource_ExpectInnerStateHasNotChanged() + { + var sourceArray = new[] { "One", "Two", "Three" }; + var actual = FlatArray.From(sourceArray); + + sourceArray[1] = "2"; + var expectedItems = new[] { "One", "Two", "Three" }; + + actual.VerifyInnerState(expectedItems, expectedItems.Length); + } +} \ No newline at end of file diff --git a/src/flatcollections-array/FlatArray.Tests/Tests.FlatArray.T/Factory/Factory.Explicit.From.FlatArray.cs b/src/flatcollections-array/FlatArray.Tests/Tests.FlatArray.T/Factory/Factory.Explicit.From.FlatArray.cs new file mode 100644 index 00000000..1a74f264 --- /dev/null +++ b/src/flatcollections-array/FlatArray.Tests/Tests.FlatArray.T/Factory/Factory.Explicit.From.FlatArray.cs @@ -0,0 +1,61 @@ +using System; +using PrimeFuncPack.UnitTest; +using Xunit; +using static PrimeFuncPack.UnitTest.TestData; + +namespace PrimeFuncPack.Core.Tests; + +partial class FlatArrayTest +{ + [Fact] + public void FromFlatArray_SourceIsDefault_ExpectInnerStateIsDefault() + { + var source = default(FlatArray); + var actual = FlatArray.From(source); + + actual.VerifyInnerState(default, default); + } + + [Theory] + [InlineData(SomeString, AnotherString)] + [InlineData(LowerSomeString, null, SomeString, EmptyString, WhiteSpaceString)] + public void FromFlatArray_SourceIsNotDefault_ExpectInnerStateIsSourceArray( + params string?[] sourceArray) + { + var coppied = sourceArray.GetCopy(); + + var source = sourceArray.InitializeFlatArray(); + var actual = FlatArray.From(source); + + actual.VerifyInnerState(coppied, coppied.Length); + } + + [Fact] + public void FromNullableFlatArray_SourceIsNull_ExpectInnerStateIsDefault() + { + var source = default(FlatArray?); + var actual = FlatArray.From(source); + + actual.VerifyInnerState(default, default); + } + + [Fact] + public void FromNullableFlatArray_SourceIsDefault_ExpectInnerStateIsDefault() + { + FlatArray? source = default(FlatArray); + var actual = FlatArray.From(source); + + actual.VerifyInnerState(default, default); + } + + [Fact] + public void FromNullableFlatArray_SourceIsNotDefault_ExpectInnerStateIsSourceArray() + { + FlatArray? source = new bool?[] { false, null, true }.InitializeFlatArray(); + + var actual = FlatArray.From(source); + var expectedItems = new bool?[] { false, null, true }; + + actual.VerifyInnerState(expectedItems, expectedItems.Length); + } +} \ No newline at end of file diff --git a/src/flatcollections-array/FlatArray.Tests/Tests.FlatArray.T/Factory/Factory.Explicit.From.ImmutableArray.cs b/src/flatcollections-array/FlatArray.Tests/Tests.FlatArray.T/Factory/Factory.Explicit.From.ImmutableArray.cs new file mode 100644 index 00000000..755f2751 --- /dev/null +++ b/src/flatcollections-array/FlatArray.Tests/Tests.FlatArray.T/Factory/Factory.Explicit.From.ImmutableArray.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Immutable; +using PrimeFuncPack.UnitTest; +using Xunit; +using static PrimeFuncPack.UnitTest.TestData; + +namespace PrimeFuncPack.Core.Tests; + +partial class FlatArrayTest +{ + [Fact] + public void FromImmutableArray_SourceIsDefault_ExpectInnerStateIsDefault() + { + var source = default(ImmutableArray); + var actual = FlatArray.From(source); + + actual.VerifyInnerState(default, default); + } + + [Theory] + [InlineData(SomeString)] + [InlineData(LowerSomeString, null, AnotherString)] + public void FromImmutableArray_SourceIsNotDefault_ExpectInnerStateAreSourceItems( + params string?[] sourceArray) + { + var coppied = sourceArray.GetCopy(); + + var source = sourceArray.ToImmutableArray(); + var actual = FlatArray.From(source); + + actual.VerifyInnerState(coppied, coppied.Length); + } + + [Fact] + public void FromNullableImmutableArray_SourceIsNull_ExpectInnerStateIsDefault() + { + ImmutableArray? source = null; + var actual = FlatArray.From(source); + + actual.VerifyInnerState(default, default); + } + + [Fact] + public void FromNullableImmutableArray_SourceIsDefault_ExpectInnerStateIsDefault() + { + ImmutableArray? source = new ImmutableArray(); + var actual = FlatArray.From(source); + + actual.VerifyInnerState(default, default); + } + + [Theory] + [InlineData(PlusFifteen)] + [InlineData(null, MinusFifteen, Zero)] + public void FromNullableImmutableArray_SourceIsNotDefault_ExpectInnerStateAreSourceItems( + params int?[] sourceItems) + { + var coppied = sourceItems.GetCopy(); + + ImmutableArray? source = sourceItems.ToImmutableArray(); + var actual = FlatArray.From(source); + + actual.VerifyInnerState(coppied, coppied.Length); + } +} \ No newline at end of file diff --git a/src/flatcollections-array/FlatArray.Tests/Tests.FlatArray.T/Factory/Factory.Explicit.From.List.cs b/src/flatcollections-array/FlatArray.Tests/Tests.FlatArray.T/Factory/Factory.Explicit.From.List.cs new file mode 100644 index 00000000..0b771a6b --- /dev/null +++ b/src/flatcollections-array/FlatArray.Tests/Tests.FlatArray.T/Factory/Factory.Explicit.From.List.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using PrimeFuncPack.UnitTest; +using Xunit; +using static PrimeFuncPack.UnitTest.TestData; + +namespace PrimeFuncPack.Core.Tests; + +partial class FlatArrayTest +{ + [Fact] + public void FromList_SourceIsNull_ExpectInnerStateIsDefault() + { + List? source = null; + var actual = FlatArray.From(source); + + actual.VerifyInnerState(default, default); + } + + [Fact] + public void FromList_SourceIsEmpty_ExpectInnerStateIsDefault() + { + var source = new List(); + var actual = FlatArray.From(source); + + actual.VerifyInnerState(default, default); + } + + [Fact] + public void FromList_SourceIsNotEmpty_ExpectInnerStateAreSourceItems() + { + var source = new List + { + SomeTextRecordStruct, null, AnotherTextRecordStruct + }; + + var actual = FlatArray.From(source); + + const int expectedLength = 3; + var expectedItems = new RecordStruct?[] + { + SomeTextRecordStruct, null, AnotherTextRecordStruct + }; + + actual.VerifyInnerState(expectedItems, expectedLength); + } + + [Fact] + public void FromList_ThenModifySource_ExpectInnerStateHasNotChanged() + { + var sourceList = new List + { + MinusFifteenIdSomeStringNameRecord, ZeroIdNullNameRecord, PlusFifteenIdSomeStringNameRecord + }; + + var actual = FlatArray.From(sourceList); + + sourceList[0] = PlusFifteenIdLowerSomeStringNameRecord; + sourceList.Add(MinusFifteenIdNullNameRecord); + + const int expectedLength = 3; + var expectedItems = new[] + { + MinusFifteenIdSomeStringNameRecord, ZeroIdNullNameRecord, PlusFifteenIdSomeStringNameRecord + }; + + actual.VerifyInnerState(expectedItems, expectedLength); + } +} \ No newline at end of file diff --git a/src/flatcollections-array/FlatArray.Tests/Tests.FlatArray.T/Factory/Factory.Explicit.From.cs b/src/flatcollections-array/FlatArray.Tests/Tests.FlatArray.T/Factory/Factory.Explicit.From.cs index f6216a36..02b4254f 100644 --- a/src/flatcollections-array/FlatArray.Tests/Tests.FlatArray.T/Factory/Factory.Explicit.From.cs +++ b/src/flatcollections-array/FlatArray.Tests/Tests.FlatArray.T/Factory/Factory.Explicit.From.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Collections.Immutable; using System.Linq; using PrimeFuncPack.Core.Tests.TestData; using PrimeFuncPack.UnitTest; @@ -11,215 +10,6 @@ namespace PrimeFuncPack.Core.Tests; partial class FlatArrayTest { - [Fact] - public void FromArray_SourceIsNull_ExpectInnerStateIsDefault() - { - object?[]? source = null; - var actual = FlatArray.From(source); - - actual.VerifyInnerState(default, default); - } - - [Fact] - public void FromArray_SourceIsEmpty_ExpectInnerStateIsDefault() - { - var source = Array.Empty(); - var actual = FlatArray.From(source); - - actual.VerifyInnerState(default, default); - } - - [Theory] - [InlineData(Zero)] - [InlineData(PlusFifteen, null, MinusFifteen, PlusFifteen)] - [InlineData(12, 15, 1, 91, 7, -95, null, 0, 5, 6, 7, 901, 98, -266, 78, 62, 21, 35, 75, 212, 51)] - public void FromArray_SourceIsNotEmpty_ExpectInnerStateIsSourceArray( - params int?[] source) - { - var coppied = source.GetCopy(); - var actual = FlatArray.From(source); - - actual.VerifyInnerState(coppied, coppied.Length); - } - - [Fact] - public void FromArray_ThenModifySource_ExpectInnerStateHasNotChanged() - { - var sourceArray = new[] { "One", "Two", "Three" }; - var actual = FlatArray.From(sourceArray); - - sourceArray[1] = "2"; - var expectedItems = new[] { "One", "Two", "Three" }; - - actual.VerifyInnerState(expectedItems, expectedItems.Length); - } - - [Fact] - public void FromFlatArray_SourceIsDefault_ExpectInnerStateIsDefault() - { - var source = default(FlatArray); - var actual = FlatArray.From(source); - - actual.VerifyInnerState(default, default); - } - - [Theory] - [InlineData(SomeString, AnotherString)] - [InlineData(LowerSomeString, null, SomeString, EmptyString, WhiteSpaceString)] - public void FromFlatArray_SourceIsNotDefault_ExpectInnerStateIsSourceArray( - params string?[] sourceArray) - { - var coppied = sourceArray.GetCopy(); - - var source = sourceArray.InitializeFlatArray(); - var actual = FlatArray.From(source); - - actual.VerifyInnerState(coppied, coppied.Length); - } - - [Fact] - public void FromNullableFlatArray_SourceIsNull_ExpectInnerStateIsDefault() - { - var source = default(FlatArray?); - var actual = FlatArray.From(source); - - actual.VerifyInnerState(default, default); - } - - [Fact] - public void FromNullableFlatArray_SourceIsDefault_ExpectInnerStateIsDefault() - { - FlatArray? source = default(FlatArray); - var actual = FlatArray.From(source); - - actual.VerifyInnerState(default, default); - } - - [Fact] - public void FromNullableFlatArray_SourceIsNotDefault_ExpectInnerStateIsSourceArray() - { - FlatArray? source = new bool?[] { false, null, true }.InitializeFlatArray(); - - var actual = FlatArray.From(source); - var expectedItems = new bool?[] { false, null, true }; - - actual.VerifyInnerState(expectedItems, expectedItems.Length); - } - - [Fact] - public void FromList_SourceIsNull_ExpectInnerStateIsDefault() - { - List? source = null; - var actual = FlatArray.From(source); - - actual.VerifyInnerState(default, default); - } - - [Fact] - public void FromList_SourceIsEmpty_ExpectInnerStateIsDefault() - { - var source = new List(); - var actual = FlatArray.From(source); - - actual.VerifyInnerState(default, default); - } - - [Fact] - public void FromList_SourceIsNotEmpty_ExpectInnerStateAreSourceItems() - { - var source = new List - { - SomeTextRecordStruct, null, AnotherTextRecordStruct - }; - - var actual = FlatArray.From(source); - - const int expectedLength = 3; - var expectedItems = new RecordStruct?[] - { - SomeTextRecordStruct, null, AnotherTextRecordStruct - }; - - actual.VerifyInnerState(expectedItems, expectedLength); - } - - [Fact] - public void FromList_ThenModifySource_ExpectInnerStateHasNotChanged() - { - var sourceList = new List - { - MinusFifteenIdSomeStringNameRecord, ZeroIdNullNameRecord, PlusFifteenIdSomeStringNameRecord - }; - - var actual = FlatArray.From(sourceList); - - sourceList[0] = PlusFifteenIdLowerSomeStringNameRecord; - sourceList.Add(MinusFifteenIdNullNameRecord); - - const int expectedLength = 3; - var expectedItems = new[] - { - MinusFifteenIdSomeStringNameRecord, ZeroIdNullNameRecord, PlusFifteenIdSomeStringNameRecord - }; - - actual.VerifyInnerState(expectedItems, expectedLength); - } - - [Fact] - public void FromImmutableArray_SourceIsDefault_ExpectInnerStateIsDefault() - { - var source = default(ImmutableArray); - var actual = FlatArray.From(source); - - actual.VerifyInnerState(default, default); - } - - [Theory] - [InlineData(SomeString)] - [InlineData(LowerSomeString, null, AnotherString)] - public void FromImmutableArray_SourceIsNotDefault_ExpectInnerStateAreSourceItems( - params string?[] sourceArray) - { - var coppied = sourceArray.GetCopy(); - - var source = sourceArray.ToImmutableArray(); - var actual = FlatArray.From(source); - - actual.VerifyInnerState(coppied, coppied.Length); - } - - [Fact] - public void FromNullableImmutableArray_SourceIsNull_ExpectInnerStateIsDefault() - { - ImmutableArray? source = null; - var actual = FlatArray.From(source); - - actual.VerifyInnerState(default, default); - } - - [Fact] - public void FromNullableImmutableArray_SourceIsDefault_ExpectInnerStateIsDefault() - { - ImmutableArray? source = new ImmutableArray(); - var actual = FlatArray.From(source); - - actual.VerifyInnerState(default, default); - } - - [Theory] - [InlineData(PlusFifteen)] - [InlineData(null, MinusFifteen, Zero)] - public void FromNullableImmutableArray_SourceIsNotDefault_ExpectInnerStateAreSourceItems( - params int?[] sourceItems) - { - var coppied = sourceItems.GetCopy(); - - ImmutableArray? source = sourceItems.ToImmutableArray(); - var actual = FlatArray.From(source); - - actual.VerifyInnerState(coppied, coppied.Length); - } - [Fact] public void FromEnumerable_SourceIsNull_ExpectInnerStateIsDefault() {