Hey guys,
is there a way to compare two arrays with each other?
I'm trying this but it crashes my DOORS application:
int array_size(Array a){
int size_ar = 0;
while( (get(a, size_ar, 0)!= null ) )
size_ar++;
return size_ar;
}
bool isequal = true
for(lenText=0; lenText < array_size(pairingsText); lenText++)
{
for(lenID=0; lenID < array_size(pairingsID); lenID++)
{
if (get(pairingsText, lenText, 0) != get(pairingsID, lenID, 0))
isequal = false
}
}
Any help would be much appreciated :)
Thanks, Yannick
YannickC - Wed Oct 19 08:31:20 EDT 2011 |
|
Re: Comparing Arrays in DXL SystemAdmin - Wed Oct 19 09:05:33 EDT 2011
Did not try your code but let's start off with this nugget of wisdom from the DXL Help
This section describes a dynamically sized two-dimensional array data type. An example of its use is in the Rational DOORS ASCII output generator in the tools library. As with skip lists, you must retrieve data into variables of the same data type as they were put into the array, or program failure may occur.
...and further on "get"
To ensure that this works unambiguously in the way intended, you should use a cast prefix to the get command
Array a = create(10,10)
string str
int i
put(a, "a string", 3, 4)
put(a, 1000, 3, 5)
str = (string get(a,3,4)) // cast get as string
print str "\n" // prints "a string"
i = (int get(a, 3, 5)) // cast get as int
print i // prints "1000"
--
Pekka Mäkinen - http://www.softqa.eu/
|
|
Re: Comparing Arrays in DXL YannickC - Wed Oct 19 09:42:31 EDT 2011 SystemAdmin - Wed Oct 19 09:05:33 EDT 2011
Did not try your code but let's start off with this nugget of wisdom from the DXL Help
This section describes a dynamically sized two-dimensional array data type. An example of its use is in the Rational DOORS ASCII output generator in the tools library. As with skip lists, you must retrieve data into variables of the same data type as they were put into the array, or program failure may occur.
...and further on "get"
To ensure that this works unambiguously in the way intended, you should use a cast prefix to the get command
Array a = create(10,10)
string str
int i
put(a, "a string", 3, 4)
put(a, 1000, 3, 5)
str = (string get(a,3,4)) // cast get as string
print str "\n" // prints "a string"
i = (int get(a, 3, 5)) // cast get as int
print i // prints "1000"
--
Pekka Mäkinen - http://www.softqa.eu/
Hey, thanks for your answer. My main problem, though, is, I think, to get the size of my arrays.
They are dynamic, but after I have put my data in there, they will stay the same size througout the execution of my dxl program. So in my opinion it should be possible to get the size and loop through both arrays with two for loops to do the compare.
|
|
Re: Comparing Arrays in DXL llandale - Thu Oct 20 12:12:12 EDT 2011
I'm going to have to think about the 'getsize' function; but you will likely want a "GetSize_XCoord" and a "GetSize_YCoord" functions.
If you only care about comparing the values when YCoord = 0, it would look like this:
Size1 = GetSize_XCoord(a1)
Size2 = GetSize_XCoord(a2)
if (Size1 != Size2) IsSame = false
else
{ IsSame = true
for (i=0; i<Size1; i++)
{ if ((string get(a1, i, 0)) != (string get(a2, 1, 0)))
{ IsSame = false
break // stop looking
}
}
}
Yes, always caste the get function (string get(...)).
It appears you can indeed retrieve value 2,2 from the Array even when its never been set; a fact that disturbs me considerably. I think. But it does seem to retrieve a "null" value, so if you are disciplined in making sure all your Array cells have something in it then checking for null should work. But, it doesn't seem realistic to me to make sure all the valid cells are non-null, certainly storing strings sometimes the value will be null.
I'm thus inclined to believe you cannot realistically get the size of an unknown Array, and will need to keep track of exactly how many rows and columns it has. Hopefully someone will prove me wrong.
I tried a little to store the number of rows and columns of the array inside the array itself, perhaps coordinates (-1, -1) but its not working.
|
|
Re: Comparing Arrays in DXL Mathias Mamsch - Thu Oct 20 16:23:12 EDT 2011 YannickC - Wed Oct 19 09:42:31 EDT 2011
Hey, thanks for your answer. My main problem, though, is, I think, to get the size of my arrays.
They are dynamic, but after I have put my data in there, they will stay the same size througout the execution of my dxl program. So in my opinion it should be possible to get the size and loop through both arrays with two for loops to do the compare.
You could store the size in array position (0,0) and store the items of the array from index 1. Regards, Mathias
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
|
Re: Comparing Arrays in DXL SystemAdmin - Mon Oct 24 17:19:18 EDT 2011
This may be a problem...
while( (get(a, size_ar, 0)!= null ) )
Several years ago a coworker attended some sort of class/seminar put on by telelogic. In their notes from this, they have written never to use null in this way. Rather than saying something like "if (x == null)" you would want to say "if (null x)". I don't know the reasoning for this or if it is even a problem anymore. Perhaps the smarter folks can weigh in on this...
Anyway, you may want to try this instead
{code}
while (!null (string get(a, size_ar, 0)))
|
|
Re: Comparing Arrays in DXL SystemAdmin - Mon Oct 24 17:21:57 EDT 2011 SystemAdmin - Mon Oct 24 17:19:18 EDT 2011
This may be a problem...
while( (get(a, size_ar, 0)!= null ) )
Several years ago a coworker attended some sort of class/seminar put on by telelogic. In their notes from this, they have written never to use null in this way. Rather than saying something like "if (x == null)" you would want to say "if (null x)". I don't know the reasoning for this or if it is even a problem anymore. Perhaps the smarter folks can weigh in on this...
Anyway, you may want to try this instead
{code}
while (!null (string get(a, size_ar, 0)))
the end of that last post should be
while (!null (string get(a, size_ar, 0))) // cast depends on array
-Adam
|
|
Re: Comparing Arrays in DXL SystemAdmin - Mon Oct 24 17:22:03 EDT 2011 SystemAdmin - Mon Oct 24 17:19:18 EDT 2011
This may be a problem...
while( (get(a, size_ar, 0)!= null ) )
Several years ago a coworker attended some sort of class/seminar put on by telelogic. In their notes from this, they have written never to use null in this way. Rather than saying something like "if (x == null)" you would want to say "if (null x)". I don't know the reasoning for this or if it is even a problem anymore. Perhaps the smarter folks can weigh in on this...
Anyway, you may want to try this instead
{code}
while (!null (string get(a, size_ar, 0)))
the end of that last post should be
while (!null (string get(a, size_ar, 0))) // cast depends on array
-Adam
|
|
Re: Comparing Arrays in DXL llandale - Mon Oct 24 17:45:06 EDT 2011 SystemAdmin - Mon Oct 24 17:19:18 EDT 2011
This may be a problem...
while( (get(a, size_ar, 0)!= null ) )
Several years ago a coworker attended some sort of class/seminar put on by telelogic. In their notes from this, they have written never to use null in this way. Rather than saying something like "if (x == null)" you would want to say "if (null x)". I don't know the reasoning for this or if it is even a problem anymore. Perhaps the smarter folks can weigh in on this...
Anyway, you may want to try this instead
{code}
while (!null (string get(a, size_ar, 0)))
Mathias has explained it but I don't quite get it, something to do with casting which "null()" function is being called.
I've always used "if (null x)" and never "if (x == null)", but I just fell into that since it seems clearer to me and not for the valid reason's in your post. To me, the concept of "null" ("has no value") is fundamentally different from "has a trivial value" and I think code should visually reflect that difference. You should say either "I didn't go to the stream" or "I went to the stream and picked up no rocks" instead of "I did not pick up rocks at the stream" which can mean either.
And, there are times where a null string is different than a string of length zero. I don't recall the exact cases, but these pairs are only 95% of the time the same thing:
if (s == null); if (s == "")
s = null; s = ""
I imagine there are times when a null integer is not the same thing as an integer of value zero, although most of the time they are the same.
|
|
Re: Comparing Arrays in DXL SystemAdmin - Wed Oct 26 15:53:27 EDT 2011 llandale - Mon Oct 24 17:45:06 EDT 2011
Mathias has explained it but I don't quite get it, something to do with casting which "null()" function is being called.
I've always used "if (null x)" and never "if (x == null)", but I just fell into that since it seems clearer to me and not for the valid reason's in your post. To me, the concept of "null" ("has no value") is fundamentally different from "has a trivial value" and I think code should visually reflect that difference. You should say either "I didn't go to the stream" or "I went to the stream and picked up no rocks" instead of "I did not pick up rocks at the stream" which can mean either.
And, there are times where a null string is different than a string of length zero. I don't recall the exact cases, but these pairs are only 95% of the time the same thing:
if (s == null); if (s == "")
s = null; s = ""
I imagine there are times when a null integer is not the same thing as an integer of value zero, although most of the time they are the same.
Louie -- See new thread
Link:https://www.ibm.com/developerworks/forums/thread.jspa?threadID=394527
|
|