1+ # -------------------------------------------------------------------------------
2+ # Copyright (c) 2019-2022 University of Newcastle upon Tyne. All rights reserved.
3+ # Copyright (c) 2022-2025 Arjuna Technologies, Newcastle upon Tyne. All rights reserved.
4+ #
5+ # This program and the accompanying materials
6+ # are made available under the terms of the GNU Public License v3.0.
7+ #
8+ # You should have received a copy of the GNU General Public License
9+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
10+ # -------------------------------------------------------------------------------
11+
12+ #
13+ # Set up
14+ #
15+
16+ # context("colnamesDS::smk::setup")
17+
18+ #
19+ # Tests
20+ #
21+
22+ # context("colnamesDS::smk::data.frame")
23+ test_that(" simple colnamesDS, data.frame" , {
24+ input <- data.frame (v1 = c(0.0 , 1.0 , 2.0 , 3.0 , 4.0 ), v2 = c(4.0 , 3.0 , 2.0 , 1.0 , 0.0 ))
25+
26+ res <- colnamesDS(" input" )
27+
28+ expect_equal(class(res ), " character" )
29+ expect_length(res , 2 )
30+ expect_true(" v1" %in% res )
31+ expect_true(" v2" %in% res )
32+ })
33+
34+ # context("colnamesDS::smk::data.matrix")
35+ test_that(" simple colnamesDS, data.matrix" , {
36+ input <- data.matrix(data.frame (v1 = c(0.0 , 1.0 , 2.0 , 3.0 , 4.0 ), v2 = c(4.0 , 3.0 , 2.0 , 1.0 , 0.0 )))
37+
38+ res <- colnamesDS(" input" )
39+
40+ expect_equal(class(res ), " character" )
41+ expect_length(res , 2 )
42+ expect_true(" v1" %in% res )
43+ expect_true(" v2" %in% res )
44+ })
45+
46+ test_that(" colnamesDS throws error when object does not exist" , {
47+ expect_error(
48+ colnamesDS(" nonexistent_object" ),
49+ regexp = " does not exist"
50+ )
51+ })
52+
53+ test_that(" colnamesDS throws error when object is not data.frame or matrix" , {
54+ bad_input <- list (a = 1 : 3 , b = 4 : 6 )
55+ expect_error(
56+ colnamesDS(" bad_input" ),
57+ regexp = " must be of type data.frame or matrix"
58+ )
59+ })
60+
61+ #
62+ # Done
63+ #
64+
65+ # context("colnamesDS::smk::shutdown")
66+
67+ # context("colnamesDS::smk::done")
0 commit comments