Skip to content
Snippets Groups Projects
Commit 4cb44ebe authored by Florian Angerer's avatar Florian Angerer
Browse files

Added tests and updated native version.

parent 9fa889b5
No related branches found
No related tags found
No related merge requests found
......@@ -279,7 +279,7 @@ public final class MiscNodes {
}
protected CastNode createCast() {
HeadPhaseBuilder<Double> findFirst = CastNodeBuilder.newCastBuilder().mustNotBeMissing().mustNotBeNull().asDoubleVector().findFirst();
HeadPhaseBuilder<Double> findFirst = CastNodeBuilder.newCastBuilder().mustNotBeMissing().allowNull().asDoubleVector().findFirst();
return findFirst.buildCastNode();
}
......
......@@ -13,7 +13,7 @@ public abstract class OctSizeNode extends RExternalBuiltinNode.Arg1 {
static {
Casts casts = new Casts(OctSizeNode.class);
casts.arg(0).mustNotBeMissing().mustNotBeNull().returnIf(Predef.integerValue()).asDoubleVector().findFirst();
casts.arg(0).mustNotBeMissing().allowNull().returnIf(Predef.integerValue()).asDoubleVector().findFirst();
}
@Child private SizeToOctalRawNode sizeToOctal = SizeToOctalRawNode.create();
......
44
45
......@@ -10,6 +10,7 @@ import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.r.runtime.RError;
import com.oracle.truffle.r.runtime.RRuntime;
import com.oracle.truffle.r.runtime.data.RDataFactory;
import com.oracle.truffle.r.runtime.data.RNull;
import com.oracle.truffle.r.runtime.data.RRawVector;
import com.oracle.truffle.r.runtime.data.nodes.SetDataAt;
......@@ -31,9 +32,12 @@ public abstract class SizeToOctalRawNode extends UnaryNode {
}
ByteBuffer encode = asciiCharset.encode(Integer.toOctalString(s));
// reverse
byte[] result = new byte[11];
Arrays.fill(result, (byte) 48);
encode.get(result);
Arrays.fill(result, (byte) '0');
for (int i = result.length - 1; i >= 0 && encode.hasRemaining(); i--) {
result[i] = encode.get();
}
return result;
}
......@@ -59,6 +63,11 @@ public abstract class SizeToOctalRawNode extends UnaryNode {
return ans;
}
@Specialization
protected RRawVector octSize(@SuppressWarnings("unused") RNull n) {
return RDataFactory.createRawVector(11);
}
public static SizeToOctalRawNode create() {
return SizeToOctalRawNodeGen.create();
......
......@@ -167456,6 +167456,26 @@ Error: the first argument must be of mode character
[28] plot.ts plot.tskernel*
see '?methods' for accessing help and source code
 
##com.oracle.truffle.r.test.library.utils.TestUtils.testOctSize#
#.Call(utils:::C_octsize, 1.0)
[1] 30 30 30 30 30 30 30 30 30 30 31
##com.oracle.truffle.r.test.library.utils.TestUtils.testOctSize#
#.Call(utils:::C_octsize, 1L)
[1] 30 30 30 30 30 30 30 30 30 30 31
##com.oracle.truffle.r.test.library.utils.TestUtils.testOctSize#
#.Call(utils:::C_octsize, 2147483647)
[1] 31 37 37 37 37 37 37 37 37 37 37
##com.oracle.truffle.r.test.library.utils.TestUtils.testOctSize#
#.Call(utils:::C_octsize, NA)
[1] 00 00 00 00 00 00 00 00 00 00 00
##com.oracle.truffle.r.test.library.utils.TestUtils.testOctSize#
#.Call(utils:::C_octsize, NULL)
[1] 00 00 00 00 00 00 00 00 00 00 00
##com.oracle.truffle.r.test.library.utils.TestWriteTable.testTable#
#write.table(data.frame(col=c(1,2,3,4), col2=c(T, F, T, F)))
"col" "col2"
......@@ -44,4 +44,11 @@ public class TestUtils extends TestBase {
// The vector of methods is not sorted alphabetically
assertEval(Ignored.ImplementationError, "methods(plot)");
}
private static final String[] TEST_OCTSIZE_PARAMS = {"1L", "1.0", Integer.toString(Integer.MAX_VALUE), "NA", "NULL"};
@Test
public void testOctSize() {
assertEval(template(".Call(utils:::C_octsize, %0)", TEST_OCTSIZE_PARAMS));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment