Skip to content

Commit

Permalink
Arrange FlatArray From factory test files
Browse files Browse the repository at this point in the history
  • Loading branch information
andreise committed Aug 28, 2023
1 parent f8f33b8 commit d6f79ea
Show file tree
Hide file tree
Showing 5 changed files with 247 additions and 210 deletions.
Original file line number Diff line number Diff line change
@@ -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<object?>.From(source);

actual.VerifyInnerState(default, default);
}

[Fact]
public void FromArray_SourceIsEmpty_ExpectInnerStateIsDefault()
{
var source = Array.Empty<StructType>();
var actual = FlatArray<StructType>.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<int?>.From(source);

actual.VerifyInnerState(coppied, coppied.Length);
}

[Fact]
public void FromArray_ThenModifySource_ExpectInnerStateHasNotChanged()
{
var sourceArray = new[] { "One", "Two", "Three" };
var actual = FlatArray<string>.From(sourceArray);

sourceArray[1] = "2";
var expectedItems = new[] { "One", "Two", "Three" };

actual.VerifyInnerState(expectedItems, expectedItems.Length);
}
}
Original file line number Diff line number Diff line change
@@ -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<RefType>);
var actual = FlatArray<RefType>.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<string?>.From(source);

actual.VerifyInnerState(coppied, coppied.Length);
}

[Fact]
public void FromNullableFlatArray_SourceIsNull_ExpectInnerStateIsDefault()
{
var source = default(FlatArray<StructType?>?);
var actual = FlatArray<StructType?>.From(source);

actual.VerifyInnerState(default, default);
}

[Fact]
public void FromNullableFlatArray_SourceIsDefault_ExpectInnerStateIsDefault()
{
FlatArray<RecordType>? source = default(FlatArray<RecordType>);
var actual = FlatArray<RecordType>.From(source);

actual.VerifyInnerState(default, default);
}

[Fact]
public void FromNullableFlatArray_SourceIsNotDefault_ExpectInnerStateIsSourceArray()
{
FlatArray<bool?>? source = new bool?[] { false, null, true }.InitializeFlatArray();

var actual = FlatArray<bool?>.From(source);
var expectedItems = new bool?[] { false, null, true };

actual.VerifyInnerState(expectedItems, expectedItems.Length);
}
}
Original file line number Diff line number Diff line change
@@ -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<long?>);
var actual = FlatArray<long?>.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<string?>.From(source);

actual.VerifyInnerState(coppied, coppied.Length);
}

[Fact]
public void FromNullableImmutableArray_SourceIsNull_ExpectInnerStateIsDefault()
{
ImmutableArray<RecordType>? source = null;
var actual = FlatArray<RecordType>.From(source);

actual.VerifyInnerState(default, default);
}

[Fact]
public void FromNullableImmutableArray_SourceIsDefault_ExpectInnerStateIsDefault()
{
ImmutableArray<RefType?>? source = new ImmutableArray<RefType?>();
var actual = FlatArray<RefType?>.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<int?>? source = sourceItems.ToImmutableArray();
var actual = FlatArray<int?>.From(source);

actual.VerifyInnerState(coppied, coppied.Length);
}
}
Original file line number Diff line number Diff line change
@@ -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<DateOnly>? source = null;
var actual = FlatArray<DateOnly>.From(source);

actual.VerifyInnerState(default, default);
}

[Fact]
public void FromList_SourceIsEmpty_ExpectInnerStateIsDefault()
{
var source = new List<RefType>();
var actual = FlatArray<RefType>.From(source);

actual.VerifyInnerState(default, default);
}

[Fact]
public void FromList_SourceIsNotEmpty_ExpectInnerStateAreSourceItems()
{
var source = new List<RecordStruct?>
{
SomeTextRecordStruct, null, AnotherTextRecordStruct
};

var actual = FlatArray<RecordStruct?>.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<RecordType>
{
MinusFifteenIdSomeStringNameRecord, ZeroIdNullNameRecord, PlusFifteenIdSomeStringNameRecord
};

var actual = FlatArray<RecordType>.From(sourceList);

sourceList[0] = PlusFifteenIdLowerSomeStringNameRecord;
sourceList.Add(MinusFifteenIdNullNameRecord);

const int expectedLength = 3;
var expectedItems = new[]
{
MinusFifteenIdSomeStringNameRecord, ZeroIdNullNameRecord, PlusFifteenIdSomeStringNameRecord
};

actual.VerifyInnerState(expectedItems, expectedLength);
}
}
Loading

0 comments on commit d6f79ea

Please sign in to comment.