From c949693bc85f44c12c493c00dd82827b55370903 Mon Sep 17 00:00:00 2001 From: schamberlain Date: Wed, 4 Sep 2013 23:09:30 -0700 Subject: [PATCH] added many expects to test_inheritance for conversions and for some value checking --- inst/tests/test_inheritance.R | 89 ++++++++++++++++++++++++----------- 1 file changed, 62 insertions(+), 27 deletions(-) diff --git a/inst/tests/test_inheritance.R b/inst/tests/test_inheritance.R index 38bdaf3..e2da1df 100644 --- a/inst/tests/test_inheritance.R +++ b/inst/tests/test_inheritance.R @@ -6,46 +6,81 @@ context("inheritance") ## Add tests to check values on some nodes/attributes... test_that("we can perform simple conversions between NeXML XML and S4", { -require(XML) -require(RNeXML) -# basic example -node <- newXMLNode("meta", - attrs = c(id="dict1", - property="cdao:has_tag", - content="true", - 'xsi:type'="nex:LiteralMeta", - datatype="xsd:boolean"), - suppressNamespaceWarning=TRUE) -n2 <- newXMLNode("node", - attrs = c(id = "n4", - label="n4", - about="#n4"), - .children = node) - -# check conversions to/from NeXML - s4 <- as(n2, "node") - as(s4, "XMLInternalNode") + require(XML) + require(RNeXML) + # basic example + node <- newXMLNode("meta", + attrs = c(id="dict1", + property="cdao:has_tag", + content="true", + 'xsi:type'="nex:LiteralMeta", + datatype="xsd:boolean"), + suppressNamespaceWarning=TRUE) + n2 <- newXMLNode("node", + attrs = c(id = "n4", + label="n4", + about="#n4"), + .children = node) + + # check conversions to/from NeXML + s4 <- as(n2, "node") + xmlfroms4 <- as(s4, "XMLInternalNode") + expect_that(identical(n2, xmlfroms4), is_true()) }) - - -## Should be separate unit tests here to facilitate debugging... - -test_that("We can parse a complete NeXML file and toggle back and forth between XML and S4", { +# test_that("We can parse a complete NeXML file and toggle back and forth between XML and S4", { +test_that("Parse a complete NeXML file to a single otu", { doc <- xmlParse(system.file("examples", "trees.xml", package="RNeXML")) root <- xmlRoot(doc) -# check conversions otu <- as(root[["otus"]][[1]], "otu") + expect_that(otu, is_a("otu")) as(otu, "XMLInternalNode") +}) +test_that("Parse a complete NeXML file to trees", { trees <- as(root[["trees"]], "trees") + expect_that(trees, is_a("trees")) as(trees, "XMLInternalNode") +}) +test_that("Parse a complete NeXML file to many otus", { otus <- as(root[["otus"]], "otus") - as(otus, "XMLInternalNode") - + expect_that(otus, is_a("otus")) + tt <- as(otus, "XMLInternalNode") + expect_that(tt, is_a("XMLInternalNode")) +}) +test_that("Parse a complete NeXML file to xmlinternalnode", { parsed <- as(root, "nexml") + expect_that(parsed, is_a("nexml")) serialized <- as(parsed, "XMLInternalNode") + expect_that(serialized, is_a("XMLInternalNode")) }) + +test_that("Check that values are correct in the otu class element", { + otu <- as(root[["otus"]][[1]], "otu") + expect_that(otu@id[[1]], equals("t1")) + expect_that(otu@label[[1]], equals("species 1")) + expect_that(otu@meta, is_a("list")) + expect_that(otu@about, is_identical_to(character(0))) +}) + +test_that("Check that values are correct in the trees class element", { + trees <- as(root[["trees"]], "trees") + expect_that(trees@tree, is_a("ListOftree")) + expect_that(trees@otus[[1]], equals("tax1")) + expect_that(trees@id[[1]], equals("Trees")) + expect_that(trees@label[[1]], equals("TreesBlockFromXML")) + expect_that(trees@meta, is_a("list")) + expect_that(trees@about, is_identical_to(character(0))) +}) + +test_that("Check that values are correct in the otus class element", { + otus <- as(root[["otus"]], "otus") + expect_that(otus@otu, is_a("ListOfotu")) + expect_that(otus@id[[1]], equals("tax1")) + expect_that(otus@label[[1]], equals("RootTaxaBlock")) + expect_that(otus@meta, is_a(class=c("list","ListOfmeta"))) + expect_that(otus@about, is_identical_to(character(0))) +}) \ No newline at end of file