def test_float_at_put(): target = model.W_Float(1.0) for f in [1.0, -1.0, 1.1, 64.4, -0.0, float('nan'), float('inf')]: source = model.W_Float(f) target.store(space, 0, source.fetch(space, 0)) target.store(space, 1, source.fetch(space, 1)) if math.isnan(f): assert math.isnan(target.value) else: assert target.value == f
def test_at(): w_obj = bootstrap_class(0, varsized=True).as_class_get_shadow(space).new(1) foo = wrap("foo") w_obj.store(space, 0, foo) assert prim(primitives.AT, [w_obj, 1]) is foo w_obj = model.W_Float(1.1) foo = wrap(1) w_obj.store(space, 0, foo) assert prim(primitives.AT, [w_obj, 1]) == foo
def test_not_is_same_object(w_o1=model.W_PointersObject(space, None, 0), w_o2=model.W_PointersObject(space, None, 0)): assert not w_o1.is_same_object(w_o2) assert not w_o2.is_same_object(w_o1) w_o2 = model.W_SmallInteger(2) assert not w_o1.is_same_object(w_o2) assert not w_o2.is_same_object(w_o1) w_o2 = model.W_Float(5.5) assert not w_o1.is_same_object(w_o2) assert not w_o2.is_same_object(w_o1)
def test_not_is_same_object(w_o1=None, w_o2=None): if w_o1 is None: w_o1 = model.W_PointersObject(space, None, 0) if w_o2 is None: w_o2 = model.W_PointersObject(space, None, 0) assert not w_o1.is_same_object(w_o2) assert not w_o2.is_same_object(w_o1) w_o2 = model.W_SmallInteger(2) assert not w_o1.is_same_object(w_o2) assert not w_o2.is_same_object(w_o1) w_o2 = model.W_Float(5.5) assert not w_o1.is_same_object(w_o2) assert not w_o2.is_same_object(w_o1)
def test_float_at(): b = model.W_Float(64.0) r = b.fetch(space, 0) if isinstance(r, model.W_LargePositiveInteger1Word): assert r.size() == 4 assert space.unwrap_int(r.at0(space, 0)) == 0 assert space.unwrap_int(r.at0(space, 1)) == 0 assert space.unwrap_int(r.at0(space, 2)) == 80 assert space.unwrap_int(r.at0(space, 3)) == 64 else: assert isinstance(r, model.W_SmallInteger) assert space.unwrap_int(r) == (80 << 16) + (64 << 24) r = b.fetch(space, 1) assert isinstance(r, model.W_SmallInteger) assert r.value == 0
def new(self, extrasize=0): w_cls = self.w_self() if self.instance_kind == POINTERS: size = self.instsize() + extrasize w_new = model.W_PointersObject(self.space, w_cls, size) elif self.instance_kind == WORDS: w_new = model.W_WordsObject(self.space, w_cls, extrasize) elif self.instance_kind == BYTES: w_new = model.W_BytesObject(self.space, w_cls, extrasize) elif self.instance_kind == COMPILED_METHOD: w_new = model.W_CompiledMethod(self.space, extrasize) elif self.instance_kind == FLOAT: w_new = model.W_Float(0) # Squeak gives a random piece of memory elif self.instance_kind == LARGE_POSITIVE_INTEGER: if extrasize <= 4: w_new = model.W_LargePositiveInteger1Word(0, extrasize) else: w_new = model.W_BytesObject(self.space, w_cls, extrasize) elif self.instance_kind == WEAK_POINTERS: size = self.instsize() + extrasize w_new = model.W_PointersObject(self.space, w_cls, size, weak=True) else: raise NotImplementedError(self.instance_kind) return w_new
def test_float_hash(): target = model.W_Float(1.1) assert target.gethash() == model.W_Float(1.1).gethash() target.store(space, 0, space.wrap_int(42)) assert target.gethash() != model.W_Float(1.1).gethash()
def test_intfloat_notis_same_object(): test_not_is_same_object(model.W_SmallInteger(1), model.W_Float(1)) test_not_is_same_object(model.W_Float(100), model.W_SmallInteger(100)) test_not_is_same_object(model.W_Float(1.100), model.W_Float(1.200)) test_not_is_same_object(model.W_SmallInteger(101), model.W_SmallInteger(100))
def wrap_float(self, i): return model.W_Float(i)