示例#1
0
  void test_divmod() {
    Fixnum* one = as<Fixnum>(Fixnum::from(15));
    Fixnum* two = as<Fixnum>(Fixnum::from(4));

    Array* ary1 = one->divmod(state, two);
    Object* o1 = ary1->get(state, 0);
    Object* o2 = ary1->get(state, 1);
    TS_ASSERT(o1->fixnum_p());
    TS_ASSERT_EQUALS(as<Integer>(o1)->to_native(), 3);
    TS_ASSERT(o2->fixnum_p());
    TS_ASSERT_EQUALS(as<Integer>(o2)->to_native(), 3);

    Fixnum* zero = Fixnum::from(0);
    TS_ASSERT_THROWS_ASSERT(one->divmod(state, zero), const RubyException &e,
                            TS_ASSERT(Exception::zero_division_error_p(state, e.exception)));
  }
示例#2
0
  void test_divmod_with_a_float() {
    Fixnum* one = as<Fixnum>(Fixnum::from(15));

    Array* ary1 = one->divmod(state, Float::create(state, -3.3));
    Object* o1 = ary1->get(state, 0);
    Object* o2 = ary1->get(state, 1);
    TS_ASSERT(o1->fixnum_p());
    TS_ASSERT_EQUALS(as<Integer>(o1)->to_native(), -5);
    check_float(as<Float>(o2), Float::create(state, -1.5));
  }
示例#3
0
  void test_divmod_with_a_bignum() {
    Fixnum* one = as<Fixnum>(Fixnum::from(15));
    Bignum* two = Bignum::from(state, (native_int)4);

    Array* ary1 = one->divmod(state, two);
    Object* o1 = ary1->get(state, 0);
    Object* o2 = ary1->get(state, 1);
    TS_ASSERT(o1->fixnum_p());
    TS_ASSERT_EQUALS(as<Integer>(o1)->to_native(), 3);
    TS_ASSERT(o2->fixnum_p());
    TS_ASSERT_EQUALS(as<Integer>(o2)->to_native(), 3);
  }