Including uncovered files in Devel::Cover reports - perl

I have a project setup like this:
bin/fizzbuzz-game.pl
lib/FizzBuzz.pm
test/TestFizzBuzz.pm
test/TestFizzBuzz.t
When I run coverage on this, using
perl -MDevel::Cover=-db,/tmp/cover_db test/*.t
... I get the following output:
----------------------------------- ------ ------ ------ ------ ------ ------
File stmt bran cond sub time total
----------------------------------- ------ ------ ------ ------ ------ ------
lib/FizzBuzz.pm 100.0 100.0 n/a 100.0 1.4 100.0
test/TestFizzBuzz.pm 100.0 n/a n/a 100.0 97.9 100.0
test/TestFizzBuzz.t 100.0 n/a n/a 100.0 0.7 100.0
Total 100.0 100.0 n/a 100.0 100.0 100.0
----------------------------------- ------ ------ ------ ------ ------ ------
That is: the totally-uncovered file bin/fizzbuzz-game.pl is not included in the results.
How do I fix this?

Have you checked the documentation? The section on Selecting which files to cover seems most helpful. :) It looks like the +select option is the one you are looking for.

I figured out a work-around for this.
The core of this problem is that the uncovered code in the main file (fizzbuzz-game.pl) is not included in the coverage report, hence the overall percentage is wrong. The underlying problem is that substantial logic resides in the main file instead of testable modules. This is a smell (don't know which, but I'm pretty sure there is a name for "lots of logic in main()").
By getting rid of this smell, eg. moving all substatial code from bin/fizzbuzz-game.pl to lib/FizzBuzzGame.pm, the code can theoretically be tested, and can definitively be included in the test run.
The coverage report after this becomes:
----------------------------------- ------ ------ ------ ------ ------ ------
File stmt bran cond sub time total
----------------------------------- ------ ------ ------ ------ ------ ------
lib/FizzBuzz.pm 100.0 100.0 n/a 100.0 0.0 100.0
lib/FizzBuzzGame.pm 75.0 n/a n/a 75.0 100.0 75.0
Total 87.5 100.0 n/a 83.3 100.0 88.9
----------------------------------- ------ ------ ------ ------ ------ ------

Related

Problem serving local files with vweb (V-lang's default server)

Description of the problem
According to V's doc, using vweb, in order to serve static files one just has to add the following line to a server:
app.mount_static_folder_at(os.resource_abs_path('dist'), '/content')
So, for instance: the following server is supposed to serve the content of the local directory ./dist at the address: http://localhost:8080/content
The complete code being :
import vweb
import os
struct App {
vweb.Context
}
fn main() {
mut app := &App{}
println(os.resource_abs_path('dist'))
app.mount_static_folder_at(os.resource_abs_path('dist'), '/content')
vweb.run(app, 8080)
}
["/"]
fn (mut app App) root() vweb.Result {
return app.text('Hello from root')
}
Expected Behavior
The server is supposed to serve the content of the local directory ./dist at the address: http://localhost:8080/content
Current Behavior
404 Not Found
Reproduction Steps
println(os.resource_abs_path('dist')) yields
C:\Users\serge\Documents\vue-tests\vue-tests-nomodules\v2\dist
Which is correct, plus:
ls lists
---- ------------- ------ ----
d----- 2/11/2023 6:45 PM dist
d----- 2/11/2023 6:45 PM src
-a---- 2/11/2023 5:53 PM 139 .editorconfig
-a---- 2/11/2023 5:53 PM 148 .gitattributes
-a---- 2/11/2023 5:53 PM 237 .gitignore
-a---- 2/11/2023 6:06 PM 85 v.mod
-a---- 2/12/2023 12:56 PM 2037248 v2.exe
PS C:\Users\serge\Documents\vue-tests\vue-tests-nomodules\v2> ls .\dist\
Directory: C:\Users\serge\Documents\vue-tests\vue-tests-nomodules\v2\dist
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2/11/2023 6:32 PM 295 app.html
-a---- 2/11/2023 6:42 PM 295 index.html
Possible Solution
No response
Additional Information/Context
No response
V version
V 0.3.3 90591eb
Environment details (OS name and version, etc.)
Windows 11

Getting table rows count by using count 1

To get an appropriate table rows count I thought to use a naive approach: use count 1 construct. And it works in a simple case:
q)t:([]sym:`a`a`b`b);
q)select cnt: count 1 by sym from t
sym| cnt
---| ---
a | 2
b | 2
But when I added other fields, I've got wrong result:
q)select cnt: count 1, sym by sym from t
sym| cnt sym
---| -------
a | 1 a a
b | 1 b b
Why does count 1 work (or just it seems so) in one column case and failed with multiple columns?
Upd: Expected to get something like this
sym| cnt sym
---| -------
a | 2 a a
b | 2 b b
I don't think count 1 will produce the result you're looking for, nor even a consistent one.
I think you might want to use count i instead. When selecting by sym you are specifying which column you want to count by.
q)t:([]sym:`a`a`b`b)
q)select cnt:count i,sym by sym from t
sym| cnt sym
---| -------
a | 2 a a
b | 2 b b
q).z.K
3.6
A point to note however is that this solution will not work on kdb+ 4.0.
q)t:([]sym:`a`a`b`b)
q)select cnt:count i,sym by sym from t
'dup names for cols/groups sym
[0] select cnt:count i,sym by sym from t
^
q).z.K
4f

kdb: filter table match symbol column: ~ vs =

For a where clause to filter on symbol columns, = works fine, but why does the match operator ~ not work?
q)t:([sym:`aa`bb]qty:20 30)
q)t
sym| qty
---| ---
aa | 20
bb | 30
q)select from t where sym=`aa
sym| qty
---| ---
aa | 20
q)select from t where sym~`aa
sym| qty
---| ---
Match is comparing `aa to the entire symbol column, where equals is comparing to each element
q)`a=`a`b`c
100b
q)`a~`a`b`c
0b
You could do
q)select from t where sym~\:`aa
sym| qty
---| ---
aa | 20

Pivot table in PostgreSQL repeating values in columns

Having the following data in a table:
ID --------- Category --------- Value
1234 -------- Cat01 ----------- V001
1234 -------- Cat02 ----------- V002
1234 -------- Cat03 ----------- V003
1234 -------- Cat03 ----------- V004
1234 -------- Cat03 ----------- V005
I want to have the following output:
ID --------- Cat01 --------- Cat02 --------- Cat03
1234 ------- V001 ---------- V002 ---------- V003
1234 ------- V001 ---------- V002 ---------- V004
1234 ------- V001 ---------- V002 ---------- V005
How can it be done in PostgreSQL. As you can see, the value in Cat01 and Cat02 columns are repeated for each entry in Cat03 column
Many thanks for your help!
How about something like this:
SELECT a.val AS cat01, b.val AS cat02, c.val AS cat03
FROM
test_pivot AS a,
test_pivot AS b,
test_pivot AS c
WHERE
a.category = 'Cat01'
AND
b.category = 'Cat02'
AND
c.category = 'Cat03'

Spark(scala): Count all distinct values of a whole column on RDD

I have this RDD:
val resultRdd: RDD[(VertexId, String, Seq[Long])]
I want to count the distinct values in Seq of all records.
for example, if I have 3 records with Seq values as follows:
VertexId ------- String -------Seq[Long]
1 ----------------- x ------------- 1, 3
2 ----------------- x ------------- 1, 5
3 ----------------- x--------------- 2, 3, 6
the result should be = 5 , the count of {1,3,5,2,6}
Thanks :)
resultRdd.flatMap(_._3).distinct().count()