Can I have one question? What is the difference between Condition coverage and Decision coverage?
I have simply example:
IF (A && B) THEN
Condition coverage will have two tests (The result will be false):
A = TRUE, B = FALSE
A = FALSE, B = TRUE
Decision coverage will have only one test (The result will be true):
A = TRUE, B = TRUE
Do I understand that right?
In Condition Coverage (also know as Predicate Coverage) each of the boolean expressions must be evaluated to true and false at least once. For example:
IF ((A || B) && C) THEN
To satisfy the condition coverage criteria, you could use the following tests:
1) A = true | B = not eval | C = false
2) A = false | B = true | C = true
3) A = false | B = false | C = not eval
In Decision Coverage (also know as Branch Coverage) you have to test all posible branches. For example:
...
IF (A){
ELSE IF(B){
}ELSE{
}
...
To satisfy the decision coverage criteria for this piece of code you'll need to run 3 tests:
1) A is evaluated to true
2) A is evaluated to false and B is evaluated to true
3) A and B are evaluated to false
Example:
a = int(input())
if a=0:
print("Zero")
elif a>0:
print("Positive")
else:
print("Negative")
Here the Statement no. 2, 4 and 6 will be considered under Condition Coverage. (Bcz here you are checking the condition that is it equal to 0 or not, is it greater than 0 or not, etc.)
and the statement no. 3, 5 and 7 will be considered under Decision coverage.
(Bcz these are the decision taken after cheking the condition)
Imp Note: Decision Coverage and Branch Coverage are different.
Related
im in a process of making a roblox game. I want to make the water rise and descend again down. I think i did something wrong with coding,(its my second day of coding and i cant find any video on it) im not sure what. So everytime i run roblox after 1st descending and starting of 2nd game, it freezes,water dissapears and it throws a error: Script timeout: exhausted allowed execution time. Here is my code:
wait(21)
t = 17
repeat
t = t-1
script.Parent.Position = script.Parent.Position + Vector3.new(0, 1, 0)
wait(2)
until
t == 0
wait(1)
t = 17
repeat
t = t-1
script.Parent.Position = script.Parent.Position + Vector3.new(0, -1, 0)
wait(0.5)
until
t == 0
wait(9)
t = 17
while true do
t = t-1
script.Parent.Position = script.Parent.Position + Vector3.new(0, 1, 0)
end
wait(2)
while false do
t = t-1
script.Parent.Position = script.Parent.Position + Vector3.new(0, -1, 0)
end
Script timeout: exhausted allowed execution time.
Because the code never stops looping here:
while true do
//...
end
This will continue to loop forever. (Well, for as long as true is true. And I can't think of a condition in which it wouldn't be.)
Contrast that with your loops above:
t = 17
repeat
t = t-1
//...
until
t == 0
In this case the loop explicitly repeats "until t equals 0", and each iteration of the loop brings t one step closer to 0.
Modify your later loops to have similar structures and conditions. For example:
t = 17
while t > 0 do
t = t-1
//...
end
Note also that this loop will never execute:
while false do
//...
end
Because false is never true. Now is a good time to take a step back and consider the logic of what you want these loops to do. Just like with your first two loops, modify your second two loops to indicate how many times they should repeat.
I'm using Pandas DataFrames. I'm looking to identify all rows where both columns A and B == True, then represent in Column C the all points on other side of that intersection where only A or B is still true but not the other. For example:
A B C
0 False False False
1 True False True
2 True True True
3 True True True
4 False True True
5 False False False
6 True False False
7 True False False
I can find the direct overlaps quite easily:
df.loc[(df['A'] == True) & (df['B'] == True), 'C'] = True
... however this does not take into account the overlap need.
I considered creating column 'C' in this way, then grouping each column:
grp_a = df.loc[(df['A'] == True), 'A'].groupby(df['A'].astype('int').diff.ne(0).cumsum())
grp_b = df.loc[(df['A'] == True), 'A'].groupby(df['A'].astype('int').diff.ne(0).cumsum())
grp_c = df.loc[(df['A'] == True), 'A'].groupby(df['A'].astype('int').diff.ne(0).cumsum())
From there I thought to iterate over the indexes in grp_c.indices and test the indices in grp_a and grp_b against those, find the min/max index of A and B and update column C. This feels like an inefficient way of getting to the result I want though.
Ideas?
Try this:
#Input df just columns 'A' and 'B'
df = df[['A','B']]
df['C'] = df.assign(C=df.min(1)).groupby((df[['A','B']].max(1) == 0).cumsum())['C']\
.transform('max').mask(df.max(1)==0, False)
print(df)
Output:
A B C
0 False False False
1 True False True
2 True True True
3 True True True
4 False True True
5 False False False
6 True False False
7 True False False
Explanation:
First, create column 'C' with the assignment of minimum value, what this does is to ass True to C where both A and B are True. Next, using
df[['A','B']].max(1) == 0
0 True
1 False
2 False
3 False
4 False
5 True
6 False
7 False
dtype: bool
We can find all of the records were A and B are both False. Then we use cumsum to create a count of those False False records. Allowing us to create grouping of records with the False False recording having a count up until the next False False record which gets incremented.
(df[['A','B']].max(1) == 0).cumsum()
0 1
1 1
2 1
3 1
4 1
5 2
6 2
7 2
dtype: int32
Let's group the dataframe with the newly assigned column C by this grouping created with cumsum. Then take the maximum value of column C from that group. So, if the group has a True True record, assign True to all the records in that group. Lastly, use mask to turn the first False False record back to False.
df.assign(C=df.min(1)).groupby((df[['A','B']].max(1) == 0).cumsum())['C']\
.transform('max').mask(df.max(1)==0, False)
0 False
1 True
2 True
3 True
4 True
5 False
6 False
7 False
Name: C, dtype: bool
And, assign that series to df['C'] overwriting the temporarily assigned C in the statement.
df['C'] = df.assign(C=df.min(1)).groupby((df[['A','B']].max(1) == 0).cumsum())['C']\
.transform('max').mask(df.max(1)==0, False)
I have spent two days searching, any help would be appreciated.
Trying to create c_flg based on values in other columns.
a_flg b_flg Count c_flg (Expected Output)
False True 3 False
True False 2 False
False False 4 True
a_flg & b_flg are strs, Count is an int
Approaching from two angles, neither successful.
Method 1:
df['c_flg'] = np.where((df[(df['a_flg'] == 'False') &
(df['b_flg'] == 'False') &
(df['Count'] <= 6 )]), 'True', 'False')
ValueError: Length of values does not match length of index
Method 2:
def test_func(df):
if (('a_flg' == 'False') &
('b_flg' == 'False') &
('Count' <= 6 )):
return True
else:
return False
df['c_flg']=df.apply(test_func, axis=1)
TypeError: ('unorderable types: str() <= int()', 'occurred at index 0')
Very new to the Python language, help would be appreciated.
If I understand your problem properly then you need this,
df['c_flg']=(df['a_flg']=='False')&(df['b_flg']=='False')&(df['Count']<=6)
df['c_flg']=(df['a_flg']==False)&(df['b_flg']==False)&(df['Count']<=6)#use this if 'x_flg' is boolean
Output:
a_flg b_flg Count c_flg
0 False True 3 False
1 True False 2 False
2 False False 4 True
Note: For this problem you really don't need numpy, pandas itself can solve this without any problem.
I believe np.where is not necessary, use ~ for invert boolean mask and chain & for bitwise AND:
print (df.dtypes)
a_flg bool
b_flg bool
Count int64
dtype: object
df['c_flg'] = ~df['a_flg'] & ~df['b_flg'] & (df['Count'] <= 6)
print (df)
a_flg b_flg Count c_flg
0 False True 3 False
1 True False 2 False
2 False False 4 True
I need to create a procedure with optional arguments and use them only if they are not null
My current query looks like:
SELECT * FROM sth WHERE
(arg1 IS NULL OR sth.c1 = arg1) AND
(arg2 IS NULL OR sth.c2 = arg2) AND
(arg3 IS NULL OR sth.c3 > arg3) AND
(arg4 IS NULL OR sth.c4 < arg4)
I'm thinking of a way to make it look better / shorter. My first shot is:
SELECT * FROM sth WHERE
COALESCE(sth.c1 = arg1, 't') AND
COALESCE(sth.c2 = arg2, 't') AND
COALESCE(sth.c3 > arg3, 't') AND
COALESCE(sth.c4 < arg4, 't');
but I'm not sure if this looks any better. Do you know any useful tricks for this?
Keep it the way it is. Using coalesce will prevent the query planner from doing its job properly, and you'll end up with sucky query plans.
Best I'm aware, the following expressions will use a btree index:
col = 'val'
col is null
The following expressions will not use a btree index:
col is [not] 'val'
(col = 'val') is [not] <true | false | null>
col is [not] distinct from 'val'
coalesce(col, 'val') = 'val'
coalesce(col = 'val', <true | false | null>)
Ok, I think that this query is the best idea for this purpose
SELECT * FROM sth WHERE
NOT (sth.c1 = arg1) IS FALSE AND
NOT (sth.c2 = arg2) IS FALSE AND
NOT (sth.c3 > arg3) IS FALSE AND
NOT (sth.c4 < arg4) IS FALSE;
it doesn't use any functions so the query planner should work fine just as before
it just uses simple expressions where:
1.
true = true // true
true = false // false
true = null // null
2.
false is false // true
true is false // false
null is false // false
3.
not true // false
not false // true
so it will return true if expression is true OR null
If, for example, I wanted to define a function that returned true if a=b and b=c, and false if neither one of those equalities were true in Poly ML, how would I write it? I'm not sure how to do more than one conditional simultaneously.
Isn't
a = b andalso b = c
what you want?
I believe this does what you need:
fun f (a, b, c) =
if a = b andalso b = c
then true
else
if a <> b andalso b <> c
then false
else ... (* you haven't specified this case *)
The main points here are:
You can nest conditionals, i.e. have one if expression inside another's then or else case
The operator andalso is the boolean conjunction, meaning x andalso y is true if and only if x evaluates to true and y evaluates to true.
You can put this more concisely using a case expression:
fun f (a, b, c) =
case (a = b, b = c) of
(true, true) => true
| (false, false) => false
| _ => (* you haven't specified this case *)