From 3cee9a2caac7bfb0f7fd5a80a5167d2079e978c7 Mon Sep 17 00:00:00 2001 From: Gergely Attila Kiss Date: Sun, 21 Jul 2024 13:03:01 +0200 Subject: [PATCH] add further tests for better coverage --- test/commands.jl | 43 +++++++++++++++++++++++++++++++++++++++---- test/test.dta | Bin 3155 -> 1855 bytes 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/test/commands.jl b/test/commands.jl index de7517a..0a601fd 100644 --- a/test/commands.jl +++ b/test/commands.jl @@ -592,6 +592,14 @@ end r = @with df @regress y x z z*x @if x < 5 || x >8 @test r.coef ≈ [2.000000000000003, 2.9999999999999996, 0.9999999999999998, 5.124106267500724e-17] end + @testset "Options" begin + r = @with df @regress y x z fe(s), robust + @test r.coef ≈ [ 2.9999999999999996, 1.0000000000000002] + r = @with df @regress y x z fe(s), cluster(s) + @test r.coef ≈ [ 2.9999999999999996, 1.0000000000000002] + r = @with df @regress y x z fe(s), cluster(s) robust + @test r.coef ≈ [ 2.9999999999999996, 1.0000000000000002] + end end @testset "Missing values" begin @@ -654,6 +662,14 @@ end @test_throws Exception (@with df @list x).y end +@testset "Describe" begin + df = DataFrame(x=1:10, y=11:20) + @test (@with df @describe) == DataFrame(variable=[:x, :y], eltype=[Int64, Int64]) + @test (@with df @describe x) == DataFrame(variable=[:x], eltype=[Int64]) + @test (@with df @describe y) == DataFrame(variable=[:y], eltype=[Int64]) + @test (@with df @describe x y) == DataFrame(variable=[:x, :y], eltype=[Int64, Int64]) +end + @testset "Sort" begin df = DataFrame(x=[1, 2, 3, 2, 1, 3], y= [0, 2, 0, 1, 1, 1]) @testset "Known values" begin @@ -671,12 +687,24 @@ end @test all(df2.y .== [1, 0, 2, 1, 1, 0]) end @testset "Missing values" begin - df = DataFrame(x=[1, 2, missing, 3, 3, 3], y= [0, 0, 0, 1, 1, 1]) + df = DataFrame(x=[1, 2, missing, 3, 3, 3], y=[0, 0, 1, 1, 0, 1]) df2 = @with df @sort x - #@test all(df2.x .== [1, 2, 3, 3, 3, missing]) + @test all(df2.x[1:5] .== [1, 2, 3, 3, 3]) + @test ismissing(df2.x[6]) + @test all(df2.y .== [0, 0, 1, 0, 1, 1]) df2 = @with df @sort x y - #@test all(df2.x .== [1, 2, 3, 3, 3, missing]) - @test all(df2.y .== [0, 0, 1, 1, 1, 0]) + @test all(df2.x[1:5] .== [1, 2, 3, 3, 3]) + @test ismissing(df2.x[6]) + @test all(df2.y .== [0, 0, 0, 1, 1, 1]) + df2 = @with df @sort y + @test all(df2.x[1:3] .== [1, 2, 3]) + @test all(df2.x[5:6] .== [3, 3]) + @test ismissing(df2.x[4]) + @test all(df2.y .== [0, 0, 0, 1, 1, 1]) + df2 = @with df @sort y x + @test all(df2.x[1:5] .== [1, 2, 3, 3, 3]) + @test ismissing(df2.x[6]) + @test all(df2.y .== [0, 0, 0, 1, 1, 1]) end end @@ -720,3 +748,10 @@ end @test_throws Exception @with df @rename a b c end end + +@testset "Use" begin + df = DataFrame(x=1:10, y=11:20) + @use "test.dta", clear + @test df == getdf() + try @use "test.dta" @if x<5, clear; catch e; @test e isa LoadError; end +end \ No newline at end of file diff --git a/test/test.dta b/test/test.dta index df8a2ca20d7fed816c56ff95830894147d7fd692..00865f44f3ad428dafc93ad414296a2014a831cc 100644 GIT binary patch literal 1855 zcmeHIPiqrF6raX6X&bFZiy(*uMDgS#QLvTAs0bdc^derogh?{mh23VEnFMp{O}ywQ z5Ye+21wVk|&6D($PoSSbg(B9SeeanPSrDNYaS!>;`}g}z-ptzt=e5`Ep4SRCjP4n$ zz?#@-XH>Jf0+J2rjJ)aFkZ|kv4UiKP)>KJ=TvM>F76m>a*A>LNV`3$;7_PuaiOKYm zRMncR^_zpZ-fFZi)?3ZXja877C`jH)qSK53pJ#+8W^kbh@08F^3BM4YnnnNnGU6w~ zN(JrXgck^}5P}SoN|VwO`ZKI^+3G%Tuy~}^#<|dwx16& zj3~K}zoUKR{v+zVIoJ$vee2`Mc{)3gzZ`I{ZxijEIrteqWOJTUG2Rh{%9e+5#>8?zMAn%n^f@VZK`cRFojRlQh zVHavvy!){w#M=~+^Up0j%*TZb$Jb9|=*iYx@GVn->(Y}?mx7B%Td>W1U$+ygK)6cB z$Ih3pH+h*O^Dw{qM)i+Tze?Gx!^k8dKfaZsa?pr+a%q(d(f-s z7Z5Cd01x8HFCchR{0d&Y>7jTMVNB*F-FC&xUIt~eu)n;#n0szV@_6?#mzSSom;`(3W+&)oh(vzZZvo%oQMjnPMFx4i#;dDO@} zDBA&5wgW|aU^;;6NG)1Qn+)FBir(&Q*;3dYgtd-rGp*>k#Y^)K#__v^g;&Q6Fc806 zQ!ZkYC&h`7V4%j?`((}k6#-i}qj@nrf{ScXG?;Une%!l$a%pMXT>yWL#Kxz=>t9cT zAo_^t=U=FPcxS88w-=2wsQP|$#*Q6x3cv1N^0Z)f7faw}Z*Of%cvA&_etE@vTFCV; z`}N+AxBuq6(|<#LcTw%~cs@_kbDdFsZ|}$Rg?;{tXK24S2_Qyp5D-AtJx~wR d>ghbIoeeV}#dJ_w3Tw^bo&(yBj)=qWh~Hq8VygfE