Skip to content

Commit

Permalink
Merge pull request r-dbi#203 from harvey131/harvey131-patch-1
Browse files Browse the repository at this point in the history
- Improved tests for numerical precision (r-dbi#203, @harvey131).
  • Loading branch information
krlmlr authored Dec 30, 2018
2 parents 4a1b522 + b924316 commit cda6cc5
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/testthat/test-dbWriteTable.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,40 @@ with_database_connection({
})
})
})

describe("Writing to the database with possible numeric precision issues", {
# reference value
value <- data.frame(x = -0.000064925595060641, y = -0.00006492559506064059)
test_that("dbWriteTable(copy = F)", {
with_table(con, "xy", {
dbWriteTable(con, name = "xy", value = value, copy = F)
expect_equal(dbGetQuery(con, "SELECT * FROM xy"), value)
})
})

test_that("dbWriteTable(append = T, copy = F)", {
with_table(con, "xy", {
dbExecute(con, "CREATE TEMPORARY TABLE xy ( x numeric NOT NULL, y numeric NOT NULL);")
dbWriteTable(con, name = "xy", value = value, append = T, copy = F)
expect_equal(dbGetQuery(con, "SELECT * FROM xy"), value)
})
})

test_that("dbWriteTable(append = T, copy = T)", {
with_table(con, "xy", {
dbExecute(con, "CREATE TEMPORARY TABLE xy ( x numeric NOT NULL, y numeric NOT NULL);")
dbWriteTable(con, name = "xy", value = value, append = T, copy = T)
expect_equal(dbGetQuery(con, "SELECT * FROM xy"), value)
})
})

test_that("dbWriteTable(append = F, copy = T, field.types=NUMERIC)", {
with_table(con, "xy", {
dbWriteTable(con, name = "xy", value = value, overwrite = F, append = F, copy = T, field.types = c(x = "NUMERIC", y = "NUMERIC"))
expect_equal(dbGetQuery(con, "SELECT * FROM xy"), value)
})
})
})
})

}

0 comments on commit cda6cc5

Please sign in to comment.