PageRenderTime 51ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Examples/test-suite/r/r_copy_struct_runme.R

#
R | 58 lines | 39 code | 16 blank | 3 comment | 0 complexity | 13c7fcb5103790e01a611aac7a142294 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. source("unittest.R")
  2. dyn.load(paste("r_copy_struct", .Platform$dynlib.ext, sep=""))
  3. source("r_copy_struct.R")
  4. cacheMetaData(1)
  5. a <- getA()
  6. r = getARef()
  7. unittest(A_d_get(r), 42)
  8. unittest(r$d, 42)
  9. unittest(r$i, 20)
  10. # An error in trying to access a field that doesn't exist.
  11. try(r$foo)
  12. r$d <- pi
  13. unittesttol(r$d, 3.141593, 0.0001)
  14. r$i <- -100
  15. r$ui
  16. r$ui <- 10
  17. # An error since i is unsigned and so must be positive.
  18. try(r$ui <- -10)
  19. a = A()
  20. unittest(a$i,0)
  21. unittest(a$d,0)
  22. unittest(a$ui,0)
  23. a$ui <- 100
  24. unittest(a$ui,100)
  25. a$d = 1
  26. unittest(a$d,1)
  27. d <- bar()
  28. unittest(class(d), "_p_D")
  29. unittest(d$x, 1)
  30. unittest(d$u, 0)
  31. la <- new("A");
  32. la@ui <- as.integer(5)
  33. # Removing the next line makes this fail in R 2.4
  34. la@str <- ""
  35. other = A()
  36. foo <- copyToC(la, other)
  37. aa = A()
  38. aa$i = as.integer(201)
  39. aa$d = pi
  40. aa$str = "foo"
  41. aa$ui = as.integer(0)
  42. copyToR(aa)