Skip to content

Commit

Permalink
added many expects to test_inheritance for conversions and for some v…
Browse files Browse the repository at this point in the history
…alue checking
  • Loading branch information
sckott committed Sep 5, 2013
1 parent ada8def commit c949693
Showing 1 changed file with 62 additions and 27 deletions.
89 changes: 62 additions & 27 deletions inst/tests/test_inheritance.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
})

0 comments on commit c949693

Please sign in to comment.