public void Aperture_Can_Act_As_A_Transducer() { var expected = new[] { new[] { 1, 2 }, new[] { 2, 3 }, new[] { 3, 4 }, new[] { 4, 5 }, new[] { 5, 6 }, new[] { 6, 7 } }; var res = (Array)R.Into(new object[0], R.Aperture(2), sevenLs); NestedCollectionAssert.AreEqual(res, expected); }
public void Of_Returns_Its_Argument_As_An_Array() { NestedCollectionAssert.AreEqual(R.Of(100), new[] { 100 }); NestedCollectionAssert.AreEqual(R.Of(new[] { 100 }), new object[] { new[] { 100 } }); NestedCollectionAssert.AreEqual(R.Of(R.@null), new[] { R.@null }); NestedCollectionAssert.AreEqual(R.Of(new object[0]), new object[] { new object[0] }); }
public void Partition_Splits_A_List_Into_Two_Lists_According_To_A_Predicate() { NestedCollectionAssert.AreEqual(R.Partition(pred, new object[0]), new object[] { new object[0], new object[0] }); NestedCollectionAssert.AreEqual(R.Partition(pred, new[] { 0, 2, 4, 6 }), new object[] { new object[0], new[] { 0, 2, 4, 6 } }); NestedCollectionAssert.AreEqual(R.Partition(pred, new[] { 1, 3, 5, 7 }), new object[] { new[] { 1, 3, 5, 7 }, new object[0] }); NestedCollectionAssert.AreEqual(R.Partition(pred, new[] { 0, 1, 2, 3 }), new object[] { new[] { 1, 3 }, new object[] { 0, 2 } }); }
public void Aperture_Returns_An_Empty_List_When_N_Greater_Then_List_Length() { NestedCollectionAssert.AreEqual((Array)R.Aperture(1, sevenLs), new[] { new[] { 1 }, new[] { 2 }, new[] { 3 }, new[] { 4 }, new[] { 5 }, new[] { 6 }, new[] { 7 } }); NestedCollectionAssert.AreEqual((Array)R.Aperture(2, sevenLs), new[] { new[] { 1, 2 }, new[] { 2, 3 }, new[] { 3, 4 }, new[] { 4, 5 }, new[] { 5, 6 }, new[] { 6, 7 } }); NestedCollectionAssert.AreEqual((Array)R.Aperture(3, sevenLs), new[] { new[] { 1, 2, 3 }, new[] { 2, 3, 4 }, new[] { 3, 4, 5 }, new[] { 4, 5, 6 }, new[] { 5, 6, 7 } }); NestedCollectionAssert.AreEqual((Array)R.Aperture(4, new[] { 1, 2, 3, 4 }), new[] { new[] { 1, 2, 3, 4 } }); }
public async Task PipeP_Performs_Left_To_Right_Composition_Of_Promise_Returning_Functions() { Assert.AreEqual(R.PipeP(f).Length, 1); Assert.AreEqual(R.PipeP(g).Length, 2); Assert.AreEqual(R.PipeP(f, f).Length, 1); Assert.AreEqual(R.PipeP(f, g).Length, 1); Assert.AreEqual(R.PipeP(g, f).Length, 2); Assert.AreEqual(R.PipeP(g, g).Length, 2); await Task.Run(() => { ((PromiseLikeDynamicDelegate)R.PipeP(f, g)(1)).Then(result1 => { NestedCollectionAssert.AreEqual(result1, new object[] { new[] { 1 }, null }); ((PromiseLikeDynamicDelegate)R.PipeP(g, f)(1)).Then(result2 => { NestedCollectionAssert.AreEqual(result2, new[] { new object[] { 1, null } }); ((PromiseLikeDynamicDelegate)R.PipeP(f, g)(1, 2)).Then(result3 => { NestedCollectionAssert.AreEqual(result3, new object[] { new[] { 1 }, null }); ((PromiseLikeDynamicDelegate)R.PipeP(g, f)(1, 2)).Then(result4 => { NestedCollectionAssert.AreEqual(result4, new object[] { new[] { 1, 2 } }); return(result4); }); return(result3); }); return(result2); }); return(result1); }); }); }
public void Aperture_Creates_A_List_Of_N_tuples_From_A_List() { NestedCollectionAssert.AreEqual((Array)R.Aperture(1, sevenLs), new[] { new[] { 1 }, new[] { 2 }, new[] { 3 }, new[] { 4 }, new[] { 5 }, new[] { 6 }, new[] { 7 } }); NestedCollectionAssert.AreEqual((Array)R.Aperture(2, sevenLs), new[] { new[] { 1, 2 }, new[] { 2, 3 }, new[] { 3, 4 }, new[] { 4, 5 }, new[] { 5, 6 }, new[] { 6, 7 } }); NestedCollectionAssert.AreEqual((Array)R.Aperture(3, sevenLs), new[] { new[] { 1, 2, 3 }, new[] { 2, 3, 4 }, new[] { 3, 4, 5 }, new[] { 4, 5, 6 }, new[] { 5, 6, 7 } }); NestedCollectionAssert.AreEqual((Array)R.Aperture(4, new[] { 1, 2, 3, 4 }), new[] { new[] { 1, 2, 3, 4 } }); }
public void Zip_Returns_An_Array_Of_Tuples() { var a = new[] { 1, 2, 3 }; var b = new[] { 100, 200, 300 }; NestedCollectionAssert.AreEqual(R.Zip(a, b), new object[] { new[] { 1, 100 }, new[] { 2, 200 }, new[] { 3, 300 } }); }
public void Transpose_Skips_Elements_When_Rows_Are_Shorter() { var actual = R.Transpose(new int[][] { new[] { 10, 11 }, new[] { 20 }, new int[0], new[] { 30, 31, 32 } }); var expected = new int[][] { new[] { 10, 20, 30 }, new[] { 11, 31 }, new[] { 32 } }; NestedCollectionAssert.AreEqual(actual, expected); }
public void Transpose_Copes_With_True_False_R_Null_Elements_Of_Arrays() { var actual = R.Transpose(new object[][] { new object[] { true, false, R.@null, null }, new object[] { R.@null, R.@null, false, true } }); var expected = new object[][] { new object[] { true, R.@null }, new object[] { false, R.@null }, new object[] { R.@null, false }, new object[] { R.@null, true } }; NestedCollectionAssert.AreEqual(actual, expected); }
public void Partition_Works_With_Objects() { NestedCollectionAssert.AreEqual(R.Partition(pred, new { }), new object[] { new { }, new { } }); NestedCollectionAssert.AreEqual(R.Partition(pred, new { A = 0, B = 2, C = 4, D = 6 }), new object[] { new { }, new { A = 0, B = 2, C = 4, D = 6 } }); NestedCollectionAssert.AreEqual(R.Partition(pred, new { A = 1, B = 3, C = 5, D = 7 }), new object[] { new { A = 1, B = 3, C = 5, D = 7 }, new { } }); NestedCollectionAssert.AreEqual(R.Partition(pred, new { A = 0, B = 1, C = 2, D = 3 }), new object[] { new { B = 1, D = 3 }, new { A = 0, C = 2 } }); }
public void ToPairs_Only_Iterates_The_Objects_Own_Properties() { var f = new F { X = 1, Y = 2 }; NestedCollectionAssert.AreEqual(R.ToPairs(f), new object[] { new object[] { "X", 1 }, new object[] { "Y", 2 } }); }
public void Aperture_Is_Curried() { var pairwise = R.Aperture(2); var res = (Array)pairwise(sevenLs); var expected = new[] { new[] { 1, 2 }, new[] { 2, 3 }, new[] { 3, 4 }, new[] { 4, 5 }, new[] { 5, 6 }, new[] { 6, 7 } }; NestedCollectionAssert.AreEqual(res, expected); }
public void Sequence_Operates_On_A_List_Of_Lists() { NestedCollectionAssert.AreEqual(R.Sequence(R.Of(R.__), new object[0]), new object[] { new object[0] }); NestedCollectionAssert.AreEqual(R.Sequence(R.Of(R.__), new object[] { new object[0], new[] { 1, 2, 3, 4 } }), new int[0]); NestedCollectionAssert.AreEqual(R.Sequence(R.Of(R.__), new object[] { new[] { 1 }, new[] { 2, 3, 4 } }), new object[] { new[] { 1, 2 }, new[] { 1, 3 }, new[] { 1, 4 } }); NestedCollectionAssert.AreEqual(R.Sequence(R.Of(R.__), new object[] { new[] { 1, 2 }, new[] { 3, 4 } }), new object[] { new[] { 1, 3 }, new[] { 1, 4 }, new[] { 2, 3 }, new[] { 2, 4 } }); NestedCollectionAssert.AreEqual(R.Sequence(R.Of(R.__), new object[] { new[] { 1, 2, 3 }, new[] { 4 } }), new object[] { new[] { 1, 4 }, new[] { 2, 4 }, new[] { 3, 4 } }); NestedCollectionAssert.AreEqual(R.Sequence(R.Of(R.__), new object[] { new[] { 1, 2, 3, 4 }, new int[0] }), new int[0]); }
public void Product_Selects_The_Chosen_Properties_From_Each_Element_In_A_List() { NestedCollectionAssert.AreEqual(R.Project(new[] { "Name", "Age" }, kids), new[] { new { Name = "Abby", Age = 7 }, new { Name = "Fred", Age = 12 }, new { Name = "Rusty", Age = 10 }, new { Name = "Alois", Age = 15 } }); }
public void Product_Has_An_Undefined_Property_On_The_Output_Tuple_For_Any_Input_Tuple_That_Does_Not_Have_The_Property() { NestedCollectionAssert.AreEqual(R.Project(new[] { "Name", "Hair" }, kids), new object[] { new { Name = "Abby", Hair = "blond" }, new { Name = "Fred", Hair = "brown" }, new { Name = "Rusty", Hair = "brown" }, new { Name = "Alois", Hair = R.@null } }); }
public void Zip_Returns_A_List_As_Long_As_The_Shorter_Of_The_Lists_Input() { var a = new[] { 1, 2, 3 }; var b = new[] { 100, 200, 300, 400 }; var c = new[] { 10, 20 }; NestedCollectionAssert.AreEqual(R.Zip(a, b), new object[] { new[] { 1, 100 }, new[] { 2, 200 }, new[] { 3, 300 } }); NestedCollectionAssert.AreEqual(R.Zip(a, c), new object[] { new[] { 1, 10 }, new[] { 2, 20 } }); }
public void Traverse_Operates_On_A_List_Of_Lists() { NestedCollectionAssert.AreEqual(R.Traverse(R.Of(R.__), R.Map(R.Add(10)), new int[0]), new int[][] { new int[0] }); NestedCollectionAssert.AreEqual(R.Traverse(R.Of(R.__), R.Map(R.Add(10)), new int[][] { new int[0], new[] { 1, 2, 3, 4 } }), new int[0]); NestedCollectionAssert.AreEqual(R.Traverse(R.Of(R.__), R.Map(R.Add(10)), new int[][] { new[] { 1 }, new[] { 2, 3, 4 } }), new int[][] { new[] { 11, 12 }, new[] { 11, 13 }, new[] { 11, 14 } }); NestedCollectionAssert.AreEqual(R.Traverse(R.Of(R.__), R.Map(R.Add(10)), new int[][] { new[] { 1, 2 }, new[] { 3, 4 } }), new int[][] { new[] { 11, 13 }, new[] { 11, 14 }, new[] { 12, 13 }, new[] { 12, 14 } }); NestedCollectionAssert.AreEqual(R.Traverse(R.Of(R.__), R.Map(R.Add(10)), new int[][] { new[] { 1, 2, 3 }, new[] { 4 } }), new[] { new[] { 11, 14 }, new[] { 12, 14 }, new[] { 13, 14 } }); NestedCollectionAssert.AreEqual(R.Traverse(R.Of(R.__), R.Map(R.Add(10)), new int[][] { new[] { 1, 2, 3, 4 }, new int[0] }), new int[0]); }
public void Unnest_Only_Flattens_One_Layer_Deep_Of_A_Nested_List() { var nest = new object[] { 1, new[] { 2 }, new object[] { 3, new[] { 4, 5 }, 6, new object[] { new object[] { new[] { 7 }, 8 } } }, 9, 10 }; NestedCollectionAssert.AreEqual(R.Unnest(nest), new object[] { 1, 2, 3, new[] { 4, 5 }, 6, new object[] { new object[] { new[] { 7 }, 8 } }, 9, 10 }); nest = new object[] { new object[] { new object[] { new[] { 3 } }, 2, 1 }, 0, new object[] { new[] { -1, -2 }, -3 } }; NestedCollectionAssert.AreEqual(R.Unnest(nest), new object[] { new object[] { new[] { 3 } }, 2, 1, 0, new[] { -1, -2 }, -3 }); NestedCollectionAssert.AreEqual(R.Unnest(new[] { 1, 2, 3, 4, 5 }), new[] { 1, 2, 3, 4, 5 }); }
public void PropEq_Is_Curried() { var hairMatch = R.PropEq("Hair"); var brunette = hairMatch("brown"); var kids = new[] { obj1, obj2, obj3, obj4 }; Assert.IsInstanceOfType(hairMatch, typeof(DynamicDelegate)); NestedCollectionAssert.AreEqual(R.Filter(brunette, kids), new[] { obj2, obj3 }); NestedCollectionAssert.AreEqual(R.Filter(R.PropEq("Hair", "brown"), kids), new[] { obj2, obj3 }); }
public void Unnest_Handles_Array_Like_Objects() { var o = new Dictionary <string, object> { ["Length"] = 3, ["1"] = new int[0], ["0"] = new object[] { 1, 2, new[] { 3 } }, ["2"] = new object[] { "a", "b", "c", new[] { "d", "e" } } }; NestedCollectionAssert.AreEqual(R.Unnest(o), new object[] { 1, 2, new[] { 3 }, "a", "b", "c", new[] { "d", "e" } }); }
public void Product_Is_Curried() { var myFields = R.Project(new[] { "Name", "Age" }); NestedCollectionAssert.AreEqual(myFields(kids), new[] { new { Name = "Abby", Age = 7 }, new { Name = "Fred", Age = 12 }, new { Name = "Rusty", Age = 10 }, new { Name = "Alois", Age = 15 } }); }
public void SplitEvery_Splits_A_Collection_Into_Slices_Of_The_Specified_Length() { NestedCollectionAssert.AreEqual(R.SplitEvery(1, new[] { 1, 2, 3, 4 }), new object[] { new[] { 1 }, new[] { 2 }, new[] { 3 }, new[] { 4 } }); NestedCollectionAssert.AreEqual(R.SplitEvery(2, new[] { 1, 2, 3, 4 }), new[] { new[] { 1, 2 }, new[] { 3, 4 } }); NestedCollectionAssert.AreEqual(R.SplitEvery(3, new[] { 1, 2, 3, 4 }), new[] { new[] { 1, 2, 3 }, new[] { 4 } }); NestedCollectionAssert.AreEqual(R.SplitEvery(4, new[] { 1, 2, 3, 4 }), new[] { new[] { 1, 2, 3, 4 } }); NestedCollectionAssert.AreEqual(R.SplitEvery(5, new[] { 1, 2, 3, 4 }), new[] { new[] { 1, 2, 3, 4 } }); CollectionAssert.AreEqual(R.SplitEvery(3, new int[0]), new int[0]); CollectionAssert.AreEqual(R.SplitEvery(1, "abcd"), new[] { "a", "b", "c", "d" }); CollectionAssert.AreEqual(R.SplitEvery(2, "abcd"), new[] { "ab", "cd" }); CollectionAssert.AreEqual(R.SplitEvery(3, "abcd"), new[] { "abc", "d" }); CollectionAssert.AreEqual(R.SplitEvery(4, "abcd"), new[] { "abcd" }); CollectionAssert.AreEqual(R.SplitEvery(5, "abcd"), new[] { "abcd" }); CollectionAssert.AreEqual(R.SplitEvery(3, string.Empty), new string[0]); }
public void Keys_Works_For_Primitives() { var result = R.Map(val => R.Keys(val), new object[] { R.@null, 55, string.Empty, true, false, new object[0] }); NestedCollectionAssert.AreEqual(result, R.Repeat(new string[0], 6)); }
public void Append_Adds_The_Element_To_The_End_Of_The_List() { NestedCollectionAssert.AreEqual(R.Append("z", new[] { "x", "y" }), new[] { "x", "y", "z" }); NestedCollectionAssert.AreEqual((IList)R.Append <object>(new string[] { "a", "z" }, new[] { "x", "y" }), new object[] { "x", "y", new object[] { "a", "z" } }); }
public void Transpose_Returns_An_Array_Of_Two_Arrays() { var input = new object[][] { new object[] { "a", 1 }, new object[] { "b", 2 }, new object[] { "c", 3 } }; NestedCollectionAssert.AreEqual(R.Transpose(input), new object[] { new[] { "a", "b", "c" }, new[] { 1, 2, 3 } }); }
public void SplitWhen_Splits_An_Array_At_The_First_Instance_To_Satisfy_The_Predicate() { NestedCollectionAssert.AreEqual(R.SplitWhen(R.Equals(2), new[] { 1, 2, 3 }), new object[] { new[] { 1 }, new object[] { 2, 3 } }); }
public void Insert_Inserts_Another_List_As_An_Element() { NestedCollectionAssert.AreEqual(R.Insert(2, new[] { "s", "t" }, list), new object[] { "a", "b", new[] { "s", "t" }, "c", "d", "e" }); }
public void Values_Returns_An_Empty_Object_For_Primitives() { var result = R.Map(val => R.Values(val), new object[] { R.@null, 55, string.Empty, true, false, new object[0] }); NestedCollectionAssert.AreEqual(result, R.Repeat(new object[0], 6)); }
public void LensIndex_Over_Applies_Function_To_The_Value_At_The_Specified_List_Index() { NestedCollectionAssert.AreEqual(R.Over(R.LensIndex(2), R.Keys(R.__), testList), new object[] { new { A = 1 }, new { B = 2 }, new[] { "C" } }); }
public void Partition_Is_Curried() { var polarize = R.Partition((Func <object, bool>)Convert.ToBoolean); NestedCollectionAssert.AreEqual(polarize(new object[] { true, 0, 1, null }), new[] { new object[] { true, 1 }, new object[] { 0, R.@null } }); }