I'm trying to write some code in java robitum which will test and check that my sort button is working correctly.
I do this is by activating the sort button, then iterate through the sorted array to make checks on the current value against the next value. The problem is that I'm comparing strings such as "Tenancy 8 & Tenancy 12", where it is then telling me that Tenancy 8 > Tenancy 12.
I know this is happening because software sorts based on ASCII, but I was wondering how I could get around this issue. My code is as follows:
solo.clickLongOnView(tenancy_sort);
for(int i = 0; i<9; i++)
{
TextView tenancy_current = (TextView)
solo.getView(R.id.device_selector_row_tenancy_text,i);
TextView tenancy_next = (TextView)
solo.getView(R.id.device_selector_row_tenancy_text,i+1);
String tenancy_current_text = tenancy_current.getText().toString();
String tenancy_next_text = tenancy_next.getText().toString();
int result = tenancy_current_text.compareTo(tenancy_next_text);
assertTrue(result <= 0);
}
They way I sort the array in the actual application is by using a custom sort class which contains an algorithm for natural sorting. Thanks in advance for any help, Will.
Aucun commentaire:
Enregistrer un commentaire