Executing without step definition of BUT - specflow

I faced an issue. We need to have a matching step definition for 'BUT' otherwise the execution is not happening. Based on reading Ben comments , i thought that it will not be required to have a matching step definition for 'BUT' but this is not the case.
Can we execute without having step definition provided 'BUT' is there ??

All steps must have a matching step definition. There are only 3 types of steps: Given, When and Then. And steps and But steps are just aliases for 'the same as the previous step'. There is no attribute for And and But.
so these two scenarios are equivalent:
Given a given step
And some other given condition
When a thing happens
Then a condition should be true
But some other condition should not be
And
Given a given step
Given some other given condition
When a thing happens
Then a condition should be true
Then some other condition should not be
but obviously the first one reads a bit better

Related

Passing output of a TestStep to another TestStep

In the Keysight OpenTap
There is Test- Step 1. I would like the pass the result obtained by Test-Step 1 to any of the Test-Step-n
Example : Test-Step1 executes SCPI Query and then the result obtained from this, has to be passed to Test-Step-N.
For this approach, we have extended a Test-Step and created our own Test Step.
Is there any in-built feature In TAP we could make use of it?
Are you asking for this feature to be provided by the built-in 'Basic/Flow Steps'?
Input/Output parameters are fully supported by the OpenTAP engine and as you point out, you have created your own TestStep which I assume has utilised this approach.
Any generic Teststep that would consume the output of another TestStep would need to understand the data to make any use of it other than in the simplest of cases.
Do you have a specific example?

Check values existence using spss syntax

I should check existence of values based on some conditions.
i.e. i have 3 variables, varA, varB and varC. varC should not be empty only if varA>varB (condition).
i normally use some syntax to check any of the variables and run a frequency of any of them to see if there are errors:
if missing(varC) and (varA>varB) ck_varC=1.
if not(missing(varC)) and not(varA>varB) ck_varC=2.
exe.
fre ck_varC.
exe.
I had some errors when the condition became complex and when in the condition there are missing() or other functions but i could have made a mistake.
do you think there is an easier way of doing this checks?
thanks in advance
EDIT: here an example of what i mean, think at a questionnaire with some routing, you ask age to anyone, if they are between 17 and 44 ask them if they work, if they work ask them how many hours.
i have an excel tool where i put down all variables with all conditions, then it will generate the syntax in the example, all with the same structure for all variables, considering both situations, we have a value that shouldn't be there or we don't have a value that should be there.
is there an easier way of doing that? is this structure always valid no matter what is the condition?
In SPSS, missing values are not numbers. You need to explicitly program those scenarios as well. you got varC covered (partially), but no scenario where varA or varB have missing data is covered.
(As good practice, maybe you should initialize your check variable as sysmis or 0, using syntax):
numeric ck_varC (f1.0).
compute ck_varC=0.
if missing(varC) and (varA>varB) ck_varC=1.
if not(missing(varC)) and not(varA>varB) ck_varC=2.
***additional conditional scenarios go here:.
if missing(varA) or missing(varB) ck_varC=3.
...
fre ck_varC.
By the way - you do not need any of the exe. commands if you are going to run your syntax as a whole.
Later Edit, after the poster updated the question:
Your syntax would be something like this. Note the use of the range function, which is not mandatory, but might be useful for you in the future.
I am also assuming that work is a string variable, so its values need to be referenced using quotation signs.
if missing(age) ck_age=1.
if missing(work) and range(age,17,44) ck_work=1.
if missing(hours) and work="yes" ck_hours=1.
if not (missing (age)) and not(1>0) ck_age=2. /*this will never happen because of the not(1>0).
if not(missing(work)) and (not range(age,17,44)) ck_work=2. /*note that if age is missing, this ck_work won't be set here.
if not(missing(hours)) and (not(work="yes")) ck_hours=2.
EXECUTE.
String variables are case sensitive
There is no missing equivalent in strings; an empty blank string ("") is still a string. not(work="yes") is True when work is blank ("").

DLV Rule is not safe

I am starting to work with DLV (Disjunctive Datalog) and I have a rule that is reporting a "Rule is not safe" error, when running the code. The rule is the following:
foo(R, 1) :- not foo(R, _)
I have read the manual and seen that "cyclic dependencies are disallowed". I guess this is why I am being reported the error, but I am not sure how this statement is so problematic to DLV. The final goal is to have some kind of initialization in case that the predicate has not been defined.
More precisely, if there is no occurrence of 'foo' with the parameter R (and anything else), then define it with parameters R and 1. Once it is defined, the rule shouldn't be triggered again. So, this is not a real recursion in my opinion.
Any comments on how to solve this issue are welcomed!
I have realised that I probably need another predicate to match the parameter R in the body of the rule. Something like this:
foo(R, 1) :- not foo(R, _), bar(R)
Since, otherwise there would be no way to know whether there are no occurrences of foo(R, _). I don't know whether I made myself clear.
Anyway, this doesn't work either :(
To the particular "Rule is not safe" error: First of all this has nothing to do with cyclic or acyclic dependencies. The same error message shows up for the non-cyclic program:
foo2(R, 1) :- not foo(R,_), bar(R).
The problem is that the program is actually not safe (http://www.dlvsystem.com/html/DLV_User_Manual.html#SAFETY). As mentioned in the section on negative rules (anchor #AEN375, I am only allowed to use 2 links in my answer):
Variables, which occur in a negated literal, must also occur in a
positive literal in the body.
Observe that the _ is an anonymous variable. I.e., the program
foo(R,1) :- not foo(R,_), bar(R).
can be equivalently written as (and is equivalent to)
foo(R,1) :- not foo(R,X), bar(R).
Anonymous variables (DLV manual, anchor #AEN264 - at the end of the section) just allow us to avoid inventing names for variables that will only occur once within the rule (i.e. for variables that only express "there is some value, I absolutely do not care about it), but they are variables nevertheless. And since negation with not is "negation" and not "true negation" (or "strong negation" as it is also often called), none of the three safety conditions is satisfied by the rule.
A very rough and high-level intuition for safety is that it guarantees that every variable in the program can be assigned to some finite domain - as it is now the case with R by adding bar(R). However, the same also must be the case for the anonymous variable _ .
To the actual problem of defining default values:
As pointed out by lambda.xy.x, the problem here is the Answer Set (or stable model) semantics of DLV: Trying to do it in one rule does not give any solution:
In order to get a safe program, we could replace the above problems e.g. by
foo(1,2). bar(1). bar(2).
tmp(R) :- foo(R,_).
foo(R,1) :- not tmp(R), bar(R).
This has no stable model:
Assume the answer is, as intended,
{foo(1,2), bar(1), bar(2), foo(2,1)}
However, this is not a valid model, since tmp(R) :- foo(R,_) would require it to contain tmp(2). But then, "not tmp(2)" is no longer true, and therefore having foo(2,1) in the model violates the required minimality of the model. (This is not exactly what is going on, more a rough intuition. More technical details could be found in any article on answer set programming, a quick Google search gave me this paper as one of the first results: http://www.kr.tuwien.ac.at/staff/tkren/pub/2009/rw2009-asp.pdf)
In order to solve the problem, it is therefore somehow necessary to "break the cycle". One possibility would be:
foo(1,2). bar(1). bar(2). bar(3).
tmp(R) :- foo(R,X), X!=1.
foo(R,1) :- bar(R), not tmp(R).
I.e., by explicitly stating that we want to add R into the intermediate atom only if the value is different from 1, having foo(2,1) in the model does not contradict tmp(2) not being part of the model as well. Of course, this no longer allows to distinguish whether foo(R,1) is there as default value or by input, but if this is not required ...
Another possibility would be to not use foo for the computation, but some foo1 instead. I.e. having
foo1(R,X) :- foo(R,X).
tmp(R) :- foo(R,_).
foo1(R,1) :- bar(R), not tmp(R).
and then just use foo1 instead of foo.

Questions about the statement coverage, branch coverage and path coverage

I am really confuse with the statement coverage. I did some search on the Internet. Some say the statement coverage only go through the true condition, which in this case is 1-2-3-4-12. However, others say the statement coverage should cover as many statements as possible, which I believe in this case will be 1-2-3-5-6-7-8-9-10-11-12. Which one is correct?
For the branch coverage, I believe I should test both the true/false conditions without considering the loop, which I will use the value 1)x=-1 and 2)x=0
For the path coverage, I think I should test all the paths so compared to branch coverage I will need to test the loop also. So I am going to use the value 1) x= -1, 2)x = 0 and 3) x = 10.
Is my answers correct?
Thank you in advance
I think "statement coverage" refers to "meaningful/useful/normal".
The nubmer of statement may vary by breaking one statement into two.
The "true" condition may not be useful for us just like the example you gave. Normally we want a positive number to get its factorial. You can switch the "true" and "false" conditions whatever you like.
To calculate Statement Coverage, find out the shortest number of paths following which all the nodes will be covered.
So in your case :
1-2-3-5-6-7-8-9-10-11-12
This path is the shortest and covering maximum number of nodes but not all
so we have to take one more path , which is :
1-2-3-4-12
So in this exercise , the value of SC=2

Single parameter with multiple values - referencing extended-choice parameter values

I am stuck with the following situation in Jenkins.
A job needs to build multiple make targets. This will happen through multiple invocations of make per run as it allows only 1 target at a time. I want to allow users to select which targets to build with each run.
I tried with extended-choice parameter plugin (Multi-select), but could not figure out how to parse multiple values from it, and how to structure my call to make
Can someone help me with this
Extended-choice parameter will always list its selected values as TARGET=value1,value2. At best, you can enforce the values to be quoted like this TARGET="value1,value2"
You have to parse this TARGET value to get it into the format you want.
If you could pass targets to make in sequence, like make value1 value2, all you would need is to change that comma , in value of TARGET to a space . You didn't provide your OS, so I will assume *nix. You can use the following to quickly do that ${TARGET//,/ }
Finally, since make does not appear to support multiple targets (according to OP), we need a loop.
So, in your Jenkins Execute Shell build step, type:
for currentTarget in ${TARGET//,/ }; do
make $currentTarget
done
This will be equivalent to:
make value1
make value2
As for the order of thing: the order of these values will always be same as they are defined in job configuration. It doesn't matter in what order the user chooses these.
REQUIREMENT:
The parameter $TARGETS had 26 values (Values might be added/deleted in future). The user is interested in selecting which parameters he wants to build this time.
$TARGETS=make1,make2,make3.......
TRIAL:
Jenkins "extended choice parameter". Could assign multiple values to a parameter and user gets the option to select multiple values.
During build with make $TARGETS, I got error, could not "make make1 make2".
I needed
make make1
make make2
SOLUTION:
In the build step, use "for loop"
for currentTarget in ${TARGET//,/ }; do
make $currentTarget
done
Thanks to #Slav
Hope this helps people who might face similar situation.
Thanks

Resources