using System; using System.Collections.Generic; using System.Linq; using Xunit; public class FlattenArrayTest { [Fact] public void Flattens_A_Nested_List() { var nestedList = new List { new List() }; Assert.Empty(Flattener.Flatten(nestedList)); } [Fact(Skip = "Remove to run test")] public void Flattens_2_Level_Nested_List() { var nestedList = new List { 1, new List { 2, 3, 4 }, 5 }; Assert.Equal(new List { 1, 2, 3, 4, 5 }, Flattener.Flatten(nestedList).Cast()); } [Fact(Skip = "Remove to run test")] public void Flattens_3_Level_Nested_List() { var nestedList = new List { 1, new List { 2, 3, 4 }, 5, new List { 6, new List { 7, 8 } } }; Assert.Equal(new List { 1, 2, 3, 4, 5, 6, 7, 8 }, Flattener.Flatten(nestedList).Cast()); } [Fact(Skip = "Remove to run test")] public void Flattens_5_Level_Nested_List() { var nestedList = new List { 0, 2, new List { new List { 2, 3 }, 8, 100, 4, new List { new List { new List { 50 } } }, -2 } }; Assert.Equal(new List { 0, 2, 2, 3, 8, 100, 4, 50, -2 }, Flattener.Flatten(nestedList).Cast()); } [Fact(Skip = "Remove to run test")] public void Flattens_6_Level_Nested_List() { var nestedList = new List { 1, new List { 2, new List { new List { 3 } }, new List { 4, new List { new List { 5 } } }, 6, 7 }, 8 }; Assert.Equal(new List { 1, 2, 3, 4, 5, 6, 7, 8 }, Flattener.Flatten(nestedList).Cast()); } [Fact(Skip = "Remove to run test")] public void Flattens_6_Level_Nested_List_With_Nulls() { var nestedList = new List { 1, new List { 2, null, new List { new List { 3 }, null }, new List { 4, new List { new List { 5 } } }, 6, 7, new List { new List { null } } }, 8, null }; Assert.Equal(new List { 1, 2, 3, 4, 5, 6, 7, 8 }, Flattener.Flatten(nestedList).Cast()); } [Fact(Skip = "Remove to run test")] public void All_Null_Nested_List_Returns_Empty_List() { var nestedList = new List { null, new List { null, new List { null }, new List { new List { new List { null } } } }, null }; Assert.Empty(Flattener.Flatten(nestedList)); } }