tests/testthat/test-pga_results.R

# sportsR - A Comprehensive Collection of Sports and Athletics Datasets
# Version 0.1.0
# Copyright (C) 2026 Renzo Caceres Rossi
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

# pga_results

library(testthat)

# Test 1: Check that the object is a data.frame and has 34 columns
test_that("pga_results is a data.frame with 34 columns", {
  expect_s3_class(pga_results, "data.frame")
  expect_equal(ncol(pga_results), 34)
  expect_equal(length(pga_results), 34)
})

# Test 2: Check the number of rows
test_that("pga_results has 3676 rows", {
  expect_equal(nrow(pga_results), 3676)
})

# Test 3: Validate column names
test_that("pga_results has correct column names", {
  expect_named(
    pga_results,
    c("Player_initial_last", "tournament.id", "player.id", "hole_par",
      "strokes", "hole_DKP", "hole_FDP", "hole_SDP", "streak_DKP",
      "streak_FDP", "streak_SDP", "n_rounds", "made_cut", "pos",
      "finish_DKP", "finish_FDP", "finish_SDP", "total_DKP", "total_FDP",
      "total_SDP", "player", "tournament.name", "course", "date",
      "purse", "season", "no_cut", "Finish", "sg_putt", "sg_arg",
      "sg_app", "sg_ott", "sg_t2g", "sg_total")
  )
})

# Test 4: Check data types
test_that("pga_results has correct data types", {
  expect_type(pga_results$Player_initial_last, "character")
  expect_type(pga_results$tournament.id, "integer")
  expect_type(pga_results$player.id, "integer")
  expect_type(pga_results$hole_par, "integer")
  expect_type(pga_results$strokes, "integer")
  expect_type(pga_results$hole_DKP, "double")
  expect_type(pga_results$hole_FDP, "double")
  expect_type(pga_results$hole_SDP, "integer")
  expect_type(pga_results$streak_DKP, "integer")
  expect_type(pga_results$streak_FDP, "double")
  expect_type(pga_results$streak_SDP, "integer")
  expect_type(pga_results$n_rounds, "integer")
  expect_type(pga_results$made_cut, "integer")
  expect_type(pga_results$pos, "integer")
  expect_type(pga_results$finish_DKP, "integer")
  expect_type(pga_results$finish_FDP, "integer")
  expect_type(pga_results$finish_SDP, "integer")
  expect_type(pga_results$total_DKP, "double")
  expect_type(pga_results$total_FDP, "double")
  expect_type(pga_results$total_SDP, "integer")
  expect_type(pga_results$player, "character")
  expect_type(pga_results$tournament.name, "character")
  expect_type(pga_results$course, "character")
  expect_type(pga_results$date, "character")
  expect_type(pga_results$purse, "double")
  expect_type(pga_results$season, "integer")
  expect_type(pga_results$no_cut, "integer")
  expect_type(pga_results$Finish, "character")
  expect_type(pga_results$sg_putt, "double")
  expect_type(pga_results$sg_arg, "double")
  expect_type(pga_results$sg_app, "double")
  expect_type(pga_results$sg_ott, "double")
  expect_type(pga_results$sg_t2g, "double")
  expect_type(pga_results$sg_total, "double")
})

Try the sportsR package in your browser

Any scripts or data that you put into this service are public.

sportsR documentation built on Aug. 27, 2026, 1:08 a.m.