Which assert method i can use to check whether an array of 1000 elements contains a particular element? - junit4

I have an integer array of 1000 elements. I have to check whether this array contains a particular element using an assert method?

You'll have to search / iterate through the array and set a boolean that you can then test with an assertTrue().
Or if it was an ArrayList(), and not a raw array, you could use:
assertTrue(arrayList.contains(XYZ));

Related

Flutter list.indexOf(element) always returns -1

i'm trying to get indexes of elements in a list using Flutter and Getx. The problem is that it is always returning -1 whatever element I pass into indexOf().
Here is my code:
var my_index = Get.find<ProductsController>()
.productsList
.indexOf(_cartList[index].product!);
print(my_index); ==> always retuning -1
Noting that _cartList and productsList have elements inside of them. Even when I pass an element manually it always returns -1.
Usually -1 is the standard message to tell that the element not exist in the list searched.
Maybe it is but the comparison can't be made (==) ? Are the types rigorously accurate? Do you use equatable or an equivalent (freezed, ...). If you are able to do it with a list of integer or string it is probably from there

Changing data types in an array in Redshift

I have the following string: WhatsappAutoResponse+landing+redirectFrom1206+redirectFrom1352
My goal is to extract the numbers after the substrings +redirectfrom and store that in an array, like this: [1206, 1352]
I managed to do the following:
The function split_to_array separates the string in parts. The numbers I'm looking for are the 2nd and 3rd elements in the array. I don't want the first element.
select split_to_array('WhatsappAutoResponse+landing+redirectFrom1206+redirectFrom1352', '+redirectFrom');
Result: ["WhatsappAutoResponse+landing","1206","1352"]
I get rid of the 1st element using the subarray function:
select subarray(split_to_array('WhatsappAutoResponse+landing+redirectFrom1206+redirectFrom1352', '+redirectFrom'),1,2);
Result: ["1206","1352"]
Almost there! However, I'm getting an array of strings, but I need an array of integers. I couldn't find a way to cast values inside an array, like in array::int
Is there any way to solve this?

Separate values from array

This string response i am getting from server.
2001,wooza,0420224346,J Wratt ,+61417697070,2013-55-1803-55-54.jpg,No<br />2002,wooza,0420224346,J Wratt ,+61417697070,2013-56-1803-56-17.jpg,No<br />2003,testing,9894698946,ggh hjj,9894598945,2013-11-1811-11-40.jpg,Yes<br />
I separate each record through "br" and stored it in a array.How do i access (2013-55-1803-55-54.jpg) value from array.
You can get through objectAtIndex method.
Alrenatively its better you keep the all the related data of your custom class and storing that in array.
Most of the times you will need more than one value during display. In that case, just get the object from array and show related info through object reference.
Take comma separated strings from an intended element in a different array and use NSPredicate to get the string containing .jpg in it.

PostgreSQL CASE: position within text array

I am currently successfully using a CASE expression to update an empty column based on attributes from other columns. For example
UPDATE table SET cat = CASE
WHEN term = '{"Boulder"}' then 'Boulder'
However, I need to do the same but on an text array and particularly when an element is in a specific position within that array.
For example if the data looks like
{"Boulder, Tree, Bush"}
WHEN position('Tree' in term) > 0 then 'Boulder'
But I receive an error message
function pg_catalog.position(character varying[], unknown) does not exist
I have used position in a function before so I am not sure why PostgreSQL does not like it in this situation.
Is there a way to using a CASE expression whilst determining the position of a text element within an array.
Apparently your term column is defined as an array, e.g. varchar[]. The position function only works with scalar values, not with arrays.
If you want to test if an element is contained in an array you need to use a different operator: #>
update foobar
set cat = 'Boulder'
where term #> '{"Boulder"}'
The expression '{"Boulder"}' creates an array with a single element. It's equivalent to array['Boulder'] (which I find more readable). So the above where condition updates all rows where the array term contains all elements of the array on the right hand side of the operator. In this case it's only a single element you are testing for.
More details about the array functions and operators can be found in the manual: http://www.postgresql.org/docs/current/static/functions-array.html
Edit after the requirements have changed
To find and update only those where boulder is in the first, second or third place, you can use this:
update foobar
set cat = 'Boulder'
where 'Boulder' in (term[1], term[2], term[3]);

libxml2 - get node(xmlNodePtr) content?

I parsed and have pointer xmlNodePtr upto category tag, But I want to get the value of the node(name) like TrailersFreeMovies , Trailers in an array.
<categories><category><name>TrailersFreeMovies</name><url>https://www.ex1.com/srs/index.php?cid=47</url></category><category><name>Trailers</name><url>https://www.ex1.com/srs/index.php?cid=45</url></category></categories>
guide me to parse this
XPath part of the api returns an array of nodes. See XPath examples.
Once you obtain the result of xmlXPathEvalExpression as xpathObj then the array is in xpathObj->nodesetval->nodeTab. nodesetval is a pointer to xmlNodeSet type.
xmlGetNodePath returns following values for the nodes of your sample xml matching the //name xpath expression:
/categories/category[1]/name
/categories/category[2]/name
So a specific answer to your question would be: apply xpath expression ("%s/name", xmlGetNodePath(categoryNode)) and process returned array of nodes. For each entry get the text with xmlNodeListGetString(doc, node->xmlChildrenNode, 1).