blob: 0b227c07a69b251ae3dc675ca60cf9cd42d40472 [file] [log] [blame]
Leah McNuttc9c9cde2016-10-07 16:53:52 +00001*** Settings ***
2Documentation This module contains keywords for list manipulation.
3Library Collections
4
5*** Keywords ***
6Intersect Lists
7 [Documentation] Intersects the two lists passed in. Returns a list of
8 ... values common to both lists with no duplicates.
9 [Arguments] ${list1} ${list2}
10
11 # list1 The first list to intersect.
12 # list2 The second list to intersect.
13
14 ${length1}= Get Length ${list1}
15 ${length2}= Get Length ${list2}
16
17 @{intersected_list} Create List
18
19 @{larger_list}= Set Variable If ${length1} >= ${length2} ${list1}
20 ... ${length1} < ${length2} ${list2}
21 @{smaller_list}= Set Variable If ${length1} >= ${length2} ${list2}
22 ... ${length1} < ${length2} ${list1}
23
24 :FOR ${element} IN @{larger_list}
25 \ ${rc}= Run Keyword and Return Status List Should Contain Value ${smaller_list}
26 ... ${element}
27 \ Run Keyword If '${rc}' == 'True' Append to List ${intersected_list}
28 ... ${element}
29
30 @{intersected_list}= Remove Duplicates ${intersected_list}
31
Gunnar Millsc9ea9362016-12-13 16:21:13 -060032 [Return] @{intersected_list}
Rahul Maheshwaria93b8c02017-05-12 05:23:00 -050033
34
35Subtract Lists
36 [Documentation] Subtract list 2 from list 1 and return the result.
37 # Return list contain items from the list 1 which are not present
38 # in the list 2.
39 [Arguments] ${list1} ${list2}
40 # Description of argument(s):
41 # list1 The base list which is to be subtracted from.
42 # list2 The list which is to be subtracted from list1.
43
44 ${diff_list}= Create List
45 :FOR ${item} IN @{list1}
46 \ ${status}= Run Keyword And Return Status
47 ... Should Contain ${list2} ${item}
48 \ Run Keyword If '${status}' == '${False}'
49 ... Append To List ${diff_list} ${item}
50
51 [Return] ${diff_list}