Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MAGN-3992 #2041

Merged
merged 3 commits into from
Jul 29, 2014
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
MaximumItem, MinimumItem & Sort nodes don't replicate
- Updated the input argument type as IEnumerable<object> so that the
argument is marshaled as 1D collection, and hence it will replicate on
multi-dimension collection.
- On multi dimension collection these methods fail or behave wrong. It
should replicate and return values from each collection.
- Fixed http://adsk-oss.myjetbrains.com/youtrack/issue/MAGN-3567
sharadkjaiswal committed Jul 25, 2014

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
commit 3ba816a5cccc5db85ea836e6c1b7b31c75b56116
12 changes: 6 additions & 6 deletions src/Libraries/CoreNodes/List.cs
Original file line number Diff line number Diff line change
@@ -125,9 +125,9 @@ public static IList Sublists(IList list, IList ranges, int offset)
/// <param name="list">List to be sorted.</param>
/// <returns name="list">Sorted list.</returns>
/// <search>sort,order</search>
public static IList Sort(IList list)
public static IList Sort(IEnumerable<object> list)
{
return list.Cast<object>().OrderBy(x => x, new ObjectComparer()).ToList();
return list.OrderBy(x => x, new ObjectComparer()).ToList();
}

/// <summary>
@@ -136,9 +136,9 @@ public static IList Sort(IList list)
/// <param name="list">List to take the minimum value from.</param>
/// <returns name="min">Minimum value from the list.</returns>
/// <search>least,smallest,find min</search>
public static object MinimumItem(IList list)
public static object MinimumItem(IEnumerable<object> list)
{
return list.Cast<object>().Min<object, object>(DoubleConverter);
return list.Min<object, object>(DoubleConverter);
}

/// <summary>
@@ -147,9 +147,9 @@ public static object MinimumItem(IList list)
/// <param name="list">List to take the maximum value from.</param>
/// <returns name="max">Maximum value from the list.</returns>
/// <search>greatest,largest,biggest,find max</search>
public static object MaximumItem(IList list)
public static object MaximumItem(IEnumerable<object> list)
{
return list.Cast<object>().Max<object, object>(DoubleConverter);
return list.Max<object, object>(DoubleConverter);
}

/// <summary>
34 changes: 34 additions & 0 deletions test/DynamoCoreTests/DSEvaluationTest.cs
Original file line number Diff line number Diff line change
@@ -84,6 +84,20 @@ public void AssertPreviewValue(string guid, object value)
AssertValue(previewVariable, value);
}

/// <summary>
/// Compares preview value of two nodes and asserts they are same.
/// </summary>
/// <param name="guid1">guid for first node</param>
/// <param name="guid2">guid for second node</param>
public void AssertSamePreviewValues(string guid1, string guid2)
{
string var1 = GetVarName(guid1);
var data1 = GetRuntimeMirror(var1).GetData();
string var2 = GetVarName(guid2);
var data2 = GetRuntimeMirror(var2).GetData();
AssertMirrorData(data1, data2);
}

public void SelectivelyAssertPreviewValues(string guid, Dictionary<int, object> selectedValue)
{
string previewVariable = GetVarName(guid);
@@ -156,6 +170,26 @@ public void AssertValue(MirrorData data, object value)
Assert.AreEqual(value, data.Data);
}

private void AssertMirrorData(MirrorData data1, MirrorData data2)
{
if (data1.IsNull)
Assert.True(data2.IsNull);
else if (data1.IsCollection)
{
Assert.True(data2.IsCollection);
List<MirrorData> elems1 = data1.GetElements();
List<MirrorData> elems2 = data2.GetElements();
Assert.AreEqual(elems1.Count, elems2.Count);
int i = 0;
foreach (var item in elems1)
{
AssertMirrorData(item, elems2[i++]);
}
}
else
Assert.AreEqual(data1.Data, data2.Data);
}

private void AssertCollection(MirrorData data, IEnumerable collection)
{
Assert.IsTrue(data.IsCollection);
23 changes: 23 additions & 0 deletions test/DynamoCoreTests/Nodes/ListTests.cs
Original file line number Diff line number Diff line change
@@ -2755,5 +2755,28 @@ public void TestListSample_Filtering()
#endregion
}
#endregion

#region Replication tests for MinimumItem, MaximumItem and Sort methods

[Test]
public void ReplicationForMinMaxSort()
{
var model = dynSettings.Controller.DynamoModel;

string openPath = Path.Combine(GetTestDirectory(), @"core\list\ReplicationForMinMaxSort.dyn");
RunModel(openPath);

// check all the nodes and connectors are loaded
Assert.AreEqual(12, model.CurrentWorkspace.Nodes.Count);
Assert.AreEqual(11, model.CurrentWorkspace.Connectors.Count);
AssertSamePreviewValues("77527c0b-b4f9-4bd1-809e-488f030fbd37", "dee87fc8-aa2a-4fb0-9924-ae04bf12fc8a");
AssertPreviewValue("77527c0b-b4f9-4bd1-809e-488f030fbd37", new double[] { 10, 10 }); //List.MaximumItem
AssertPreviewValue("dee87fc8-aa2a-4fb0-9924-ae04bf12fc8a", new double[] { 10, 10 }); //List.Map Max
AssertPreviewValue("e9a93b16-2211-4bbf-955e-30fe943df927", new double[] { 1, 5 });
AssertPreviewValue("3d8545d9-1e13-4609-bd42-0ac838282e9d", new double[] { 1, 5 });
//Assert for List.Sort and List.Map Sort nodes
AssertSamePreviewValues("683fb5ab-a753-4ad4-864f-f19c98243262", "fd0740af-543a-4876-9580-a4e5fc07f070");
}
#endregion
}
}
16 changes: 8 additions & 8 deletions test/Libraries/CoreNodesTests/ListTests.cs
Original file line number Diff line number Diff line change
@@ -45,15 +45,15 @@ public static void SortList()
{
var sorted = Enumerable.Range(1, 5).ToList();

Assert.AreEqual(sorted, List.Sort(List.Shuffle(sorted)));
Assert.AreEqual(sorted, List.Sort(List.Shuffle(sorted).Cast<object>()));
}

[Test]
public static void SortMixedList1()
{
Assert.AreEqual(
new ArrayList { 1, 2, 3.5, 4.002, 5 },
List.Sort(new ArrayList { 2, 3.5, 5, 4.002, 1 }));
new List<object> { 1, 2, 3.5, 4.002, 5 },
List.Sort(new List<object> { 2, 3.5, 5, 4.002, 1 }));
}

[Test]
@@ -62,7 +62,7 @@ public static void SortMixedList2()
var obj = new object();
Assert.AreEqual(
new ArrayList { 1, 2, 3.5, 4.002, 5, false, true, "aaa", "bb", obj },
List.Sort(new ArrayList { obj, 2, 3.5, "bb", 5, 4.002, true, 1, false, "aaa" }));
List.Sort(new List<object> { obj, 2, 3.5, "bb", 5, 4.002, true, 1, false, "aaa" }));
}

//[Test]
@@ -88,13 +88,13 @@ public static void SortMixedList2()
[Test]
public static void ListMinimumValue()
{
Assert.AreEqual(0, List.MinimumItem(new ArrayList { 8, 4, 0, 66, 10 }));
Assert.AreEqual(0, List.MinimumItem(new List<object> { 8, 4, 0, 66, 10 }));
}

[Test]
public static void ListMinimumValueMixed()
{
Assert.AreEqual(0, List.MinimumItem(new ArrayList { 8.5, 4, 0, 6.6, 10.2 }));
Assert.AreEqual(0, List.MinimumItem(new List<object> { 8.5, 4, 0, 6.6, 10.2 }));
}

//[Test]
@@ -106,13 +106,13 @@ public static void ListMinimumValueMixed()
[Test]
public static void ListMaximumValue()
{
Assert.AreEqual(66, List.MaximumItem(new ArrayList { 8, 4, 0, 66, 10 }));
Assert.AreEqual(66, List.MaximumItem(new List<object> { 8, 4, 0, 66, 10 }));
}

[Test]
public static void ListMaximumValueMixed()
{
Assert.AreEqual(66, List.MaximumItem(new ArrayList { 8.223, 4, 0.64, 66, 10.2 }));
Assert.AreEqual(66, List.MaximumItem(new List<object> { 8.223, 4, 0.64, 66, 10.2 }));
}

[Test]
30 changes: 30 additions & 0 deletions test/core/list/ReplicationForMinMaxSort.dyn
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Workspace Version="0.7.1.29160" X="-19.5077617187599" Y="-53.086899069684" zoom="0.784369328044827" Description="" Category="" Name="Home">
<Elements>
<Dynamo.Nodes.CodeBlockNodeModel type="Dynamo.Nodes.CodeBlockNodeModel" guid="5b8006f4-a612-4219-bb86-74a7b137da28" nickname="Code Block" x="36" y="95" isVisible="true" isUpstreamVisible="true" lacing="Disabled" CodeText="{1..10, 5..10};" ShouldFocus="false" />
<Dynamo.Nodes.DSFunction type="Dynamo.Nodes.DSFunction" guid="77527c0b-b4f9-4bd1-809e-488f030fbd37" nickname="List.MaximumItem" x="628.686623390686" y="37.1254519124768" isVisible="true" isUpstreamVisible="true" lacing="Shortest" assembly="DSCoreNodes.dll" function="DSCore.List.MaximumItem@var[]" />
<Dynamo.Nodes.DSFunction type="Dynamo.Nodes.DSFunction" guid="e9a93b16-2211-4bbf-955e-30fe943df927" nickname="List.MinimumItem" x="452.975994207449" y="160.400361529981" isVisible="true" isUpstreamVisible="true" lacing="Shortest" assembly="DSCoreNodes.dll" function="DSCore.List.MinimumItem@var[]" />
<Dynamo.Nodes.DSFunction type="Dynamo.Nodes.DSFunction" guid="1058a34f-1308-4b0b-95e5-0eb50f464494" nickname="List.Shuffle" x="86" y="209.5" isVisible="true" isUpstreamVisible="true" lacing="Shortest" assembly="DSCoreNodes.dll" function="DSCore.List.Shuffle@var[]..[]" />
<DSCore.Map type="DSCore.Map" guid="59ba08d7-962c-41f6-92e9-629334798b0f" nickname="List.Map" x="256" y="105.5" isVisible="true" isUpstreamVisible="true" lacing="Disabled" />
<Dynamo.Nodes.DSFunction type="Dynamo.Nodes.DSFunction" guid="683fb5ab-a753-4ad4-864f-f19c98243262" nickname="List.Sort" x="453.900361529982" y="263.153073004842" isVisible="true" isUpstreamVisible="true" lacing="Shortest" assembly="DSCoreNodes.dll" function="DSCore.List.Sort@var[]" />
<DSCore.Map type="DSCore.Map" guid="dee87fc8-aa2a-4fb0-9924-ae04bf12fc8a" nickname="List.Map Max" x="453.05394087858" y="398.729212026066" isVisible="true" isUpstreamVisible="true" lacing="Disabled" />
<Dynamo.Nodes.DSFunction type="Dynamo.Nodes.DSFunction" guid="bca55fc5-aa70-46f5-9e69-57bedd6b564c" nickname="MaximumItem" x="67.1693418540076" y="334.179392791057" isVisible="true" isUpstreamVisible="true" lacing="Shortest" assembly="DSCoreNodes.dll" function="DSCore.List.MaximumItem@var[]" />
<Dynamo.Nodes.DSFunction type="Dynamo.Nodes.DSFunction" guid="81d10729-8f92-4d9f-a916-66e1304d4746" nickname="MinimumItem" x="94.1693418540076" y="456.179392791057" isVisible="true" isUpstreamVisible="true" lacing="Shortest" assembly="DSCoreNodes.dll" function="DSCore.List.MinimumItem@var[]" />
<Dynamo.Nodes.DSFunction type="Dynamo.Nodes.DSFunction" guid="c5c15968-3bcc-4aff-aa21-c1df53d4aefe" nickname="Sort" x="86.1693418540076" y="597.179392791057" isVisible="true" isUpstreamVisible="true" lacing="Shortest" assembly="DSCoreNodes.dll" function="DSCore.List.Sort@var[]" />
<DSCore.Map type="DSCore.Map" guid="3d8545d9-1e13-4609-bd42-0ac838282e9d" nickname="List.Map Min" x="453.771800661447" y="517.295806453997" isVisible="true" isUpstreamVisible="true" lacing="Disabled" />
<DSCore.Map type="DSCore.Map" guid="fd0740af-543a-4876-9580-a4e5fc07f070" nickname="List.Map Sort" x="458.871439131466" y="635.86240088193" isVisible="true" isUpstreamVisible="true" lacing="Disabled" />
</Elements>
<Connectors>
<Dynamo.Models.ConnectorModel start="5b8006f4-a612-4219-bb86-74a7b137da28" start_index="0" end="59ba08d7-962c-41f6-92e9-629334798b0f" end_index="0" portType="0" />
<Dynamo.Models.ConnectorModel start="1058a34f-1308-4b0b-95e5-0eb50f464494" start_index="0" end="59ba08d7-962c-41f6-92e9-629334798b0f" end_index="1" portType="0" />
<Dynamo.Models.ConnectorModel start="59ba08d7-962c-41f6-92e9-629334798b0f" start_index="0" end="77527c0b-b4f9-4bd1-809e-488f030fbd37" end_index="0" portType="0" />
<Dynamo.Models.ConnectorModel start="59ba08d7-962c-41f6-92e9-629334798b0f" start_index="0" end="e9a93b16-2211-4bbf-955e-30fe943df927" end_index="0" portType="0" />
<Dynamo.Models.ConnectorModel start="59ba08d7-962c-41f6-92e9-629334798b0f" start_index="0" end="683fb5ab-a753-4ad4-864f-f19c98243262" end_index="0" portType="0" />
<Dynamo.Models.ConnectorModel start="59ba08d7-962c-41f6-92e9-629334798b0f" start_index="0" end="dee87fc8-aa2a-4fb0-9924-ae04bf12fc8a" end_index="0" portType="0" />
<Dynamo.Models.ConnectorModel start="59ba08d7-962c-41f6-92e9-629334798b0f" start_index="0" end="3d8545d9-1e13-4609-bd42-0ac838282e9d" end_index="0" portType="0" />
<Dynamo.Models.ConnectorModel start="59ba08d7-962c-41f6-92e9-629334798b0f" start_index="0" end="fd0740af-543a-4876-9580-a4e5fc07f070" end_index="0" portType="0" />
<Dynamo.Models.ConnectorModel start="bca55fc5-aa70-46f5-9e69-57bedd6b564c" start_index="0" end="dee87fc8-aa2a-4fb0-9924-ae04bf12fc8a" end_index="1" portType="0" />
<Dynamo.Models.ConnectorModel start="81d10729-8f92-4d9f-a916-66e1304d4746" start_index="0" end="3d8545d9-1e13-4609-bd42-0ac838282e9d" end_index="1" portType="0" />
<Dynamo.Models.ConnectorModel start="c5c15968-3bcc-4aff-aa21-c1df53d4aefe" start_index="0" end="fd0740af-543a-4876-9580-a4e5fc07f070" end_index="1" portType="0" />
</Connectors>
<Notes />
</Workspace>