@@ -35,12 +35,14 @@ test_that("ped2graph produces a graph for inbreeding data", {
3535
3636
3737test_that(" ped2add produces correct matrix dims, values, and dimnames for hazard" , {
38+ tolerance <- 1e-10
3839 data(hazard )
3940 add <- ped2add(hazard )
4041 # Check dimension
4142 expect_equal(dim(add ), c(nrow(hazard ), nrow(hazard )))
4243 # Check several values
43- expect_true(all(diag(add ) == 1 ))
44+ # expect_true(all(diag(add) == 1))
45+ expect_true(sum((diag(add ) - 1 )^ 2 ) < tolerance )
4446 expect_equal(add , t(add ))
4547 expect_equal(add [2 , 1 ], 0 )
4648 expect_equal(add [10 , 1 ], .25 )
@@ -53,16 +55,18 @@ test_that("ped2add produces correct matrix dims, values, and dimnames for hazard
5355})
5456
5557test_that(" ped2add produces correct matrix dims, values, and dimnames for alternative transpose" , {
58+ tolerance <- 1e-10
5659 data(hazard )
5760 add <- ped2add(hazard , tcross.alt.crossprod = TRUE )
5861 # Check dimension
59- expect_equal(dim(add ), c(nrow(hazard ), nrow(hazard )))
62+ expect_equal(dim(add ), c(nrow(hazard ), nrow(hazard )), tolerance = tolerance )
6063 # Check several values
61- expect_true(all(diag(add ) == 1 ))
62- expect_equal(add , t(add ))
63- expect_equal(add [2 , 1 ], 0 )
64- expect_equal(add [10 , 1 ], .25 )
65- expect_equal(add [9 , 1 ], 0 )
64+ # expect_true(all(diag(add) == 1))
65+ expect_true(sum((diag(add ) - 1 )^ 2 ) < tolerance )
66+ expect_equal(add , t(add ),tolerance = tolerance )
67+ expect_equal(add [2 , 1 ], 0 ,tolerance = tolerance )
68+ expect_equal(add [10 , 1 ], .25 ,tolerance = tolerance )
69+ expect_equal(add [9 , 1 ], 0 ,tolerance = tolerance )
6670 expect_equal(add [" 5" , " 6" ], .5 )
6771 # Check that dimnames are correct
6872 dn <- dimnames(add )
@@ -72,16 +76,17 @@ test_that("ped2add produces correct matrix dims, values, and dimnames for altern
7276# to do, combine the sets that are equalivant. shouldn't need to run 1000 expect equals
7377
7478test_that(" ped2add produces correct matrix dims, values, and dimnames for inbreeding data" , {
79+ tolerance <- 1e-10
7580 data(inbreeding )
7681 add <- ped2add(inbreeding )
7782 # Check dimension
78- expect_equal(dim(add ), c(nrow(inbreeding ), nrow(inbreeding )))
83+ expect_equal(dim(add ), c(nrow(inbreeding ), nrow(inbreeding )), tolerance = tolerance )
7984 # Check several values
80- expect_true(all(diag(add ) > = 1 ))
81- expect_equal(add , t(add ))
82- expect_equal(add [2 , 1 ], 0 )
83- expect_equal(add [6 , 1 ], .5 )
84- expect_equal(add [113 , 113 ], 1.1250 )
85+ expect_true(all(diag(add ) > = 1 - tolerance ))
86+ expect_equal(add , t(add ), tolerance = tolerance )
87+ expect_equal(add [2 , 1 ], 0 , tolerance = tolerance )
88+ expect_equal(add [6 , 1 ], .5 , tolerance = tolerance )
89+ expect_equal(add [113 , 113 ], 1.1250 , tolerance = tolerance )
8590 expect_equal(add [" 113" , " 112" ], 0.62500 )
8691 # Check that dimnames are correct
8792 dn <- dimnames(add )
@@ -91,89 +96,99 @@ test_that("ped2add produces correct matrix dims, values, and dimnames for inbree
9196
9297
9398test_that(" ped2add produces correct matrix dims, values, and dimnames for inbreeding data with alternative transpose" , {
99+ tolerance <- 1e-10
94100 data(inbreeding )
95101 add <- ped2add(inbreeding , tcross.alt.star = TRUE )
96102 # Check dimension
97103 expect_equal(dim(add ), c(nrow(inbreeding ), nrow(inbreeding )))
98104 # Check several values
99105 expect_true(all(diag(add ) > = 1 ))
100- expect_equal(add , t(add ))
101- expect_equal(add [2 , 1 ], 0 )
102- expect_equal(add [6 , 1 ], .5 )
103- expect_equal(add [113 , 113 ], 1.1250 )
106+ expect_equal(add , t(add ), tolerance = tolerance )
107+ expect_equal(add [2 , 1 ], 0 , tolerance = tolerance )
108+ expect_equal(add [6 , 1 ], .5 , tolerance = tolerance )
109+ expect_equal(add [113 , 113 ], 1.1250 , tolerance = tolerance )
104110 expect_equal(add [" 113" , " 112" ], 0.62500 )
105111 # Check that dimnames are correct
106112 dn <- dimnames(add )
107113 expect_equal(dn [[1 ]], dn [[2 ]])
108114 expect_equal(dn [[1 ]], as.character(inbreeding $ ID ))
109115})
110116test_that(" ped2add flattens diagonal for inbreeding data" , {
117+ tolerance <- 1e-10
111118 data(inbreeding )
112119 add <- ped2add(inbreeding , flatten.diag = TRUE )
113120 # Check dimension
114- expect_equal(dim(add ), c(nrow(inbreeding ), nrow(inbreeding )))
121+ expect_equal(dim(add ), c(nrow(inbreeding ), nrow(inbreeding )), tolerance = tolerance )
115122 # Check several values
116- expect_true(all(diag(add ) == 1 ))
117- expect_equal(add , t(add ))
118- expect_equal(add [2 , 1 ], 0 )
119- expect_equal(add [6 , 1 ], .5 )
120- expect_equal(add [113 , 113 ], 1 )
123+ # expect_true(all(diag(add) == 1))
124+ expect_true(sum((diag(add ) - 1 )^ 2 ) < tolerance )
125+ expect_equal(add , t(add ), tolerance = tolerance )
126+ expect_equal(add [2 , 1 ], 0 , tolerance = tolerance )
127+ expect_equal(add [6 , 1 ], .5 , tolerance = tolerance )
128+ expect_equal(add [113 , 113 ], 1 , tolerance = tolerance )
121129 expect_equal(add [" 113" , " 112" ], 0.62500 )
122130 # Check that dimnames are correct
123131 dn <- dimnames(add )
124132 expect_equal(dn [[1 ]], dn [[2 ]])
125133 expect_equal(dn [[1 ]], as.character(inbreeding $ ID ))
126134})
127135test_that(" ped2mit produces correct matrix dims, values, and dimnames for inbreeding" , {
136+ tolerance <- 1e-10
128137 # Check dimension
129138 data(inbreeding )
130139 mit <- ped2mit(inbreeding )
131140 # Check dimension
132141 expect_equal(dim(mit ), c(nrow(inbreeding ), nrow(inbreeding )))
133142 # Check several values
134- expect_true(all(diag(mit ) == 1 ))
135- expect_equal(mit , t(mit ))
136- expect_equal(mit [2 , 1 ], 0 )
137- expect_equal(mit [6 , 1 ], 1 )
138- expect_equal(mit [113 , 113 ], 1 )
139- expect_equal(mit [" 113" , " 112" ], 1 )
143+ # expect_true(all(diag(mit) == 1))
144+ expect_true(sum((diag(mit ) - 1 )^ 2 ) < tolerance )
145+ expect_equal(mit , t(mit ), tolerance = tolerance )
146+ expect_equal(mit [2 , 1 ], 0 , tolerance = tolerance )
147+ expect_equal(mit [6 , 1 ], 1 , tolerance = tolerance )
148+ expect_equal(mit [113 , 113 ], 1 , tolerance = tolerance )
149+ expect_equal(mit [" 113" , " 112" ], 1 , tolerance = tolerance )
140150 # Check that dimnames are correct
141151 dn <- dimnames(mit )
142152 expect_equal(dn [[1 ]], dn [[2 ]])
143153 expect_equal(dn [[1 ]], as.character(inbreeding $ ID ))
144154})
145155
146156test_that(" ped2mit produces correct matrix dims, values, and dimnames for inbreeding" , {
157+ tolerance <- 1e-10
147158 # Check dimension
148159 data(inbreeding )
149160 mit <- ped2mit(inbreeding )
150161 # Check dimension
151- expect_equal(dim(mit ), c(nrow(inbreeding ), nrow(inbreeding )))
162+ expect_equal(dim(mit ), c(nrow(inbreeding ), nrow(inbreeding )), tolerance = tolerance )
152163 # Check several values
153- expect_true(all(diag(mit ) == 1 ))
154- expect_equal(mit , t(mit ))
155- expect_equal(mit [2 , 1 ], 0 )
156- expect_equal(mit [6 , 1 ], 1 )
157- expect_equal(mit [113 , 113 ], 1 )
158- expect_equal(mit [" 113" , " 112" ], 1 )
164+ # expect_true(all(diag(mit) == 1))
165+ expect_true(sum((diag(mit ) - 1 )^ 2 ) < tolerance )
166+ expect_equal(mit , t(mit ), tolerance = tolerance )
167+ expect_equal(mit [2 , 1 ], 0 , tolerance = tolerance )
168+ expect_equal(mit [6 , 1 ], 1 , tolerance = tolerance )
169+ expect_equal(mit [113 , 113 ], 1 , tolerance = tolerance )
170+ expect_equal(mit [" 113" , " 112" ], 1 , tolerance = tolerance )
159171 # Check that dimnames are correct
160172 dn <- dimnames(mit )
161173 expect_equal(dn [[1 ]], dn [[2 ]])
162174 expect_equal(dn [[1 ]], as.character(inbreeding $ ID ))
163175})
164176
165177test_that(" ped2cn produces correct matrix dims, values, and dimnames" , {
166- # # Check dimension
178+ tolerance <- 1e-10
179+
180+ # Check dimension
167181 data(inbreeding )
168182 cn <- ped2cn(inbreeding )
169- expect_equal(dim(cn ), c(nrow(inbreeding ), nrow(inbreeding )))
183+ expect_equal(dim(cn ), c(nrow(inbreeding ), nrow(inbreeding )), tolerance = tolerance )
170184 # Check several values
171- expect_true(all(diag(cn ) == 1 ))
172- expect_equal(cn , t(cn ))
173- expect_equal(cn [2 , 1 ], 0 )
174- expect_equal(cn [6 , 1 ], 0 )
175- expect_equal(cn [113 , 113 ], 1 )
176- expect_equal(cn [" 113" , " 112" ], 1 )
185+ # expect_true(all(diag(cn) == 1))
186+ expect_true(sum((diag(cn ) - 1 )^ 2 ) < tolerance )
187+ expect_equal(cn , t(cn ), tolerance = tolerance )
188+ expect_equal(cn [2 , 1 ], 0 , tolerance = tolerance )
189+ expect_equal(cn [6 , 1 ], 0 , tolerance = tolerance )
190+ expect_equal(cn [113 , 113 ], 1 , tolerance = tolerance )
191+ expect_equal(cn [" 113" , " 112" ], 1 , tolerance = tolerance )
177192 # Check that dimnames are correct
178193 dn <- dimnames(cn )
179194 expect_equal(dn [[1 ]], dn [[2 ]])
@@ -182,16 +197,18 @@ test_that("ped2cn produces correct matrix dims, values, and dimnames", {
182197})
183198
184199test_that(" ped2ce produces correct matrix dims, values, and dimnames" , {
200+ tolerance <- 1e-10
185201 data(inbreeding )
186202 ce <- ped2ce(inbreeding )
187- expect_equal(dim(ce ), c(nrow(inbreeding ), nrow(inbreeding )))
203+ expect_equal(dim(ce ), c(nrow(inbreeding ), nrow(inbreeding )), tolerance = tolerance )
188204 # Check several values
189- expect_true(all(diag(ce ) == 1 ))
190- expect_equal(ce , t(ce ))
191- expect_equal(ce [2 , 1 ], 1 )
192- expect_equal(ce [6 , 1 ], 1 )
193- expect_equal(ce [113 , 113 ], 1 )
194- expect_equal(ce [" 113" , " 112" ], 1 )
205+ # expect_true(all(diag(ce) == 1))
206+ expect_true(sum((diag(ce ) - 1 )^ 2 ) < tolerance )
207+ expect_equal(ce , t(ce ), tolerance = tolerance )
208+ expect_equal(ce [2 , 1 ], 1 , tolerance = tolerance )
209+ expect_equal(ce [6 , 1 ], 1 , tolerance = tolerance )
210+ expect_equal(ce [113 , 113 ], 1 , tolerance = tolerance )
211+ expect_equal(ce [" 113" , " 112" ], 1 , tolerance = tolerance )
195212 # Check that dimnames are correct
196213 dn <- dimnames(ce )
197214 expect_equal(dn [[1 ]], dn [[2 ]])
@@ -207,6 +224,7 @@ test_that("ped2add verbose prints updates", {
207224
208225test_that(" ped2maternal/paternal produces correct matrix dims" , {
209226 data(hazard )
227+ tolerance <- 1e-10
210228 mat <- ped2maternal(hazard )
211229 expect_equal(dim(mat ), c(nrow(hazard ), ncol(hazard ) + 1 ))
212230 data(hazard )
0 commit comments