annotate src/test-Utility/test-Utility.R @ 0:e0b5980139d9

maaslin
author george-weingart
date Tue, 13 May 2014 22:00:40 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
1 c_strDir <- file.path(getwd( ),"..")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
2
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
3 source(file.path(c_strDir,"lib","Constants.R"))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
4 source(file.path(c_strDir,"lib","Utility.R"))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
5
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
6 context("Test funcRename")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
7 test_that("Test that unclassified and none otus are represented as 2 terminal clades and others are 1",{
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
8 expect_equal(funcRename(paste("A","B","C","D",c_strUnclassified, sep=c_cFeatureDelim)),paste("D",c_strUnclassified, sep=c_cFeatureDelim))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
9 expect_equal(funcRename(paste("A","B","C","D","101", sep=c_cFeatureDelim)),paste("D","101", sep=c_cFeatureDelim))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
10 expect_equal(funcRename(paste("A","B","C","D", sep=c_cFeatureDelim)),paste("D", sep=c_cFeatureDelim))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
11 expect_equal(funcRename(paste("A", sep=c_cFeatureDelim)),paste("A", sep=c_cFeatureDelim))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
12 expect_equal(funcRename(paste(c_strUnclassified, sep=c_cFeatureDelim)),paste(c_strUnclassified, sep=c_cFeatureDelim))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
13 expect_equal(funcRename(paste("101", sep=c_cFeatureDelim)),paste("101", sep=c_cFeatureDelim))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
14 })
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
15
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
16 context("Test funcColorHelper")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
17 test_that("Test that min is min and max is max and average is average even if given as NA",{
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
18 expect_equal(funcColorHelper( dMax = 1, dMin = 1, dMed = NA ), list( dMin = 1, dMax = 1, dMed = 1))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
19 expect_equal(funcColorHelper( dMax = -3, dMin = 10, dMed = NA ), list( dMin = -3, dMax = 10, dMed = 3.5))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
20 expect_equal(funcColorHelper( dMax = 1, dMin = 11, dMed = NA ), list( dMin = 1, dMax = 11, dMed = 6))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
21 expect_equal(funcColorHelper( dMax = 4, dMin = 10, dMed = 5 ), list( dMin = 4, dMax = 10, dMed = 5))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
22 expect_equal(funcColorHelper( dMax = 10, dMin = 4, dMed = 5 ), list( dMin = 4, dMax = 10, dMed = 5))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
23 })
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
24
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
25 context("Test funcTrim")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
26 test_that("Test that white spaces at the beginning and end of s string are removed",{
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
27 expect_equal(funcTrim("TRIM"),"TRIM")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
28 expect_equal(funcTrim(" TRIM"),"TRIM")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
29 expect_equal(funcTrim(" TRIM"),"TRIM")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
30 expect_equal(funcTrim(" TRIM "),"TRIM")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
31 expect_equal(funcTrim("TRIM "),"TRIM")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
32 expect_equal(funcTrim(" TRIM "),"TRIM")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
33 expect_equal(funcTrim("TR IM"),"TR IM")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
34 expect_equal(funcTrim(" TR IM"),"TR IM")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
35 expect_equal(funcTrim(" TR I M"),"TR I M")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
36 expect_equal(funcTrim(" TR IM "),"TR IM")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
37 expect_equal(funcTrim("T R IM "),"T R IM")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
38 expect_equal(funcTrim(" T RIM "),"T RIM")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
39 })
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
40
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
41 #TODO currently the capture versio of this does not produce a tabbed table (or default table delim) which is not consistent with the rest of the code base.
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
42 context("Test funcWrite")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
43 #Answer files
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
44 c_sAnswerWriteFile1 = file.path(c_strDir,c_strTestingDirectory,c_strCorrectAnswers,"FuncWriteTemp1.txt")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
45 c_sAnswerWriteFile2 = file.path(c_strDir,c_strTestingDirectory,c_strCorrectAnswers,"FuncWriteTemp2.txt")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
46 print("c_sAnswerWriteFile2")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
47 print(c_sAnswerWriteFile2)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
48 c_sAnswerWriteDFFile1 = file.path(c_strDir,c_strTestingDirectory,c_strCorrectAnswers,"FuncWriteTempDF1.txt")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
49 c_sAnswerWriteDFFile2 = file.path(c_strDir,c_strTestingDirectory,c_strCorrectAnswers,"FuncWriteTempDF2.txt")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
50
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
51 #Working files
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
52 c_sTempWriteFile1 = file.path(c_strDir,c_strTestingDirectory,c_strTemporaryFiles,"FuncWriteTemp1.txt")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
53 c_sTempWriteFile2 = file.path(c_strDir,c_strTestingDirectory,c_strTemporaryFiles,"FuncWriteTemp2.txt")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
54 c_sTempWriteDFFile1 = file.path(c_strDir,c_strTestingDirectory,c_strTemporaryFiles,"FuncWriteTempDF1.txt")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
55 c_sTempWriteDFFile2 = file.path(c_strDir,c_strTestingDirectory,c_strTemporaryFiles,"FuncWriteTempDF2.txt")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
56 dfTest = as.data.frame(as.matrix(cbind(c(1,11,111),c(2,22,222),c(3,33,333))))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
57 sWriteString = "Testing, 1,2,3 anything but that."
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
58 unlink(c_sTempWriteFile1)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
59 unlink(c_sTempWriteFile2)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
60 unlink(c_sTempWriteDFFile1)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
61 unlink(c_sTempWriteDFFile2)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
62 funcWrite(sWriteString,c_sTempWriteFile1)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
63 funcWrite(sWriteString,c_sTempWriteFile2)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
64 funcWrite(sWriteString,c_sTempWriteFile2)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
65 funcWrite(dfTest,c_sTempWriteDFFile1)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
66 funcWrite(dfTest,c_sTempWriteDFFile2)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
67 funcWrite(dfTest,c_sTempWriteDFFile2)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
68
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
69 test_that("Test that a test file is written and appended to for strings and dataframes.",{
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
70 expect_equal(readLines(c_sTempWriteFile1),readLines(c_sAnswerWriteFile1))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
71 expect_equal(readLines(c_sTempWriteFile2),readLines(c_sAnswerWriteFile2))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
72 expect_equal(readLines(c_sTempWriteDFFile1),readLines(c_sAnswerWriteDFFile1))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
73 expect_equal(readLines(c_sTempWriteDFFile2),readLines(c_sAnswerWriteDFFile2))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
74 })
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
75
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
76 context("Test funcWriteTable")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
77 #Answer files
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
78 c_sAnswerWriteDFFile1 = file.path(c_strDir,c_strTestingDirectory,c_strCorrectAnswers,"FuncWriteTableTempDF1.txt")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
79 c_sAnswerWriteDFFile2 = file.path(c_strDir,c_strTestingDirectory,c_strCorrectAnswers,"FuncWriteTableTempDF2.txt")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
80
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
81 #Working files
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
82 c_sTempWriteDFFile1 = file.path(c_strDir,c_strTestingDirectory,c_strTemporaryFiles,"FuncWriteTableTempDF1.txt")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
83 c_sTempWriteDFFile2 = file.path(c_strDir,c_strTestingDirectory,c_strTemporaryFiles,"FuncWriteTableTempDF2.txt")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
84 unlink(c_sTempWriteDFFile1)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
85 unlink(c_sTempWriteDFFile2)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
86 funcWriteTable(dfTest,c_sTempWriteDFFile1)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
87 funcWriteTable(dfTest,c_sTempWriteDFFile2, fAppend=TRUE)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
88 funcWriteTable(dfTest,c_sTempWriteDFFile2, fAppend=TRUE)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
89
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
90 test_that("Test that a test file is written and appended to for dataframes.",{
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
91 expect_equal(readLines(c_sTempWriteDFFile1),readLines(c_sAnswerWriteDFFile1))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
92 expect_equal(readLines(c_sTempWriteDFFile2),readLines(c_sAnswerWriteDFFile2))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
93 })
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
94
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
95 context("Test funcCoef2Col")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
96 dfTestWithFactors = as.data.frame(as.matrix(cbind(c(1,11,111),c(2,22,222),c(3,33,333))))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
97 colnames(dfTestWithFactors)=c("A","B","C")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
98 dfTestWithFactors["B"]=as.factor(as.character(dfTestWithFactors[["B"]]))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
99 test_that("Test that a coefficients are found or not given if they exist",{
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
100 expect_equal(funcCoef2Col(strCoef="C",frmeData=dfTestWithFactors,astrCols=c()),"C")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
101 expect_equal(funcCoef2Col(strCoef="A",frmeData=dfTestWithFactors,astrCols=c()),"A")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
102 expect_equal(funcCoef2Col(strCoef=paste("B","2",sep=c_sFactorNameSep),frmeData=dfTestWithFactors,astrCols=c()),"B")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
103 expect_equal(funcCoef2Col(strCoef=paste("B","22",sep=c_sFactorNameSep),frmeData=dfTestWithFactors,astrCols=c()),"B")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
104 expect_equal(funcCoef2Col(strCoef=paste("B","222",sep=c_sFactorNameSep),frmeData=dfTestWithFactors,astrCols=c()),"B")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
105 expect_equal(funcCoef2Col(strCoef="C",frmeData=dfTestWithFactors,astrCols=c("A","B","C")),"C")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
106 expect_equal(funcCoef2Col(strCoef=paste("B","2",sep=c_sFactorNameSep),frmeData=dfTestWithFactors,astrCols=c("A","B")),"B")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
107 expect_equal(funcCoef2Col(strCoef=paste("B","22",sep=c_sFactorNameSep),frmeData=dfTestWithFactors,astrCols=c("B","C")),"B")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
108 expect_equal(funcCoef2Col(strCoef=paste("B","222",sep=c_sFactorNameSep),frmeData=dfTestWithFactors,astrCols=c("B")),"B")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
109 })
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
110
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
111 context("Test funcMFAValue2Col")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
112 dfTestWithFactors = data.frame(A=c(1,3,3,4,5,6,7,8),B=c(1.0,2.0, 5.8,4.6,4.7,8.9,9.0,2.0),C=c("one","two","one","two","one","two","one","two"),D=c("1","2","1","2","1","2","1","2"))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
113 dfTestWithFactors["three"]=as.factor(dfTestWithFactors[["three"]])
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
114 test_that("Test that a column names is found or not given if they exist",{
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
115 expect_equal(funcMFAValue2Col(xValue=5.8,dfData=dfTestWithFactors, aiColumnIndicesToSearch=NULL),"B")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
116 expect_equal(funcMFAValue2Col(xValue=6,dfData=dfTestWithFactors, aiColumnIndicesToSearch=NULL),"A")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
117 expect_equal(funcMFAValue2Col(xValue="one",dfData=dfTestWithFactors, aiColumnIndicesToSearch=NULL),"C")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
118 expect_equal(funcMFAValue2Col(xValue="two",dfData=dfTestWithFactors, aiColumnIndicesToSearch=NULL),"C")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
119 expect_equal(funcMFAValue2Col(xValue=paste("D","1",sep=c_sMFANameSep1),dfData=dfTestWithFactors, aiColumnIndicesToSearch=NULL),"D")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
120 expect_equal(funcMFAValue2Col(xValue=paste("D","2",sep=c_sMFANameSep1),dfData=dfTestWithFactors, aiColumnIndicesToSearch=NULL),"D")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
121 expect_equal(funcMFAValue2Col(xValue=2.0,dfData=dfTestWithFactors, aiColumnIndicesToSearch=c(1,3)),NULL)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
122 expect_equal(funcMFAValue2Col(xValue=6,dfData=dfTestWithFactors, aiColumnIndicesToSearch=c(2,3)),NULL)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
123 expect_equal(funcMFAValue2Col(xValue="one",dfData=dfTestWithFactors, aiColumnIndicesToSearch=c(1,2)),NULL)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
124 expect_equal(funcMFAValue2Col(xValue="two",dfData=dfTestWithFactors, aiColumnIndicesToSearch=c(1,2)),NULL)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
125 expect_equal(funcMFAValue2Col(xValue=2.0,dfData=dfTestWithFactors, aiColumnIndicesToSearch=c(2)),"B")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
126 expect_equal(funcMFAValue2Col(xValue=6,dfData=dfTestWithFactors, aiColumnIndicesToSearch=c(1)),"A")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
127 expect_equal(funcMFAValue2Col(xValue="one",dfData=dfTestWithFactors, aiColumnIndicesToSearch=c(3)),"C")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
128 expect_equal(funcMFAValue2Col(xValue=paste("D","2",sep=c_sMFANameSep1),dfData=dfTestWithFactors, aiColumnIndicesToSearch=c(4)),"D")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
129 })
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
130
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
131 context("Test funcFormulaStrToList")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
132 test_that("List of covariates are given, from lm or mixed model formulas",{
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
133 expect_equal(funcFormulaStrToList("adCur ~ `1Covariate`"),c("1Covariate"))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
134 expect_equal(funcFormulaStrToList("adCur ~ `1Covariate` + `2Covariate`"),c("1Covariate","2Covariate"))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
135 expect_equal(funcFormulaStrToList("adCur ~ `1Covariate` + `2Covariate` + `3Covariate`"),c("1Covariate","2Covariate","3Covariate"))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
136 expect_equal(funcFormulaStrToList("adCur ~ 1|`1Covariate`"),c("1Covariate"))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
137 expect_equal(funcFormulaStrToList("adCur ~ 1|`1Covariate` + 1|`2Covariate`"),c("1Covariate","2Covariate"))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
138 expect_equal(funcFormulaStrToList("adCur ~ 1|`1Covariate` + 1|`2Covariate` + 1|`3Covariate`"),c("1Covariate","2Covariate","3Covariate"))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
139 expect_equal(funcFormulaStrToList("adCur ~ 1|`1Covariate` + `2Covariate` + 1|`3Covariate`"),c("1Covariate","2Covariate","3Covariate"))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
140 expect_equal(funcFormulaStrToList("adCur ~ 1|`1Covariate` + 1|`2Covariate` + `3Covariate`"),c("1Covariate","2Covariate","3Covariate"))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
141 expect_equal(funcFormulaStrToList("adCur ~ `1Covariate` + 1|`2Covariate` + 1|`3Covariate`"),c("1Covariate","2Covariate","3Covariate"))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
142 expect_equal(funcFormulaStrToList("adCur ~ `1Covariate` + `2Covariate` + 1|`3Covariate`"),c("1Covariate","2Covariate","3Covariate"))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
143 expect_equal(funcFormulaStrToList("adCur ~ 1|`1Covariate` + `2Covariate` + `3Covariate`"),c("1Covariate","2Covariate","3Covariate"))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
144 expect_equal(funcFormulaStrToList("adCur ~ `1Covariate` + 1|`2Covariate` + `3Covariate`"),c("1Covariate","2Covariate","3Covariate"))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
145 })
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
146
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
147 context("Test funcFormulaListToString")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
148 test_that("The correct string formula for a lm or mixed model is created from a list of covariates",{
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
149 expect_equal(funcFormulaListToString(NULL),c(NA,NA))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
150 expect_equal(funcFormulaListToString(c("1Covariate")),c("adCur ~ `1Covariate`",NA))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
151 expect_equal(funcFormulaListToString(c("1Covariate","2Covariate")),c("adCur ~ `1Covariate` + `2Covariate`",NA))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
152 expect_equal(funcFormulaListToString(c("1Covariate","2Covariate","3Covariate")),c("adCur ~ `1Covariate` + `2Covariate` + `3Covariate`",NA))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
153 expect_equal(funcFormulaListToString(c("1Covariate","2Covariate"),c("3Covariate")),c(NA,"adCur ~ `1Covariate` + `2Covariate` + 1|`3Covariate`"))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
154 expect_equal(funcFormulaListToString(c("1Covariate","3Covariate"),c("2Covariate")),c(NA,"adCur ~ `1Covariate` + `3Covariate` + 1|`2Covariate`"))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
155 expect_equal(funcFormulaListToString(c("2Covariate","3Covariate"),c("1Covariate")),c(NA,"adCur ~ `2Covariate` + `3Covariate` + 1|`1Covariate`"))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
156 expect_equal(funcFormulaListToString(c("2Covariate"),c("1Covariate","3Covariate")),c(NA,"adCur ~ `2Covariate` + 1|`1Covariate` + 1|`3Covariate`"))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
157 expect_equal(funcFormulaListToString(c("1Covariate"),c("2Covariate","3Covariate")),c(NA,"adCur ~ `1Covariate` + 1|`2Covariate` + 1|`3Covariate`"))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
158 expect_equal(funcFormulaListToString(c("3Covariate"),c("1Covariate","2Covariate")),c(NA,"adCur ~ `3Covariate` + 1|`1Covariate` + 1|`2Covariate`"))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
159 })