diff --git a/.covrignore b/.covrignore index 5c0d0af..e02fd5e 100644 --- a/.covrignore +++ b/.covrignore @@ -1,5 +1,4 @@ ./R/entities.R -./R/HashTable.R ./R/Lrner.R ./R/Model.R ./R/NewData.R diff --git a/R/HashTable.R b/R/HashTable.R index 2076698..af707f3 100644 --- a/R/HashTable.R +++ b/R/HashTable.R @@ -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. @@ -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. #' diff --git a/tests/testthat/test-HashTable.R b/tests/testthat/test-HashTable.R index 81638a9..107bfb2 100644 --- a/tests/testthat/test-HashTable.R +++ b/tests/testthat/test-HashTable.R @@ -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")) })