Skip to content

Commit

Permalink
Merge pull request #8 from ShouvikGhosh2048/adding-tests
Browse files Browse the repository at this point in the history
Added basic tests
  • Loading branch information
ayushpatnaikgit authored Jun 2, 2022
2 parents b224fd3 + 7f8f755 commit e66244f
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 3 deletions.
5 changes: 5 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[deps]
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
RDatasets = "ce6b1742-4840-55fa-b093-852dadbb1d8b"
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
17 changes: 17 additions & 0 deletions test/basic/LinearRegression.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
mtcars = dataset("datasets", "mtcars")

priors = [
Prior_Ridge(),
Prior_Laplace(),
Prior_Cauchy(),
Prior_TDist(),
Prior_Uniform(),
]

model = @fitmodel((MPG ~ HP + WT + Gear), mtcars, LinearRegression())
@test sizeof(model) > 0

for prior in priors
model = @fitmodel((MPG ~ HP + WT + Gear), mtcars, LinearRegression(), prior)
@test sizeof(model) > 0
end
25 changes: 25 additions & 0 deletions test/basic/LogisticRegression.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
turnout = dataset("Zelig", "turnout")[1:100,:] # Take a subset of rows to reduce input size

links = [Logit(), Probit(), Cloglog(), Cauchit()]

priors = [
Prior_Ridge(),
Prior_Laplace(),
Prior_Cauchy(),
Prior_TDist(),
Prior_Uniform(),
]

for link in links
CRRao.set_rng(StableRNG(123))
model = @fitmodel((Vote ~ Age + Race + Income + Educate), turnout, LogisticRegression(), link)
@test sizeof(model) > 0
end

for prior in priors
for link in links
CRRao.set_rng(StableRNG(123))
model = @fitmodel((Vote ~ Age + Race + Income + Educate), turnout, LogisticRegression(), link, prior)
@test sizeof(model) > 0
end
end
19 changes: 19 additions & 0 deletions test/basic/NegBinomialRegression.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
sanction = dataset("Zelig", "sanction")

priors = [
Prior_Ridge(),
Prior_Laplace(),
Prior_Cauchy(),
Prior_TDist(),
Prior_Uniform(),
]

CRRao.set_rng(StableRNG(123))
model = @fitmodel((Num ~ Target + Coop + NCost), sanction, NegBinomRegression())
@test sizeof(model) > 0

for prior in priors
CRRao.set_rng(StableRNG(123))
model = @fitmodel((Num ~ Target + Coop + NCost), sanction, NegBinomRegression(), prior)
@test sizeof(model) > 0
end
17 changes: 17 additions & 0 deletions test/basic/PoissonRegression.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
sanction = dataset("Zelig", "sanction")

priors = [
Prior_Ridge(),
Prior_Laplace(),
Prior_Cauchy(),
Prior_TDist(),
Prior_Uniform(),
]

model = @fitmodel((Num ~ Target + Coop + NCost), sanction, PoissonRegression())
@test sizeof(model) > 0

for prior in priors
model = @fitmodel((Num ~ Target + Coop + NCost), sanction, PoissonRegression(), prior)
@test sizeof(model) > 0
end
26 changes: 23 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
using CRRao
using Test
using CRRao, Test, StableRNGs, Logging, RDatasets

Logging.disable_logging(Logging.Warn)

CRRao.setprogress!(false)
CRRao.set_rng(StableRNG(123))

@testset "CRRao.jl" begin
# Write your tests here.
@testset "Basic Tests" begin
@testset "Linear Regression" begin
include("basic/LinearRegression.jl")
end

@testset "Logistic Regression" begin
include("basic/LogisticRegression.jl")
end

@testset "Poisson Regression" begin
include("basic/PoissonRegression.jl")
end

@testset "Negative Binomial Regression" begin
include("basic/NegBinomialRegression.jl")
end
end
end

0 comments on commit e66244f

Please sign in to comment.