1 context("CollectionTree")
3 test_that("constructor creates file tree from character array properly", {
5 collection <- "myCollection"
6 characterArray <- c("animal",
10 collectionTree <- CollectionTree$new(characterArray, collection)
12 root <- collectionTree$getTree()
13 animal <- collectionTree$getElement("animal")
14 dog <- collectionTree$getElement("animal/dog")
15 boat <- collectionTree$getElement("boat")
17 rootHasNoParent <- is.null(root$getParent())
18 rootIsOfTypeSubcollection <- "Subcollection" %in% class(root)
19 animalIsOfTypeSubcollection <- "Subcollection" %in% class(animal)
20 dogIsOfTypeArvadosFile <- "ArvadosFile" %in% class(dog)
21 boatIsOfTypeArvadosFile <- "ArvadosFile" %in% class(boat)
22 animalsParentIsRoot <- animal$getParent()$getName() == root$getName()
23 animalContainsDog <- animal$getFirst()$getName() == dog$getName()
24 dogsParentIsAnimal <- dog$getParent()$getName() == animal$getName()
25 boatsParentIsRoot <- boat$getParent()$getName() == root$getName()
27 allElementsBelongToSameCollection <- root$getCollection() == "myCollection" &&
28 animal$getCollection() == "myCollection" &&
29 dog$getCollection() == "myCollection" &&
30 boat$getCollection() == "myCollection"
32 expect_that(root$getName(), equals(""))
33 expect_that(rootIsOfTypeSubcollection, is_true())
34 expect_that(rootHasNoParent, is_true())
35 expect_that(animalIsOfTypeSubcollection, is_true())
36 expect_that(animalsParentIsRoot, is_true())
37 expect_that(animalContainsDog, is_true())
38 expect_that(dogIsOfTypeArvadosFile, is_true())
39 expect_that(dogsParentIsAnimal, is_true())
40 expect_that(boatIsOfTypeArvadosFile, is_true())
41 expect_that(boatsParentIsRoot, is_true())
42 expect_that(allElementsBelongToSameCollection, is_true())
45 test_that("getElement returns element from tree if element exists on specified path", {
47 collection <- "myCollection"
48 characterArray <- c("animal",
52 collectionTree <- CollectionTree$new(characterArray, collection)
54 dog <- collectionTree$getElement("animal/dog")
56 expect_that(dog$getName(), equals("dog"))
59 test_that("getElement returns NULL from tree if element doesn't exists on specified path", {
61 collection <- "myCollection"
62 characterArray <- c("animal",
66 collectionTree <- CollectionTree$new(characterArray, collection)
68 fish <- collectionTree$getElement("animal/fish")
69 fishIsNULL <- is.null(fish)
71 expect_that(fishIsNULL, is_true())
74 test_that("getElement trims ./ from start of relativePath", {
76 collection <- "myCollection"
77 characterArray <- c("animal",
81 collectionTree <- CollectionTree$new(characterArray, collection)
83 dog <- collectionTree$getElement("animal/dog")
84 dogWithDotSlash <- collectionTree$getElement("./animal/dog")
86 expect_that(dogWithDotSlash$getName(), equals(dog$getName()))
89 test_that("getElement trims / from end of relativePath", {
91 collection <- "myCollection"
92 characterArray <- c("animal",
96 collectionTree <- CollectionTree$new(characterArray, collection)
98 animal <- collectionTree$getElement("animal")
99 animalWithSlash <- collectionTree$getElement("animal/")
101 expect_that(animalWithSlash$getName(), equals(animal$getName()))