I am using mockk library in Kotlin. I am covering branch coverage. I am new to testing. Can someone tell me how to cover all branches? In the given below example, it has two objects one is id as string and the name which is hidden is list. Thanks
Can someone explain what are the 12 branches are for this?
I can only count 9, but I might be missing something:
!id.isNullOrEmpty()
Reason
!xxx.isNullOrEmpty()
Reason
TRUE
id is not null and not empty
TRUE
xxx is not null and not empty
TRUE
id is not null and not empty
FALSE
xxx is empty
TRUE
id is not null and not empty
FALSE
xxx is null
FALSE
id is null
TRUE
xxx is not null and not empty
FALSE
id is empty
TRUE
xxx is not null and not empty
FALSE
id is null
FALSE
xxx is null
FALSE
id is null
FALSE
xxx is empty
FALSE
id is empty
FALSE
xxx is null
FALSE
id is empty
FALSE
xxx is empty
Related
I currently have this dataset, intended to show every line as a potential boolean combination :
Column_A
Column_B
True
True
True
False
False
True
False
False
I want this :
Column_A
Column_B
Column_C
True
True
100
True
False
50
False
True
40
False
False
10
Where Column_C is a COUNT(*) FROM the initial table, with conditions.
The thing is, if I use a subquery like
(SELECT COUNT(*) FROM table WHERE condition) as Column_C
I just get the total count regardless of the boolean combinations.
I get this :
Column_A
Column_B
Column_C
True
True
200
True
False
200
False
True
200
False
False
200
Any idea on how to solve this ?
Thanks in advance !
I think you want aggregation:
select a, b, count(*)
from t
group by a, b;
I am new to BigQuery. I have the following simple query:
SELECT name, assetType,resource.data.shieldedInstanceConfig.enableSecureBoot FROM test001_99a3cr6b.assets_compute_googleapis_com_Instance;
It gives me the the following output:
Row name assetType enableSecureBoot
1 //compute.googleapis.com/projects/blah-ddi-test001-prod/zones/us-east4-b/instances/ddi-us-east4-b-5c2b51b2e3740 compute.googleapis.com/Instance null
2 //compute.googleapis.com/projects/blah-ddi-test001-prod/zones/us-east4-a/instances/ddi-us-east4-a-5c2b51b2e3740 compute.googleapis.com/Instance null
3 //compute.googleapis.com/projects/blah-ddi-test001-prod/zones/us-east4-a/instances/ddi-us-east4-a-f2f9a153c4590 compute.googleapis.com/Instance null
4 //compute.googleapis.com/projects/blah-admin-rbs-prod/zones/us-east4-c/instances/krp-pci-krp-vm-hx5q compute.googleapis.com/Instance true
5 //compute.googleapis.com/projects/blah-admin-rbs-prod/zones/us-east4-b/instances/krp-pci-krp-vm-bvt2 compute.googleapis.com/Instance true
6 //compute.googleapis.com/projects/blah-admin-rbs-prod/zones/us-east4-c/instances/orn-test-01 compute.googleapis.com/Instance true
7 //compute.googleapis.com/projects/blah-web-ingress-prod/zones/us-east4-c/instances/instance-1 compute.googleapis.com/Instance true
8 //compute.googleapis.com/projects/blah-network-hub/zones/us-central1-a/instances/orn-test-central1 compute.googleapis.com/Instance true
9 //compute.googleapis.com/projects/blah-network-hub/zones/us-east4-c/instances/orn-test-east4 compute.googleapis.com/Instance true
10 //compute.googleapis.com/projects/blah-network-hub/zones/us-east4-c/instances/test-vm compute.googleapis.com/Instance true
11 //compute.googleapis.com/projects/blah-network-hub/zones/us-central1-a/instances/test-vm-gui compute.googleapis.com/Instance true
12 //compute.googleapis.com/projects/blah-network-hub/zones/us-east4-c/instances/orn-test-east4 compute.googleapis.com/Instance true
I want to replace the values under field 'enableSecureBoot' with 'Not_Set' I tried IFNULL, as well as IF statements, but gives me unrecognized name 'enableSecureBoot' no matter what I do. Can you anyone give me a hint on how to do it, please?
Thanks so much!!
By looking at your SELECT statement, I think resource.data.shieldedInstanceConfig is a STRUCT in your table.
if you want to create a new column enableSecureBoot using the value of a STRUCT field resource.data.shieldedInstanceConfig.enableSecureBoot,
you could do below
SELECT
name,
assetType,
IFNULL(
CAST (resource.data.shieldedInstanceConfig.enableSecureBoot AS STRING),
'Not_Set'
) AS enableSecureBoot
FROM test001_99a3cr6b.assets_compute_googleapis_com_Instance;
Please note that the original resource.data.shieldedInstanceConfig.enableSecureBoot is a BOOLEAN type column, and the new enableSecureBoot is a STRING type column
This is what worked:
SELECT name, assetType,IFNULL(CAST(resource.data.shieldedInstanceConfig.enableSecureBoot AS STRING), 'NOT SET') AS ENABLED
FROM test001_99a3cr6b.assets_compute_googleapis_com_Instance;
Thanks again!
Alex
I saw few similar queries but did not help my cause.
I have a table similar to below :
Name Value Item
---------------------------------
isVisible True 123
isAvailable False 123
Qty 3 123
isOnline True 123
DeleteElig True 123
I need to find all items which has isVisible = True
You can use filtering:
select item
from t
where name = 'isVisible' and value = 'True';
I have a table like this:
**ID** | **read** | **edit** | **delete**|
1 true false false
2 false false true
3 true false true
4 true false false
I want to "OR" the rows and at last create a row that contain the OR result of them. is there any way to do it without for loop? what is the best way ? (row may be so many and i think for loop may reduce speed)
You could just cast the bits to integers and use MAX to get the biggest value;
SELECT MAX(CAST([read] AS INT)) [read],
MAX(CAST([edit] AS INT)) [edit],
MAX(CAST([delete] AS INT)) [delete]
FROM mytable;
An SQLfiddle to test with.
Try this:
select
cast(max(cast([read] as int)) as bit) as [overall_read],
cast(max(cast([edit] as int)) as bit) as [overall_edit],
cast(max(cast([delete] as int)) as bit) as [overall_delete]
from tbl
a or b is True when at least 1 of a or b is True, and False otherwise. So you can directly reduce this to getting the maximum value for each column, as #Joachim has also pointed out.
I've tested IS NULL function provided by Google BigQuery, but it doesn't seems to give correct results.
SAMPLE DATA:
id age gender password
1, 11, NULL, NULL
1, 11, "NULL", "NULL"
1, 11, "null", "null"
1, , NULL, NULL
QUERY:
SELECT id, age, gender, password, id IS NULL, age IS NULL, gender IS NULL, password IS NULL
FROM privatedata.testnull
OUTPUT:
Row id age gender password f0_ f1_ f2_ f3_
1 1 11 NULL NULL false false false false
2 1 11 NULL NULL false false false false
3 1 11 null null false false false false
4 1 0 NULL NULL false false false false
But this SQL works:
SELECT NULL IS NULL, COUNT(*) FROM privatedata:testnull
So I'm not sure if IS NULL is working or not. Also I'm confused with how I would insert null data in string format and numeric format.
EDITED ANSWER:
For very old tables there was an issue where we did not preserve the between an empty field and a NULL one. This issue should by fixed for any table that was created after March, 2013.
OLD ANSWER:
I believe the issue is that for string fields, we're interpreting the NULL as the string "NULL". What if you just use , , for the string values?
The one that is surprising is that age in row 4 should be showing up as null. It looks like something is wrong with the IS_NULL function. I've filed a bug internally. The IS_EXPLICITLY_DEFINED() function, however, should return what you expect (e.g. IS_EXPLICITLY_DEFINED for age in row 4 would return fasle).