If controler logic - jmeter

I have a requirement where I need to validate cases that gets matches with the output JSON: I wrote code inside if controller:(so if all the cases matches, we will say pass and print the value) And its actually working fine..
("${C_etrTimestamp}"=="${ETRTIMESTAMP}")&&("${C_EventName}"=="${EVENTNAME}")&&("${C_EventType}"=="${EVENTTYPE}")&&("${C_AreaName}"=="${AREANAME}")&&("${C_AreaType}"=="${AREATYPE}")&&("${C_additionalInfo}"=="${ADDITIONALINFO}")&&("${C_resultStatusCode}"=="${RESULTSTATUSCODE}")&&("${C_resultStatusMessage}"=="${RESULTSTATUSMESSAGE}")
But I also need to print the results those doesn't matches: so I created another if controller. and inside that I wrote the below code:(but its not working for me) so the 1st if is getting executed. but the results those are not matching are not getting entered into the 2nd if controller.
("${C_etrTimestamp}"!=="${ETRTIMESTAMP}")or("${C_EventName}"!=="${EVENTNAME}")or("${C_EventType}"!=="${EVENTTYPE}")or("${C_AreaName}"!=="${AREANAME}")or("${C_AreaType}"!=="${AREATYPE}")or("${C_additionalInfo}"!=="${ADDITIONALINFO}")or("${C_resultStatusCode}"!=="${RESULTSTATUSCODE}")or("${C_resultStatusMessage}"!=="${RESULTSTATUSMESSAGE}")
can anyone suggest me what to do?

Instead of trying to negate every clause, make a second condition an exact opposite of the first with `!(...):
!(("${C_etrTimestamp}"=="${ETRTIMESTAMP}")&&("${C_EventName}"=="${EVENTNAME}")&&("${C_EventType}"=="${EVENTTYPE}")&&("${C_AreaName}"=="${AREANAME}")&&("${C_AreaType}"=="${AREATYPE}")&&("${C_additionalInfo}"=="${ADDITIONALINFO}")&&("${C_resultStatusCode}"=="${RESULTSTATUSCODE}")&&("${C_resultStatusMessage}"=="${RESULTSTATUSMESSAGE}"))
You could also simplify conditions to one comparison with all variables inside it (since you want all of them to match), make is a bit shorter and easier to read.
First If:
"${C_etrTimestamp}${C_EventName}${C_EventType}..."=="${ETRTIMESTAMP}${EVENTNAME}${EVENTTYPE}..."
Second If:
!("${C_etrTimestamp}${C_EventName}${C_EventType}..."=="${ETRTIMESTAMP}${EVENTNAME}${EVENTTYPE}...")

Related

Is it possible to have an 'IF' conditional statement nested within a 'CASE' conditional statement? (pseudocode)

I'm designing a pseudocode version of a programme thingy I made, in which one of the sections is someone inputting a number to select an option. When someone inputs a number, a value from a list is output. I thought using an 'IF' statement nested within a 'CASE' statement would make that task run more efficiently, but I'm not sure if that would still conform to the acceptable 'CASE' statement format. This is what I was envisioning for the first option:
**
CASE category OF
'1' : PRINT "Members who have chosen to work as volunteers,"
IF MemberInfo[2] = 'yes'
PRINT "MemberInfo[0], MemberInfo[1]"
**
The following numbers in the main 'CASE' statement would then follow the same format. Is this okay, or should I just make various 'IF' statements?
It does not makes to use CASE here as we use CASE when there are multiple options to choose from. Given its just one condition and action based on that an 'if' is more appropriate.
An if nested within CASE is not a good programming structure. Go with either CASE or IF.
Input a number as category
If category is a number
then
print list
end if
Sure, that makes sense. Real code can do it, so why not pseudocode?
(But if the other cases have the same format, there's probably a better way to do it: maybe a map lookup or using the category more dynamically, depending on what's changing between each case statement, and what stays the same.)

How to avoid checking each condition inside if statement which contains complex operation

Let's say I have this code:
if (condition1 || condition2) {
some_complex_operation(); // memory or time wise, doesn't matter
if (condition1) {
doJob1();
}
if (condition2) {
doJob2();
}
}
Now of course normal procedure here would be to leave out the first if condition, but since I want my complex operation to happen only when one of conditions is satisfied I'd want to avoid doing it every time.
Is there syntactically better way to rewrite this part of the code?
Unless the check for your conditions is expensive, I think your code is fine as it is (and if the check is expensive, you could convert them into booleans before the first if).
Alternatives would be:
move the call to the complex operation inside both if's and remove the outer if, but I like it better as it is now, because it's in one block.
depending on the values of your conditions, you could use a switch statement instead of the two if's, but that won't make much of a difference.
If both conditions can't be true at the same time you could place an else before the second inner if. You could even remove the second check and only use else but then you'd have to make sure the number of conditions never changes.
And of course, in general with or, always place the condition that occurs the most first (in both cases) so there's no need to check the second condition when the first evaluates to true.

How do I prevent to operate over an empty matrix or a matrix with empty columns or row?

In the problem that I want to solve a well defined matrix has no empty rows or columns.
For example the matrix [[],[]] is not valid.
When I call the function first_column, how do I prevent to execute it if the matrix that I send as an argument is not valid as defined before?
first_column([],[],[]).
first_column([[H|T]|Tail],[H|Col],[T|Rows]):- first_column(Tail,Col,Rows).
Technically, what you're asking can be done by testing for an end-condition of a list with one element, rather than an empty list, based on the specs you gave.
first_column([[H|T]],[H],[T]).
first_column([[H|T]|Tail],[H|Col],[T|Rows]):- first_column(Tail,Col,Rows).
However, beyond your specs, I suspect that you'll also need to "transfer" your final Col,Rows to end variables, something like:
first_column([[H|T]],C,R,[H|C],[T|R]).
first_column([[H|T]|Tail],[H|C],[T|R],Col,Rows):-
first_column(Tail,C,R,Col,Rows).
The modified predicate would be called with initial conditions, like
first_column(List,[],[],Col,Rows).

How to dry run with Trace Tables

This is a basic question on the use of Trace Tables to assist in a dry run of a simple algorithm.
What I find most tricky is when to take a new line in the trace table? For example, take the following question:
Here is the array of integers which it applies to:
The following trace table is presented as one completes a dry run. Here is the solution:
I understand that initialising the variables Number, Lower & Upper appear on the first line, but when I go into the While Loop, I am tempted to put the value 5 on the first line also, for the variable Current. In essence, this is what I am tempted to do:
Why does this solution require that the value for Current, which is 5, appear on the second line? I suppose the question could be rephrased to 'When do I take a new line in a trace table?'
Thanks.
I think there is no specific way to do trace table, which means you have to setup your rules before you work and go on.
consider this example:
and this also:
did you notice the difference between loop iterator in each one. In first example they put the initialization value of the iterator in first line, and in second example they put the initialization of the loop iterator in the second line.
also have a look at wiki they also put the loop initialization in the second line.
also this video has similar example to those I posted here and is always start loop iterator in the second line.
also this example has totally different approach, which is each line of code in a new line in the trace table.
you can find also another different approach for trace table here
Finally:
In my opinion chose the rules that make sense for you, for example:
1-first line will contain the default values for the variables.
2-regarding loop iterations, put loop iterator in the same line as the variables that affected by this iteration, like the second example I posted above.
regarding your question I think it's more clear to put Current first value 5 in the second line, so you can track what each loop iteration affect your variables in a clear way.

how to enumerate array indices as odd and even numbers in parameters part of omnet.ini

I have this parameter as an array. The array is big, 100 cells. It is a parameter that can be initiated in omnet.ini file. The cells with even numbers should get value A and odd numbers should get value B. How can I do this in an automated manner?
Is there a way besides having all odd and even indices initiated one by one manually?
Wildcards can be useful but I do not know how to use them to separate odd and even indices.
Thanks.
You can access the actual module index with the index operator. Combining this with the conditional operator ?: you can easily define the value:
**.myModule[*].myParameter = index % 2 == 0 ? "A" : "B"
I'm not aware of any feature like this. There are a number of work-arounds you could use:
Provide two parameters and select the correct one in code
Use the volatile keyword (probably not appropriate here)
Put the entire thing in your .ini file
I'd personally implement the first approach, that way you can use the wildcard to pass both parameters ([*].myNode.parameterEven and [*].myNode.parameterUneven) and then set the correct values in your array in a for loop.
However, you could also use the volatile keyword in your NED file, see the manual for more details. However, this approach mostly works well if you have different parameters depending on which node you are assigning it to. For this case I think the first approach is better.
The last alternative is just putting the entire thing in your .ini file, which may be useful if you want to parameterize the array later.

Resources