[Rcpp-commits] r3304 - in pkg/int64: inst/unitTests src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Nov 7 13:06:41 CET 2011


Author: romain
Date: 2011-11-07 13:06:41 +0100 (Mon, 07 Nov 2011)
New Revision: 3304

Modified:
   pkg/int64/inst/unitTests/runit.int64.R
   pkg/int64/src/int64.cpp
Log:
unit test for signif, and fix so that the test passes :-)

Modified: pkg/int64/inst/unitTests/runit.int64.R
===================================================================
--- pkg/int64/inst/unitTests/runit.int64.R	2011-11-07 11:47:44 UTC (rev 3303)
+++ pkg/int64/inst/unitTests/runit.int64.R	2011-11-07 12:06:41 UTC (rev 3304)
@@ -62,10 +62,8 @@
     chars <- c( "123456789123456789", "18446744073709551615" )
     x <- as.uint64( chars )
     checkEquals( as.character(x), chars )
-
 }
 
-
 test.unique.int64 <- function(){
     x <- as.int64( c(1:5, 1L, 3L) )
     checkEquals( unique(x), as.int64(1:5) )
@@ -85,3 +83,17 @@
     checkEquals( sort( x, decreasing = TRUE), as.uint64( c(4L,3L,3:1) ) )
 }
 
+test.signif <- function(){
+    x <- as.int64( c( "12345", "12345", "12345" ) )
+    checkEquals( 
+        signif( x, c(2,3,7) ),
+        as.int64( c("12000", "12300", "12345") )
+        )
+        
+   x <- as.uint64( c( "12345", "12345", "12345" ) )
+   checkEquals( 
+       signif( x, c(2,3,7) ),
+       as.uint64( c("12000", "12300", "12345") )
+       )     
+}
+

Modified: pkg/int64/src/int64.cpp
===================================================================
--- pkg/int64/src/int64.cpp	2011-11-07 11:47:44 UTC (rev 3303)
+++ pkg/int64/src/int64.cpp	2011-11-07 12:06:41 UTC (rev 3304)
@@ -186,8 +186,7 @@
             SET_STRING_ELT( res, i, STRING_ELT( s_, i ) ) ;    
         } else {
             s = CHAR(STRING_ELT(s_, i ));
-            tmp = len[i] - digits[i] ; 
-            for( int j=tmp; j<len[i]; j++){
+            for( int j=digits[i]; j<len[i]; j++){
                 s[j] = '0' ;
             }
             SET_STRING_ELT( res, i, Rf_mkChar(s.c_str()) ) ;



More information about the Rcpp-commits mailing list