[Rprotobuf-commits] r377 - in pkg: demo inst/unitTests

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Aug 12 23:30:51 CEST 2010


Author: edd
Date: 2010-08-12 23:30:51 +0200 (Thu, 12 Aug 2010)
New Revision: 377

Modified:
   pkg/demo/io.R
   pkg/inst/unitTests/runit.addressbook.R
Log:
more unit tests


Modified: pkg/demo/io.R
===================================================================
--- pkg/demo/io.R	2010-08-12 21:18:27 UTC (rev 376)
+++ pkg/demo/io.R	2010-08-12 21:30:51 UTC (rev 377)
@@ -3,14 +3,14 @@
 ### read messages from files and binary connections
 
 # read a message from a file name
-f <- system.file( "examples", "AddressBookFile", package = "RProtoBuf" )
+f <- system.file( "examples", "addressbook.pb", package = "RProtoBuf" )
 m1 <- read( tutorial.AddressBook, f )
 writeLines( as.character( m1 ) )
 
 # read the same message from a (binary) file connection
 con <- file( f, open = "rb" )
 m2 <- read( tutorial.AddressBook, con )
-# this also works: 
+# this also works:
 # m2 <- tutorial.AddressBook$read( con )
 writeLines( as.character( m2 ) )
 close( con )
@@ -30,7 +30,7 @@
 close( con )
 
 # test that the two binary files are identical
-stopifnot( identical( 
+stopifnot( identical(
 	readBin( tf1, raw(0), 1000), readBin( tf2, raw(0), 1000)
 	) )
 

Modified: pkg/inst/unitTests/runit.addressbook.R
===================================================================
--- pkg/inst/unitTests/runit.addressbook.R	2010-08-12 21:18:27 UTC (rev 376)
+++ pkg/inst/unitTests/runit.addressbook.R	2010-08-12 21:30:51 UTC (rev 377)
@@ -1,23 +1,25 @@
 
 ## created as
 ##   demo(addressbook)  ## creates 'book'
-##   con <- file("/tmp/addressbook.pb", open="wb")
-##   serialize(book, con)
-##   close(con)
+##   serialize(book, "/tmp/addressbook.pb")
 
 # this is executed before each test function
 .setUp <- function() {
-    file <- system.file( "examples", "AddressBookFile", package = "RProtoBuf" )
+    file <- system.file( "examples", "addressbook.pb", package = "RProtoBuf" )
     book <- read( tutorial.AddressBook, file )
 }
 
 test.size <- function() {
-	checkTrue(book$size("person"), 4, msg="Number of persons")
-}
+    checkEquals(book$size("person"),        2,   msg="Number of persons")
+    checkEquals(bytesize(book),             125, msg="Bytes in book")
+    checkEquals(bytesize(book$person[[1]]), 60,  msg="Bytes of first person message")
 
 test.personOne <- function() {
-	checkTrue(book$person[[1]]$name, "Humpty Dumpty", msg="First person name")
-	checkTrue(length(book$person[[1]]$phone), 2,      msg="First person phones")
-	checkTrue(book$person[[1]]$phone[[1]]$number, "123.456.789", msg="First person phone number")
-	checkTrue(book$person[[1]]$phone[[1]]$number, "0",           msg="First person phone type")
+    checkEquals(book$person[[1]]$name,              "Romain Francois",   msg="First person name")
+    checkEquals(book$person[[2]]$name,              "Dirk Eddelbuettel", msg="First person name")
+    checkEquals(length(book$person[[1]]$phone),     1,                   msg="First person phones")
+    checkEquals(length(book$person[[2]]$phone),     2,                   msg="Second person phones")
+    checkEquals(book$person[[1]]$phone[[1]]$number, "+33(0)...",         msg="First person phone number")
+    checkEquals(book$person[[2]]$phone[[1]]$number, "+01...",            msg="Second person phone number")
+    checkEquals(book$person[[2]]$phone[[1]]$type,   0,                   msg="Second person phone number")
 }



More information about the Rprotobuf-commits mailing list