Project

General

Profile

Feature #10782 ยป ruby-changes.patch

bigdecimal: update version, add ZERO, ONE, TEN constants, and add tests for constants - garysweaver (Gary Weaver), 01/25/2015 04:23 PM

View differences:

ext/bigdecimal/bigdecimal.c (working copy)
124 124
     * 1.0.0: Ruby 1.8.0
125 125
     * 1.0.1: Ruby 1.8.1
126 126
     * 1.1.0: Ruby 1.9.3
127
     * 1.2.0: Ruby 2.3.0
127 128
    */
128
    return rb_str_new2("1.1.0");
129
    return rb_str_new2("1.2.0");
129 130
}
130 131

  
131 132
/*
......
3259 3260
    arg = rb_str_new2("NaN");
3260 3261
    /* 'Not a Number' value. */
3261 3262
    rb_define_const(rb_cBigDecimal, "NAN", BigDecimal_global_new(1, &arg, rb_cBigDecimal));
3263
    arg = rb_str_new2("0");
3264
    /* Singleton instance of BigDecimal.new('0'). */
3265
    rb_define_const(rb_cBigDecimal, "ZERO", BigDecimal_global_new(1, &arg, rb_cBigDecimal));
3266
    arg = rb_str_new2("1");
3267
    /* Singleton instance of BigDecimal.new('1'). */
3268
    rb_define_const(rb_cBigDecimal, "ONE", BigDecimal_global_new(1, &arg, rb_cBigDecimal));
3269
    arg = rb_str_new2("10");
3270
    /* Singleton instance of BigDecimal.new('10'). */
3271
    rb_define_const(rb_cBigDecimal, "TEN", BigDecimal_global_new(1, &arg, rb_cBigDecimal));
3262 3272

  
3263 3273

  
3264 3274
    /* instance methods */
ext/bigdecimal/bigdecimal.h (working copy)
114 114
#define SZ_PINF "+Infinity"
115 115
#define SZ_NINF "-Infinity"
116 116

  
117

  
117 118
/*
118 119
 *   #define VP_EXPORT other than static to let VP_ routines
119 120
 *   be called from outside of this module.
test/bigdecimal/test_bigdecimal.rb (working copy)
1552 1552
    Thread.current.keys.to_s
1553 1553
    EOS
1554 1554
  end
1555

  
1556
  def test_zero_const
1557
    assert_equal(BigDecimal::ZERO, BigDecimal.new('0'))
1558
    assert_equal(BigDecimal::ZERO.object_id, BigDecimal::ZERO.object_id)
1559
    assert_equal((-BigDecimal::ZERO), BigDecimal.new('-0'))
1560
    assert_equal((-BigDecimal::ZERO).object_id, (-BigDecimal::ZERO).object_id)
1561
  end
1562

  
1563
  def test_one_const
1564
    assert_equal(BigDecimal::ONE, BigDecimal.new('1'))
1565
    assert_equal(BigDecimal::ONE.object_id, BigDecimal::ONE.object_id)
1566
    assert_equal((-BigDecimal::ONE), BigDecimal.new('-1'))
1567
    assert_equal((-BigDecimal::ONE).object_id, (-BigDecimal::ONE).object_id)
1568
  end
1569

  
1570
  def test_ten_const
1571
    assert_equal(BigDecimal::TEN, BigDecimal.new('10'))
1572
    assert_equal(BigDecimal::TEN.object_id, BigDecimal::TEN.object_id)
1573
    assert_equal((-BigDecimal::TEN), BigDecimal.new('-10'))
1574
    assert_equal((-BigDecimal::TEN).object_id, (-BigDecimal::TEN).object_id)
1575
  end
1555 1576
end