I am trying to compare between two tables and test the results using Gherkin but I don't know how to make it declare two lists in the #when section instead of one, like how it is shown below:
#When("^the integer table :$")
public void the_integer_table_(List<Integer> comp1, List<Integer> comp2) {
for(int i = 0; i < comp1.size(); i++) {
compare[i] = comp1.get(i);
}
for(int i = 0; i < comp2.size(); i++) {
compare2[i] = comp1.get(i);
}
comparer.comparer_tableau( compare, compare2);
}
Here is my .feature file:
Scenario: Compare the elements of two tables and return a boolean table as a result
Given I am starting a comparision operation
When these two integer table are entered :
|1|2|3|4|5|
|0|2|5|4|5|
Then I should see the correct answer is:
|false|true|false|true|true|
Here is what I get when I run it:
#When("^these two integer table two are entered :$") public void these_two_integer_table_two_are_entered_(DataTable arg1) { }
P.S: I did try and look for solutions but didn't find any.
You can change the step definition as given below and get the values of each row then compare it.
#When("^these two integer table are entered :$")
public void these_two_integer_table_are_entered(DataTable arg1) throws Throwable {
List<DataTableRow> lstRows=arg1.getGherkinRows();
Integer[] compare=new Integer[lstRows.get(0).getCells().size()];
System.out.println(compare.length);
Integer[] compare2=new Integer[lstRows.get(1).getCells().size()];
System.out.println(compare2.length);
//Get the first row values
for(int i = 0; i < compare.length; i++) {
compare[i] = Integer.valueOf(lstRows.get(0).getCells().get(i));
System.out.println(compare[i]);
}
//Get the second row values
for(int i = 0; i < compare2.length; i++) {
compare2[i] = Integer.valueOf(lstRows.get(1).getCells().get(i));
System.out.println(compare2[i]);
}
comparer.comparer_tableau( compare, compare2);
}
AFAIK, You can have only one table per step. But can get the each row values inside your definition.
Cucumber will interpret your When step to use one DataTable
When these two integer table are entered :
|1|2|3|4|5|
|0|2|5|4|5|
Instead of trying to enter two tables in one step, try entering them in two separate steps (one table per step) like this:
When the following integer table is entered :
|1|2|3|4|5|
And the following integer table is entered :
|0|2|5|4|5|
I would use a scenario outline like this and handle the log to retrieve values for each column in step definition. (split value string by comma and use values accordingly).
Scenario Outline : Compare the elements of two tables and return a boolean table as a result
Given I am starting a comparision operation
When integer '<table1>' values are entered
When integer '<table2>' values are entered
Then I should see the correct '<answer>'
Examples:
| table1 | table2 | answer |
| 1,2,3,4,5 | 0,2,5,4,5 | false,true,false,true,true |
Related
I'm learning Processing for the first time and I've been tasked to deal with data but it's been terribly confusing for me.
For every line of a CSV file (apart from the header), I want to compare two specific columns of each. i.e. ListA vs ListB
For example, with the data below:
ListA,ListB
Male,Yes
Male,No
Female,Yes
Male,Yes
And for example, I want to check for all instances that a value in ListA is "Male" AND that the corresponding value in ListB is "Yes". In this scenario, I should get the value "2" for the two rows this is true.
How would I do that?
For now, I have a 2D String array of the data in the CSV file. From that I managed to assign specific columns as ListA and ListB. I tried using sort but it would only sort one list and not both at the same time.
Current relevant code:
for (int i=1; i<lines.length; i++) {
listA[i-1] = csv[i][int(whichA)];
listB[i-1] = csv[i][int(whichB)];
}
lA = Arrays.asList(listA);
lB = Arrays.asList(listB);
Not sure if this code really helps makes things clearer though. :/
Any help would be appreciated. Thank you.
So something like this should do what you need it to. Pseudocode:
int numRows = 0;
for (int i = 0; i < length; ++i) {
if (array1[i] equals "Male" AND array2[i] equals "Yes") {
++numRows;
//add to new collection here if you need the data
}
}
so in my code i have partition the data in three parts but in output i m only getting the ouput that is retuned by 0th partition even if i set no of reducers to 3
my code
public static class customPartitioner extends Partitioner<Text,Text>{
public int getPartition(Text key, Text value, int numReduceTasks){
String country = value.toString();
if(numReduceTasks==0)
return 0;
if(key.equals(new Text("key1")) && !value.equals(new Text("valuemy")))
return 1%numReduceTasks;
if(value.equals(new Text("valueother")) && key.equals(new Text("key1")) )
return 0;
else
return 2%numReduceTasks;
}
}
and set no of reducers as
job.setNumReduceTasks(3);
it is giving me the output of only 0th partition i.e., return 0
i was doing a very silly mistake ....the partitioning was working fine in my code...but i thought the output is only in part-r-00000 file i thought that it is just to reduce load that it divides the file..but in output it shows the file by combining but i was wrong the different partitions have different outputs.
I need to get arrayList of postalCodes by Reagion IDs, but my region id's are not in provided sequence and zip codes must be associates with mentioned region id. (This data is an small example, I have csv file in with thousands of zip Code)
Please help me out to write a correct logic for it in Java.
Zip Codes V/s Region Ids = {"71854 , 612" ; "71865, 612"; "88008, 765"; "88021, 765" ; "88252 , 612"}
You can do this of two ways.
first declare a structure that contain the two values required and then fill an array with the values, as show in the example.
struct Data{
int zip_code, region_id;
Data() {}
Data(int z, int r) {
zip_code = z;
region_id = r;
}
};
define MAX 100
Data my_list[MAXN];
second declare declare two parallel arrays and fill these with the data requiered
define MAX 100
int zip_code[MAX] = {71854, 71865, 88008, 88021, 88252};
int region_id[MAX] = {612, 612, 765, 765, 612};
I have a program with multiple int variables where individual counts are added to the specific variable each time a set fail condition is encountered. I want the user to be able to track how many failures of each category they have encountered by a button click. I want to display the range on a datagridview in order from highest value integer down to lowest. I also need to display in the adjacent column the name of the test step that relates to the value. My plan was to use Array.sort to order the integers but i then lose track of their names so cant assign the adjacent string column. I tried using a hashtable but if i use the string as a key it sorts alphabetically not numerically and if i use the integer as a key i get duplicate entries which dont get added to the hash table. here is some of the examples i tried but they have the aforementioned problems. essentially i want to end with two arrays where the order matches the naming and value convention. FYI the variables were declared before this section of code, variables ending in x are the string name for the (non x) value of the integer.
Hashtable sorter = new Hashtable();
sorter[download] = downloadx;
sorter[power] = powerx;
sorter[phase] = phasex;
sorter[eeprom] = eepromx;
sorter[upulse] = upulsex;
sorter[vpulse] = vpulsex;
sorter[wpulse] = wpulsex;
sorter[volts] = voltsx;
sorter[current] = currentx;
sorter[ad] = adx;
sorter[comms] = commsx;
sorter[ntc] = ntcx;
sorter[prt] = prtx;
string list = "";
string[] names = new string[13];
foreach (DictionaryEntry child in sorter)
{
list += child.Value.ToString() + "z";
}
int[] ordered = new int[] { download, power, phase, eeprom, upulse, vpulse, wpulse, volts, current, ad, comms, ntc, prt };
Array.Sort(ordered);
Array.Reverse(ordered);
for (int i = 0; i < sorter.Count; i++)
{
int pos = list.IndexOf("z");
names[i] = list.Substring(0, pos);
list = list.Substring(pos + 1);
}
First question here so hope its not too longwinded.
Thanks
Use a Dictionary. And you can order it by the value : myDico.OrderBy(x => x.Value).Reverse(), the sort will be numerical descending. You just have to enumerate the result.
I hope I understand your need. Otherwise ignore me.
You want to be using a
Dictionary <string, int>
to store your numbers.I'm not clear on how you're displaying results at the end - do you have a grid or a list control?
You ask about usings. Which ones do you already have?
EDIT for .NET 2.0
There might be a more elegant solution, but you could implement the logic by putting your rows in a DataTable. Then you can make a DataView of that table and sort by whichever column you like, ascending or descending.
See http://msdn.microsoft.com/en-us/library/system.data.dataview(v=VS.80).aspx for example.
EDIT for .NET 3.5 and higher
As far as sorting a Dictionary by its values:
var sortedEntries = myDictionary.OrderBy(pair => pair.Value);
If you need the results to be a Dictionary, you can call .ToDictionary() on that. For reverse order, use .OrderByDescending(pair => pair.Value).
I have a table called UserManagement that contains information about the user.This table gets updated whenever new user is created. If i create two users then i need check whether two users are actually created or not. Table contains ID,UserName,FirstName,LastName,Bdate..ctc. Here ID will be generated automatically.
I am running Selenium-TestNG script.Using Selenium,how can i get the UserName of the two users which i have created? Should i have to iterate through table? If so how to iterate through the table?
Use ISelenium.GetTable(string) to get the contents of the table cells you want. For example,
selenium.GetTable("UserManagement.0.1");
will return the contents of the table's first row and second column. You could then assert that the correct username or usernames appear in the table.
Get the count of rows using Selenium.getxpathcount(\#id = fjsfj\td\tr") in a variable rowcount
Give the columncount in a variable
Ex:
int colcount = 5;
Give the req i.e New user
String user1 = "ABC"
for(i = 0;i <=rowcount;i++)
{
for(j=0;j<=colcount;j++)
{
if (user1==selenium.gettable("//#[id=dldl/tbody" +i "td"+j))
{
system.out.println(user1 + "Inserted");
break;
}
break;
}
}
Get the number of rows using:
int noOfRowsInTable = selenium.getXpathCount("//table[#id='TableId']//tr");
If the UserName you want to get is at fixed position, let's say at 2nd position, then for each row iterate as given below:
selenium.getText("xpath=//table[#id='TableId']//tr//td[1]");
Note: we can find the number of columns in that table using same procedure
int noOfColumnsInTable = selenium.getXpathCount("//table[#id='TableId']//tr//td");
Generically, something like this?
table = #browser.table(:id,'tableID')
table.rows.each do |row|
# perform row operations here
row.cells.each do |cell|
# do cell operations here
end
end