Skip to content

Commit

Permalink
DYN-2353 AnyTrue and AnyFalse Nodes (#11287)
Browse files Browse the repository at this point in the history
* Added AnyTrue and AnyFalse nodes

* Added unit tests for List.AnyTrue and List.AnyFalse

* Added tests for List.AnyTrue and List.AnyFalse

* Added icons for AnyTrue and AnyFalse

* Added AnyTrue and AnyFalse icons to libraryitems.json

* Fixed formatting
  • Loading branch information
StudioLE authored and QilongTang committed Dec 4, 2020
1 parent e74212a commit 6a7e4b1
Show file tree
Hide file tree
Showing 13 changed files with 918 additions and 0 deletions.
76 changes: 76 additions & 0 deletions src/Libraries/CoreNodes/DSCoreNodesImages.resx
Original file line number Diff line number Diff line change
Expand Up @@ -7586,4 +7586,80 @@
<data name="DSCore.Data.StringifyJSON.Small" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\DSCore.Data.StringifyJSON.Small.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="DSCore.List.AnyFalse.Large" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAYAAADimHc4AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAJcEhZcwAACxIAAAsSAdLdfvwAAAS7SURBVHhe7do9bhRBEAVgX8FX4AqcAMkJEiLzFXwFp4TE
ZL4AgQ9A4oh8L4CEEwIyHCAhESAN9VZbq9reNzPV262yZ6dG+oT1qmfprt7/2YthGNIzomGKQ8MUh4Yp
Dg1THBqmODRMcWiY4tAwxaFhikPDFIeGKQ4NUxwapjg0THFomOLQMMWhYdq7FfeiPJ4EaleCnedGwzR8
FN7jQbwS7HZm0XDFcI9+FLUHzjlpE2i4Umhgy4FHArvdSTRcMTyv2wPP/zfCjnkt0Gx2oGbHzqLhyqHp
eEqZe4HdiPIoN2sWDVfukmRM+WjBkRsQKDfgmbG3qteCjR1FwzQLL7blg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tdPQ
q9cklqjX2mno1WsSS9Rr7TT06jWJJeq1dhp69ZrEEvVaOw29ek1iiXqtnYZedhJrVvalBg292GTWqOxL
DRp6scmsUdmXGjRMcWiY4tAwxaFhikPDFIeGKQ4NUxwapjg0THFomOLQMMWhYYpDwxSHhikODVMcGqY4
NExxaJji0DDFoWGKQ8MUh4YpDg1THBqmODRMcWiY4tAwRRku/gPV4Gfymg3nWQAAAABJRU5ErkJggg==
</value>
</data>
<data name="DSCore.List.AnyFalse.Small" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAJcEhZcwAAA7AAAAOwASfED60AAAETSURBVFhH7ZMxCsIwFIZ7hV7BK3gCoYvg6lm6Ojq79Qpd
BZdO7t2cHFwdxRvE94cEmuR3MekTwcKHyefry095qYwxX4VKTajUhEpNqNSESk2oLEQrDIJ/RmEpBHXB
pjBbASGwroWbI6gLNjODL/CIHA+wOlxNSY6Xp7S1z14Izgo2HrwUuww6wexOd/wk/ycCFA6Az96/65kI
UDiA5eMA5826FnrBCPYaOTc4NwoL54I6wU//mBMAzVvXuHEOB/Vu3QkIk9QJ+QE808bRusGe1U35Bygd
ADOA+401ZsDOQ1w3pVQAfwswcJh+OHsLWN2U7AC5/F6AOYjPAYnQhkpNqNSESk2o1IRKTajUhEpNqNTD
VC9ucKppb8F6AgAAAABJRU5ErkJggg==
</value>
</data>
<data name="DSCore.List.AnyTrue.Large" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAYAAADimHc4AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAJcEhZcwAACxIAAAsSAdLdfvwAAAUzSURBVHhe7Zs9bhxHEIV1BV5BV9AJBCgxYDjTFXgFp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z5OAbb8nhVji5O7gxRdnCDc5GgP397WA58qAHGCQFJbl6DV7SB8
/q8lSG6TFU7uDlJ0cYJAUtGxvJMofQjtF7/VUQgfpwCTD1g6Cbfb1as8CVsjMXzor+wt8HEKsHr9QWhr
/OyXa53cHaTo4gTBpJoE5y7ENu3F6RP+vS2AzRrZtDV+szOlx8ndQYouThBIqt1nyytS6o3PaifAZ7UA
BHbnVkSco67zVgRBcrEM8abbow7G9/Zm3OpVMIGfW4B29j2ZBdQa+6Z3+93c15CiixsEkuNyEJ3MUXle
ivh5+U79SXHmgJ9VAAKf+H0yFYF/N/riBkHh5r6GFF22BIEkeW8mitBDfctTsS0F4Axri9BDm/tvSRNb
cl9Cii5bg0CinAlcjqIQXH/53T75EfjbBSDwYxF4TFsIbo/tbWfP1tznkKLLqCD2yKjcpegyKog9Mip3
KbqMCmKPjMpdii6jgtgjo3KXosuoIPbIqNyl6DIqiD0yKncpurRBHJm+X7YgRRcVzBHp+2ULUnRRwRyR
vl+2IMUiDykWeUixyEOKRR5SLPKQYpGHFIs8pFjkIcUiDykWeUixyEOKRR5SLPKQYpGHFIs8pFjkIcUi
DykWeUixyEOKRR5SLPKQYpGHFIs8pFjkIcUiDykWeUixyOL04j/w1CJEODKlZAAAAABJRU5ErkJggg==
</value>
</data>
<data name="DSCore.List.AnyTrue.Small" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAJcEhZcwAAA7AAAAOwASfED60AAAEaSURBVFhH7ZMxCsIwFIZ7hV7BK3gCoYvg6lm6Ojq79Qpd
BZdO7t2cHFwdxRvE/y8JNM3L0qRPBAsfJl+efT9NUhhjvoooNRGlJqLURJSaiFITUWaiBh1wTw/WwKvz
JpnZA4bguAQPi1fnTRaGX+A1cXKAzelucnK+vfHa4TkCr5c3cfBPU5dAA8zh8uRPsB4IkjkAP3sbe2cg
SOYAA7MDXHfbEnTAgB6srGutG66WdV4dvDv9fUoANmrtuAFswhA1YLMqVodxlgDjJhXnkbVoHfkHSAnA
veVd5ph7O+yznY+bRutISgAeOJ5qNnOn263RuVsQrSOzA+Ti9wIswbQPCYQ2otRElJqIUhNRaiJKTUSp
iSg1EaUepvgAv22e4jr/Ak4AAAAASUVORK5CYII=
</value>
</data>
</root>
50 changes: 50 additions & 0 deletions src/Libraries/CoreNodes/List.cs
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,56 @@ public static bool AllFalse(IList list)
return result;
}

/// <summary>
/// Determines if any item in the given list is a boolean and has a true value.
/// </summary>
/// <param name="list">List to be checked on whether any item is true.</param>
/// <returns name="bool">Whether any item is true.</returns>
/// <search>test,any,true,istrue</search>
[IsVisibleInDynamoLibrary(true)]
public static bool AnyTrue(IList list)
{
bool result = false;
foreach (object obj in list)
{
if (obj is IList subList)
{
result = AnyTrue(subList);
}
else if (obj is bool boolObj && boolObj)
{
result = true;
}
if (result) break;
}
return result;
}

/// <summary>
/// Determines if any item in the given list is a boolean and has a false value.
/// </summary>
/// <param name="list">List to be checked on whether any item is false.</param>
/// <returns name="bool">Whether any item is false.</returns>
/// <search>test,any,false,isfalse</search>
[IsVisibleInDynamoLibrary(true)]
public static bool AnyFalse(IList list)
{
bool result = false;
foreach (object obj in list)
{
if (obj is IList subList)
{
result = AnyFalse(subList);
}
else if(obj is bool boolObj && !boolObj)
{
result = true;
}
if (result) break;
}
return result;
}

/// <summary>
/// Returns the number of items stored in the given list.
/// </summary>
Expand Down
6 changes: 6 additions & 0 deletions src/LibraryViewExtension/web/library/layoutSpecs.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
{
"path": "DSCoreNodes.DSCore.List.AllTrue"
},
{
"path": "DSCoreNodes.DSCore.List.AnyFalse"
},
{
"path": "DSCoreNodes.DSCore.List.AnyTrue"
},
{
"path": "DSCoreNodes.DSCore.List.SetIntersection"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
{
"path": "DSCoreNodes.DSCore.List.AllTrue"
},
{
"path": "DSCoreNodes.DSCore.List.AnyFalse"
},
{
"path": "DSCoreNodes.DSCore.List.AnyTrue"
},
{
"path": "DSCoreNodes.DSCore.List.SetIntersection"
},
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions test/DynamoCoreTests/Nodes/ListTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2102,6 +2102,46 @@ public void TrueForAll_SimpleTest()

#endregion

#region Test AnyTrue

[Test]
public void AnyTrue_SimpleTest()
{
string openPath = Path.Combine(TestDirectory, @"core\list\AnyTrue_SimpleTest.dyn");
RunModel(openPath);

// check all the nodes and connectors are loaded
Assert.AreEqual(6, CurrentDynamoModel.CurrentWorkspace.Nodes.Count());
Assert.AreEqual(5, CurrentDynamoModel.CurrentWorkspace.Connectors.Count());
AssertPreviewValue("eb32799e0a26444081185a072e5c1c44", true);
AssertPreviewValue("dfc0430372ea40cb9b57c34551da69a6", false);
AssertPreviewValue("3391f6711c8d482eab224c881d512f73", true);
AssertPreviewValue("cfdc4008ae544881b80b0d2b807770e7", true);
AssertPreviewValue("2f20ee45e15149859b9e2d4548673079", true);
}

#endregion

#region Test AnyFalse

[Test]
public void AnyFalse_SimpleTest()
{
string openPath = Path.Combine(TestDirectory, @"core\list\AnyFalse_SimpleTest.dyn");
RunModel(openPath);

// check all the nodes and connectors are loaded
Assert.AreEqual(6, CurrentDynamoModel.CurrentWorkspace.Nodes.Count());
Assert.AreEqual(5, CurrentDynamoModel.CurrentWorkspace.Connectors.Count());
AssertPreviewValue("d18e50739b14411fac8b3115698ec655", false);
AssertPreviewValue("23e3c4f0a0ca429fab26a54515d98e7a", true);
AssertPreviewValue("e02a84cc887a43b8b8fa31db4553ae84", false);
AssertPreviewValue("7830af415719453a98b40538ced2144b", true);
AssertPreviewValue("a4478dae1ecb4a879456f590c7717a8d", true);
}

#endregion

#region Test Join List -PartiallyDone

[Test]
Expand Down
40 changes: 40 additions & 0 deletions test/Libraries/CoreNodesTests/ListTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,46 @@ public static void ListCount()
Assert.AreEqual(3, List.Count(new ArrayList { 0, 1, 2 }));
}

[Test]
[Category("UnitTests")]
public static void ListAnyTrue()
{
var oneTrue = new List<object> {true};
var oneFalse = new List<object> {false};
var subListsAllTrue = new List<object> {true, true, new List<object> {true, new List<object> {true, new List<object> {true, true, new List<object> {true}, true}}}, true};
var subListsAllFalse = new List<object> {false, false, new List<object> {false, new List<object> {false, new List<object> {false, false, new List<object> {false}, false}}}, false};
var subListsOneTrue = new List<object> {false, false, new List<object> {false, new List<object> {false, new List<object> {false, false, new List<object> {false}, false}}}, true};
var subListsOneFalse = new List<object> {true, true, new List<object> {true, new List<object> {true, new List<object> {true, false, new List<object> {true}, true}}}, true};

Assert.IsFalse(List.AnyTrue(List.Empty));
Assert.IsTrue(List.AnyTrue(oneTrue));
Assert.IsFalse(List.AnyTrue(oneFalse));
Assert.IsTrue(List.AnyTrue(subListsAllTrue));
Assert.IsFalse(List.AnyTrue(subListsAllFalse));
Assert.IsTrue(List.AnyTrue(subListsOneTrue));
Assert.IsTrue(List.AnyTrue(subListsOneFalse));
}

[Test]
[Category("UnitTests")]
public static void ListAnyFalse()
{
var oneTrue = new List<object> {true};
var oneFalse = new List<object> {false};
var subListsAllTrue = new List<object> {true, true, new List<object> {true, new List<object> {true, new List<object> {true, true, new List<object> {true}, true}}}, true};
var subListsAllFalse = new List<object> {false, false, new List<object> {false, new List<object> {false, new List<object> {false, false, new List<object> {false}, false}}}, false};
var subListsOneTrue = new List<object> {false, false, new List<object> {false, new List<object> {false, new List<object> {false, false, new List<object> {false}, false}}}, true};
var subListsOneFalse = new List<object> {true, true, new List<object> {true, new List<object> {true, new List<object> {true, false, new List<object> {true}, true}}}, true};

Assert.IsFalse(List.AnyFalse(List.Empty));
Assert.IsFalse(List.AnyFalse(oneTrue));
Assert.IsTrue(List.AnyFalse(oneFalse));
Assert.IsFalse(List.AnyFalse(subListsAllTrue));
Assert.IsTrue(List.AnyFalse(subListsAllFalse));
Assert.IsTrue(List.AnyFalse(subListsOneTrue));
Assert.IsTrue(List.AnyFalse(subListsOneFalse));
}

[Test]
[Category("UnitTests")]
public static void JoinLists()
Expand Down
16 changes: 16 additions & 0 deletions test/ViewExtensionLibraryTests/resources/libraryItems.json
Original file line number Diff line number Diff line change
Expand Up @@ -4632,6 +4632,22 @@
"itemType": "action",
"keywords": "test, all, false"
},
{
"fullyQualifiedName": "DSCore.List.AnyTrue",
"iconUrl": "http://localhost/icons/DSCore.List.AnyTrue.Small?path=DSCoreNodes.dll",
"contextData": "DSCore.List.AnyTrue@var[]..[]",
"parameters": null,
"itemType": "action",
"keywords": "test, any, true"
},
{
"fullyQualifiedName": "DSCore.List.AnyFalse",
"iconUrl": "http://localhost/icons/DSCore.List.AnyFalse.Small?path=DSCoreNodes.dll",
"contextData": "DSCore.List.AnyFalse@var[]..[]",
"parameters": null,
"itemType": "action",
"keywords": "test, any, false"
},
{
"fullyQualifiedName": "DSCore.List.Count",
"iconUrl": "http://localhost/icons/DSCore.List.Count.Small?path=DSCoreNodes.dll",
Expand Down
Loading

0 comments on commit 6a7e4b1

Please sign in to comment.