public void ReduceBy_Can_Act_As_A_Transducer() { var reduceToSumsBy = R.ReduceBy(sumValues, 0); var sumByType = reduceToSumsBy(byType); DynamicAssert.AreEqual(R.Into(new { }, R.Compose(sumByType, R.Map(R.Adjust(R.Multiply(10), 1))), sumInput), new { A = 800, B = 800, C = 500 }); }
public void Lenses_view_Over_And_Set_May_Be_Applied_To_Composed_Lenses() { var streetLens = R.Compose(AddressLens, HeadLens); var dogLens = R.Compose(R.LensPath(new[] { "Pets" }), R.LensPath(new[] { "Dog" })); Assert.AreEqual(R.View(dogLens, Alice), R.View(R.LensPath(new[] { "Pets", "Dog" }), Alice)); Assert.AreEqual(R.View(streetLens, Alice), "22 Walnut St"); DynamicAssert.AreEqual(R.Over(streetLens, R.ToUpper(R.__), Alice), new Person() { Name = "Alice Jones", Address = new[] { "22 WALNUT ST", "San Francisco", "CA" }, Pets = new Dictionary <string, string> { ["Dog"] = "Joker", ["Cat"] = "Batman" } }); DynamicAssert.AreEqual(R.Set(streetLens, "52 Crane Ave", Alice), new Person() { Name = "Alice Jones", Address = new[] { "52 Crane Ave", "San Francisco", "CA" }, Pets = new Dictionary <string, string> { ["Dog"] = "Joker", ["Cat"] = "Batman" } }); }
public void Merge_Is_Not_Destructive() { var a = new { W = 1, X = 2 }; var res = R.Merge(a, new { X = 5 }); DynamicAssert.AreEqual(res, new { W = 1, X = 5 }); }
public void Merge_Overrides_Properties_In_The_First_Object_With_Properties_In_The_Second_Object() { var a = new { W = 1, X = 2 }; var b = new { W = 100, Y = 3, Z = 4 }; DynamicAssert.AreEqual(R.Merge(a, b), new { W = 100, X = 2, Y = 3, Z = 4 }); }
public void ReduceBy_Is_Curried() { var reduceToSumsBy = R.ReduceBy(sumValues, 0); var sumByType = reduceToSumsBy(byType); DynamicAssert.AreEqual(sumByType(sumInput), new { A = 80, B = 80, C = 50 }); }
public void Invert_Is_Not_Destructive() { var input = new { X = "A", Y = "B", Z = "A", _ID = "A" }; R.Invert(input); DynamicAssert.AreEqual(input, new { X = "A", Y = "B", Z = "A", _ID = "A" }); }
public void Clone_Deep_Clone_Objects_Clones_Deep_Object() { var obj = new { a = new { b = new { c = "ramda" } } }; ExpandoObject cloned = ((object)R.Clone(obj)).ToDynamic(); DynamicAssert.AreEqual(cloned, obj); }
public void ForEachObjIndexed_Returns_The_Original_Object() { var s = string.Empty; DynamicAssert.AreEqual(R.ForEachObjIndexed((value, key, target) => { s += value; }, obj), obj); Assert.AreEqual("12123", s); }
public void MergeAll_Ignores_Inherited_Properties() { var foo = new Foo(); var res = R.MergeAll(new object[] { foo, new { Fizz = "buzz" } }); DynamicAssert.AreEqual(res, new { FIZZ = "buzz" }); }
public void Dissoc_Copies_An_Object_Omitting_The_Specified_Property() { var anonymous = new { A = 1, B = 2, C = 3 }; DynamicAssert.AreEqual(R.Dissoc("B", anonymous), new { A = 1, C = 3 }); DynamicAssert.AreEqual(R.Dissoc("D", anonymous), new { A = 1, B = 2, C = 3 }); }
public void MergeWithKey_Takes_Two_Objects_Merges_Their_Own_Properties_And_Returns_A_New_Object() { var a = new { W = 1, X = 2 }; var b = new { Y = 3, Z = 4 }; DynamicAssert.AreEqual(R.MergeWithKey(last, a, b), new { W = 1, X = 2, Y = 3, Z = 4 }); }
public void AddIndex_Binary_Functions_Like_Reduce_Passes_The_Index_As_A_Third_Parameter_To_The_Predicate() { ExpandoObject reduced = reduceIndexed(objectify, new ExpandoObject(), new[] { "a", "b", "c", "d", "e" }); Assert.AreEqual((int)reduceIndexed(timesIndexed, 0, new[] { 1, 2, 3, 4, 5 }), 40); DynamicAssert.AreEqual(reduced, new { a = 0, b = 1, c = 2, d = 3, e = 4 }); }
public void Traverse_Dispatches_To_Sequence_Method() { var Id = new Func <object, _Id>(_Id.Id); DynamicAssert.AreEqual(R.Traverse(Id, R.Map(R.Negate(R.__)), new[] { Id(1), Id(2), Id(3) }), Id(new[] { -1, -2, -3 })); CollectionAssert.AreEqual(R.Traverse(R.Of(R.__), R.Map(R.Negate(R.__)), Id(new[] { 1, 2, 3 })), new[] { Id(-1), Id(-2), Id(-3) }); }
public void DissocPath_Leaves_An_Empty_Object_When_All_Properties_Omitted() { var obj1 = new { A = 1, B = new { C = 2 }, D = 3 }; var obj2 = R.DissocPath(new[] { "B", "C" }, obj1); DynamicAssert.AreEqual(obj2, new { A = 1, B = new { }, D = 3 }); }
public void Evolve_Creates_A_New_Object_By_Evolving_The_Object_According_To_The_Transformation_Functions() { var transf = new { Elapsed = R.Add(1), Remaining = R.Add(-1) }; var obj = new { Name = "Tomato", Elapsed = 100, Remaining = 1400 }; var expected = new { Name = "Tomato", Elapsed = 101, Remaining = 1399 }; DynamicAssert.AreEqual(expected, R.Evolve(transf, obj)); }
public void Reject_Filters_Objects() { DynamicAssert.AreEqual(R.Reject(R.Equals(0), new { }), new { }); DynamicAssert.AreEqual(R.Reject(R.Equals(0), new { X = 0, Y = 0, Z = 0 }), new { }); DynamicAssert.AreEqual(R.Reject(R.Equals(0), new { X = 1, Y = 0, Z = 0 }), new { X = 1 }); DynamicAssert.AreEqual(R.Reject(R.Equals(0), new { X = 1, Y = 2, Z = 0 }), new { X = 1, Y = 2 }); DynamicAssert.AreEqual(R.Reject(R.Equals(0), new { X = 1, Y = 2, Z = 3 }), new { X = 1, Y = 2, Z = 3 }); }
public void MergeWithKey_Is_Not_Destructive() { var a = new { W = 1, X = 2 }; var res = R.MergeWithKey(last, a, new { X = 5 }); Assert.AreNotEqual(a, res); DynamicAssert.AreEqual(res, new { W = 1, X = 5 }); }
public void MergeWithKey_Applies_The_Provided_Function_To_The_Value_From_The_First_Object_And_The_Value_From_The_Second_Object_To_Determine_The_Value_For_Keys_That_Exist_In_Both_Objects() { var a = new { A = "B", X = "D" }; var b = new { A = "C", Y = "E" }; var c = R.MergeWithKey((string k, string _a, string _b) => k + _a + _b, a, b); DynamicAssert.AreEqual(c, new { A = "ABC", X = "D", Y = "E" }); }
public void Omit_Includes_Prototype_Properties() { var obj = new F(30); obj.V = 10; obj.W = 20; DynamicAssert.AreEqual(R.Omit(new[] { "W", "X", "Y" }, obj), new { V = 10, Z = 50 }); }
public void Evolve_Does_Not_Invoke_Function_If_Object_Does_Not_Contain_The_Key() { var transf = new { N = R.Add(1), M = R.Add(1) }; var obj = new { M = 3 }; var expected = new { M = 4 }; DynamicAssert.AreEqual(R.Evolve(transf, obj), expected); }
public void Evolve_Ignores_Null_Transformations() { var transf = new { N = (object)null }; var obj = new { N = 0 }; var expected = new { N = 0 }; DynamicAssert.AreEqual(R.Evolve(transf, obj), expected); }
public void Evolve_Ignores_Primitive_Value_Transformations() { var transf = new { N = 2, M = "foo" }; var obj = new { N = 0, M = 1 }; var expected = new { N = 0, M = 1 }; DynamicAssert.AreEqual(R.Evolve(transf, obj), expected); }
public void Evolve_Is_Curried() { var tick = R.Evolve(new { Elapsed = R.Add(1), Remaining = R.Add(-1) }); var obj = new { Name = "Tomato", Elapsed = 100, Remaining = 1400 }; var expected = new { Name = "Tomato", Elapsed = 101, Remaining = 1399 }; DynamicAssert.AreEqual(tick(obj), expected); }
public void Evolve_Is_Recursive() { var transf = new { Nested = new { Second = R.Add(-1), Third = R.Add(1) } }; var obj = new { First = 1, Nested = new { Second = 2, Third = 3 } }; var expected = new { First = 1, Nested = new { Second = 1, Third = 4 } }; DynamicAssert.AreEqual(R.Evolve(transf, obj), expected); }
public void ForEachObjIndexed_Performs_The_Passed_In_Function_On_Each_Key_And_Value_Of_The_Object() { IDictionary <string, object> sideEffect = new ExpandoObject(); R.ForEachObjIndexed((value, key, target) => { sideEffect[key] = value; }, obj); DynamicAssert.AreEqual(sideEffect, obj); }
public void PickBy_Retrieves_Prototype_Properties() { var obj = new F(30) { V = 10, W = 20 }; DynamicAssert.AreEqual(R.PickBy((val, key, _) => (int)val < 45, obj), new { V = 10, W = 20, X = 30, Y = 40 }); }
public void DissocPath_Includes_Well_Typed_Properties() { var obj1 = new F { B = new { C = 2, D = 3 } }; var obj2 = R.DissocPath(new[] { "B", "C" }, obj1); DynamicAssert.AreEqual(obj2, new { A = 1, B = new { D = 3 } }); }
public void Dissoc_Includes_Well_Typed_Properties() { var rect = new Rectangle(7, 6); var area = rect.Area; DynamicAssert.AreEqual(R.Dissoc("Area", rect), new { Width = 7, Height = 6 }); DynamicAssert.AreEqual(R.Dissoc("Width", rect), new { Height = 6, Area = area }); DynamicAssert.AreEqual(R.Dissoc("Depth", rect), new { Width = 7, Height = 6, Area = area }); }
public void DissocPath_Is_Curried() { var obj1 = new { A = new { B = 1, C = 2, D = new { E = 3 } }, F = new { G = new { H = 4, I = 5, J = new { K = 6, L = 7 } } }, M = 8 }; var expected = new { A = new { B = 1, C = 2, D = new { E = 3 } }, F = new { G = new { H = 4, J = new { K = 6, L = 7 } } }, M = 8 }; var f = R.DissocPath(new[] { "F", "G", "I" }); var res = f(obj1); DynamicAssert.AreEqual(res, expected); }
public void Pick_Retrieves_Prototype_Properties() { var obj = new F(30) { V = 10, W = 20 }; DynamicAssert.AreEqual(R.Pick(new[] { "W", "X", "Y" }, obj), new { W = 20, X = 30, Y = 40 }); }