Author: Antonio Cuni <[email protected]>
Branch: faster-rstruct
Changeset: r80745:85c3b26dea8a
Date: 2015-11-18 09:29 +0100
http://bitbucket.org/pypy/pypy/changeset/85c3b26dea8a/

Log:    add a passing test for singlefloats

diff --git a/rpython/jit/metainterp/test/test_strstorage.py 
b/rpython/jit/metainterp/test/test_strstorage.py
--- a/rpython/jit/metainterp/test/test_strstorage.py
+++ b/rpython/jit/metainterp/test/test_strstorage.py
@@ -1,6 +1,8 @@
 import py
+from rpython.rtyper.lltypesystem import lltype
 from rpython.rlib.strstorage import str_storage_getitem
 from rpython.rlib.test.test_strstorage import BaseStrStorageTest
+from rpython.jit.codewriter import longlong
 from rpython.jit.metainterp.history import getkind
 from rpython.jit.metainterp.test.support import LLJitMixin
 
@@ -12,9 +14,15 @@
     def str_storage_getitem(self, TYPE, buf, offset):
         def f():
             return str_storage_getitem(TYPE, buf, offset)
-        res = self.interp_operations(f, [])
+        res = self.interp_operations(f, [], supports_singlefloats=True)
         #
         kind = getkind(TYPE)[0] # 'i' or 'f'
         self.check_operations_history({'getarrayitem_gc_%s' % kind: 1,
                                        'finish': 1})
+        #
+        if TYPE == lltype.SingleFloat:
+            # interp_operations returns the int version of r_singlefloat, but
+            # our tests expects to receive an r_singlefloat: let's convert it
+            # back!
+            return longlong.int2singlefloat(res)
         return res
diff --git a/rpython/rlib/test/test_strstorage.py 
b/rpython/rlib/test/test_strstorage.py
--- a/rpython/rlib/test/test_strstorage.py
+++ b/rpython/rlib/test/test_strstorage.py
@@ -2,6 +2,7 @@
 import struct
 from rpython.rtyper.lltypesystem import lltype, rffi
 from rpython.rlib.strstorage import str_storage_getitem
+from rpython.rlib.rarithmetic import r_singlefloat
 from rpython.rtyper.test.tool import BaseRtypingTest
 
 class BaseStrStorageTest:
@@ -26,6 +27,15 @@
         assert self.str_storage_getitem(lltype.Float, buf, 0) == 12.3
         assert self.str_storage_getitem(lltype.Float, buf, size) == 45.6
 
+    def test_singlefloat(self):
+        buf = struct.pack('@ff', 12.3, 45.6)
+        size = struct.calcsize('@f')
+        x = self.str_storage_getitem(lltype.SingleFloat, buf, 0)
+        assert x == r_singlefloat(12.3)
+        x = self.str_storage_getitem(lltype.SingleFloat, buf, size)
+        assert x == r_singlefloat(45.6)
+
+
 class TestDirect(BaseStrStorageTest):
 
     def str_storage_getitem(self, TYPE, buf, offset):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to