Exemple #1
0
  void test_coerce_bignum() {
    Fixnum* one = Fixnum::from(1);
    Bignum* e = Bignum::create(state, one);
    Array* ary = one->coerce(state, e);

    Fixnum* a = try_as<Fixnum>(ary->get(state, 0));
    Fixnum* b = try_as<Fixnum>(ary->get(state, 1));

    TS_ASSERT_EQUALS(2, ary->size());
    TS_ASSERT(a);
    TS_ASSERT(b);
    TS_ASSERT_EQUALS(one, a);
    TS_ASSERT_EQUALS(one, b);

    Bignum* f = Bignum::from(state, 9223372036854775807LL);
    ary = one->coerce(state, f);
    Bignum* c = try_as<Bignum>(ary->get(state, 0));
    Bignum* d = try_as<Bignum>(ary->get(state, 1));

    TS_ASSERT_EQUALS(2, ary->size());
    TS_ASSERT(c);
    TS_ASSERT(d);
    TS_ASSERT_EQUALS(cTrue, c->equal(state, f));
    TS_ASSERT_EQUALS(cTrue, d->equal(state, e));
  }
Exemple #2
0
  void test_coerce_fixnum() {
    Fixnum* one = Fixnum::from(1);
    Fixnum* two = Fixnum::from(2);
    Array* ary = one->coerce(state, two);

    Fixnum* a = try_as<Fixnum>(ary->get(state, 0));
    Fixnum* b = try_as<Fixnum>(ary->get(state, 1));

    TS_ASSERT_EQUALS(2, ary->size());
    TS_ASSERT(a);
    TS_ASSERT(b);
    TS_ASSERT_EQUALS(two, a);
    TS_ASSERT_EQUALS(one, b);
  }