Giter Site home page Giter Site logo

Comments (3)

ianmcook avatar ianmcook commented on July 17, 2024 1

Thanks for putting some thought into this.

To reduce the repetition of the same boilerplate code in every test, we could define some helper functions. For example, we could have a trio of functions test_parse_expression_tidyverse(), test_parse_expression_base(), and test_parse_expression_generic(). The generic one would simply call both of the other two.

from queryparser.

ianmcook avatar ianmcook commented on July 17, 2024 1

Regarding whether to (1) test the translation or (2) test the outcome:

I think (1) is safer and more general. It eliminates the possibility that the particular input values used in the test coincidentally worked but will not work in general.

from queryparser.

StevenHibble avatar StevenHibble commented on July 17, 2024

I'm thinking there are two options for "indirect" translations:

  1. Test the translation
test_that("ifnull() function translates correctly", {
  SQL <- "ifnull(a, b)"
  R   <- "ifelse(is.na(a), b, a)"
  expect_equal(parse_expression(SQL, tidy = FALSE), str2lang(R))
  expect_equal(parse_expression(SQL, tidy = TRUE),  str2lang(R))
})
  1. Test the outcome
test_that("ifnull() function translates correctly", {
  a <- c(1, 2, NA)
  b <- c(7, 8, 9)
  SQL <- "ifnull(a, b)"
  answer <- c(1, 2, 9)

  untidy <- eval(parse_expression(SQL, tidy = FALSE))
  tidy   <- eval(parse_expression(SQL, tidy = TRUE))
  expect_equal(untidy, answer)
  expect_equal(tidy,   answer)
})

I think I prefer the 2nd option, though it is more involved. Thoughts?

from queryparser.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.