Skip to content

Commit

Permalink
HashTable: 100% test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
fouodo committed Jul 19, 2024
1 parent 9a56124 commit 7d3929b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 15 deletions.
1 change: 0 additions & 1 deletion .covrignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
./R/entities.R
./R/HashTable.R
./R/Lrner.R
./R/Model.R
./R/NewData.R
Expand Down
25 changes: 13 additions & 12 deletions R/HashTable.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ HashTable <- R6Class("HashTable",
parent = emptyenv())
},
#' @description
#' Printer
#' @param ... (any) \cr
#'
#' @export
#'
print = function (...) {
cat("Class: HashTable\n")
cat(sprintf("id: %s\n", private$id))
cat("-----------------\n")
print(private$key_class)
},
#' @description
#' Function to add a key-value pair to the hash table.
#' @param key (`character(1)`) \cr
#' The key to be added.
Expand Down Expand Up @@ -93,18 +105,7 @@ HashTable <- R6Class("HashTable",
}
invisible(TRUE)
},
#' @description
#' Printer
#' @param ... (any) \cr
#'
#' @export
#'
print = function (...) {
cat("Class: HashTable\n")
cat(sprintf("id: %s\n", private$id))
cat("-----------------\n")
print(private$key_class)
},

#' @description
#' Getter of the current object ID.
#'
Expand Down
46 changes: 44 additions & 2 deletions tests/testthat/test-HashTable.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,45 @@
test_that("A hash table can be created", {
expect_s3_class(HashTable$new(id = "test"), "HashTable")
hashtable <- HashTable$new(id = "test")

test_that("HashTable: initialize", {
expect_s3_class(hashtable, "HashTable")
print(hashtable)
})

test_that("HashTable: add2HashTable", {
expect_no_error(hashtable$add2HashTable(key = "obj1",
value = 2L,
.class = "test"))
expect_no_error(hashtable$add2HashTable(key = "obj1",
value = 2L,
.class = "test"))
expect_no_error(hashtable$add2HashTable(key = "obj1",
value = 2L,
.class = "test2"))
})

test_that("HashTable: getFromHashTable", {
expect_no_error(hashtable$getFromHashTable(key = "obj1"))
expect_no_error(hashtable$getFromHashTable(key = "notexists"))
})

test_that("HashTable: getKeyClass", {
expect_no_error(hashtable$getKeyClass())
})

test_that("HashTable: removeFromHashTable", {
expect_no_error(hashtable$removeFromHashTable(key = "obj1"))
expect_no_error(hashtable$getFromHashTable(key = "notexists"))
})

test_that("HashTable: getId", {
expect_no_error(hashtable$getId())
})

test_that("HashTable: getHashTable", {
expect_no_error(hashtable$getHashTable())
})


test_that("HashTable: checkClassExist", {
expect_no_error(hashtable$checkClassExist(.class = "notexists"))
})

0 comments on commit 7d3929b

Please sign in to comment.