-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.r
executable file
·35 lines (32 loc) · 1.33 KB
/
test.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env Rscript
library(testthat)
# This test runner assumes that the parser has already run.
test.runner <- function(datestamp, filename, sql){
observed <- read.csv(paste('archive', datestamp, filename, sep = '/'), stringsAsFactors = F)
expected <- read.csv(paste('fixtures', datestamp, filename, sep = '/'), stringsAsFactors = F)
# print(observed[1:2,-(1:2)])
# print(expected[1:2,-(1:2)])
expect_equal(colnames(observed), colnames(expected))
expect_equal(ncol(observed), ncol(expected))
expect_equal(nrow(observed), nrow(expected))
for (colname in colnames(expected)){
if (colname != 'footnotes' & sum(observed[,colname] != expected[,colname]) > 0) {
df = data.frame(
observed = (observed[,colname]),
expected = (expected[,colname]),
stringsAsFactors = F
)
print(df[df$observed != df$expected,])
print(t(df[df$observed != df$expected,]))
}
expect_equal(observed[,colname], expected[,colname], info = paste('failed on', colname, 'column'))
}
}
#test.runner('20121129', 'table1.csv')
test.runner('20121129', 'table2.csv')
#test.runner('20121129', 'table3a.csv')
#test.runner('20121129', 'table3b.csv')
#test.runner('20121129', 'table3c.csv')
#test.runner('20121129', 'table4.csv')
#test.runner('20121129', 'table5.csv')
#test.runner('20121129', 'table6.csv')