1
1
# test struct object
2
2
test_that(' struct objects can be created and modified' ,{
3
3
# a test object
4
- test_object = struct_class(name = ' test_name' , description = ' test_desc' ,' type' = ' test_type' )
5
-
4
+ test_object = struct_class(
5
+ name = ' test_name' ,
6
+ description = c(
7
+ ' A' = ' test_desc_A' ,
8
+ ' B' = ' test_desc_B' ),
9
+ type = ' test_type' ,
10
+ citations = bibentry(
11
+ bibtype = ' Article' ,
12
+ year = 2009 ,
13
+ volume = 95 ,
14
+ number = 2 ,
15
+ pages = ' 122-128' ,
16
+ author = as.person(" Nestor F. Perez and Joan Ferre and Ricard Boque" ),
17
+ title = paste0(' Calculation of the reliability of ' ,
18
+ ' classification in discriminant partial least-squares ' ,
19
+ ' binary classification' ),
20
+ journal = " Chemometrics and Intelligent Laboratory Systems"
21
+ ),
22
+ ontology = ' STATO:0000572'
23
+
24
+ )
25
+
6
26
# name
7
27
expect_equal({test_object $ name },' test_name' ) # get
8
28
expect_equal({test_object $ name = ' cabbage' ;test_object $ name },' cabbage' ) # set
9
29
# type
10
30
expect_equal({test_object $ type },' test_type' ) # get
11
31
expect_equal({test_object $ type = ' cabbage' ;test_object $ type },' cabbage' ) # set
12
32
# description
13
- expect_equal({test_object $ description }," test_desc" ) # get
33
+ expect_equal({test_object $ description },c(
34
+ ' A' = ' test_desc_A' ,
35
+ ' B' = ' test_desc_B' )) # get
36
+ expect_output(show(test_object ),' A "struct_class" object' )
14
37
expect_equal({test_object $ description = ' cabbage' ;test_object $ description },' cabbage' ) # set
15
38
# show
16
- expect_output(show(test_object ),' A "struct_class" object\\ n-----------------------\\ nname: cabbage\\ ndescription: cabbage' )
39
+ expect_output(show(test_object ),' A "struct_class" object' )
40
+
41
+ expect_error({
42
+ test_object = struct_class(name = ' test_name' , description = ' test_desc' ,' type' = ' test_type' ,
43
+ citations = list (bibentry(
44
+ bibtype = ' Article' ,
45
+ year = 2009 ,
46
+ volume = 95 ,
47
+ number = 2 ,
48
+ pages = ' 122-128' ,
49
+ author = as.person(" Nestor F. Perez and Joan Ferre and Ricard Boque" ),
50
+ title = paste0(' Calculation of the reliability of ' ,
51
+ ' classification in discriminant partial least-squares ' ,
52
+ ' binary classification' ),
53
+ journal = " Chemometrics and Intelligent Laboratory Systems"
54
+ ),
55
+ ' cake'
56
+
57
+ ))
58
+ })
59
+
60
+ cit = citations(test_object )
61
+ expect_true(length(cit )== 2 )
62
+ lib = libraries(test_object )
63
+ expect_true(length(lib )== 0 )
64
+ ont = ontology(test_object ,cache = list (
65
+ ' STATO:0000572' = ontology_term(
66
+ id = ' STATO:0000572' ,
67
+ ontology = ' stato' ,
68
+ label = ' test_ontology' ,
69
+ description = ' test_ontology' ,
70
+ iri = ' test_ontology' ,
71
+ rols = FALSE
72
+ )
73
+ )
74
+ )
75
+ expect_true(length(ont )== 1 )
76
+
77
+
17
78
})
18
79
19
80
# test metric object
@@ -29,16 +90,20 @@ test_that('entity object',{
29
90
E = entity(type = ' numeric' ,value = 0 ,name = ' test_enti' )
30
91
value(E )= 1
31
92
expect_equal(value(E ),1 )
93
+ max_length(E )= 1
94
+ expect_output(show(E ),regexp = ' A "entity" object' )
32
95
})
33
96
34
97
# test enum
35
98
test_that(' enum object' ,{
36
99
E = enum(allowed = c(' hello' ,' world' ),value = ' hello' ,type = ' character' ,name = ' test_entity' )
37
- # check object creation
100
+ # check object creationS
38
101
expect_equal(value(E ),' hello' )
39
102
# check throws error if value not in list
40
103
expect_error({value(E )= ' banana' },' not a valid choice for this enum' )
41
104
# check assign value
42
105
value(E )= ' world'
43
106
expect_equal(value(E ),' world' )
107
+ expect_output(show(E ),regexp = ' A "enum" object' )
44
108
})
109
+
0 commit comments