tests/testthat/tests-dollar.R

context("dollar")

# skip("dollar")

test_that("references work", {
  expect_is(s, "rscalaBridge")
  expect_is(s(x=3), "rscalaBridge")
  rng <- s$.new_scala.util.Random(); expect_is(rng, "rscalaReference")
  expect_lte(rng$nextDouble(),1.0)
  expect_gte(rng$nextDouble(),0.0)
  expect_gte(rng$nextInt(1L),0L)
  expect_lte(rng$nextInt(2L),1L)
  expect_true(s(x=s$.null_String()) * "x == null")
  expect_true(s(rng=rng,x=rng$.asInstanceOf_AnyRef()) * "x.equals(rng)")
  expect_identical(s$.new_String("Hotdog")$toString(),"Hotdog")
  expect_identical(s$List(1,2,3,4)$toArray(),c(1,2,3,4))
  expect_is(s$scala.util.Random.nextDouble, "rscalaStub")
  expect_type(s$scala.util.Random.nextDouble(), "double")
  expect_is(s$.scala.util.Random.nextDouble(), "rscalaReference")
  expect_is(s ^ "4", "rscalaReference")
  expect_is(s$.Array(1,2,3), "rscalaReference")
  expect_identical(s$Array(1,2,3), c(1,2,3))
  expect_null(s + "def nextInt(max: Int) = scala.util.Random.nextInt(max)")
  expect_type(s$nextInt(4L),"integer")
  nextInt <- s$nextInt; expect_type(nextInt(4L),"integer")
})

Try the rscala package in your browser

Any scripts or data that you put into this service are public.

rscala documentation built on Aug. 15, 2023, 9:07 a.m.