void test_sub_underflows_to_bignum() { Fixnum* min = Fixnum::from(FIXNUM_MIN); Integer* min_minus1 = min->sub(state, Fixnum::from(1)); TS_ASSERT(kind_of<Bignum>(min_minus1)); TS_ASSERT_EQUALS(FIXNUM_MIN-1, min_minus1->to_native()); }
void test_sub() { Fixnum* one = Fixnum::from(1); Fixnum* zero = as<Fixnum>(one->sub(state, one)); TS_ASSERT_EQUALS(0, zero->to_native()); TS_ASSERT_EQUALS(Fixnum::from(0), zero); }
void test_sub_overflows_to_bignum() { Fixnum* max = Fixnum::from(FIXNUM_MAX); Integer* max_plus1 = max->sub(state, Fixnum::from(-1)); TS_ASSERT(kind_of<Bignum>(max_plus1)); TS_ASSERT_EQUALS(FIXNUM_MAX+1, max_plus1->to_native()); }
void test_sub_a_bignum() { Fixnum* one = as<Fixnum>(Fixnum::from(13)); Bignum* obj = Bignum::from(state, (native_int)FIXNUM_MAX + 28); Integer* res = one->sub(state, obj); TS_ASSERT(kind_of<Bignum>(res)); TS_ASSERT_EQUALS(res->to_native(), 13 - (FIXNUM_MAX + 28)); }
void test_sub_a_float() { Fixnum* one = Fixnum::from(13); Float* res = one->sub(state, Float::create(state, 1.4)); check_float(res, Float::create(state, 11.6)); }