From df3d3a0b09f05249aff9f25f558f988bfcad8874 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 22 Feb 2011 19:24:55 -0800 Subject: add Raindrops::MAX constant This is the highest number a counter may be incremented to before it overflows. --- ext/raindrops/raindrops.c | 3 +++ test/test_raindrops.rb | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/ext/raindrops/raindrops.c b/ext/raindrops/raindrops.c index 599f39d..766ee02 100644 --- a/ext/raindrops/raindrops.c +++ b/ext/raindrops/raindrops.c @@ -203,6 +203,9 @@ void Init_raindrops_ext(void) #endif rb_define_const(cRaindrops, "SIZE", SIZET2NUM(raindrop_size)); + /* the maximum value a raindrop counter can hold */ + rb_define_const(cRaindrops, "MAX", ULONG2NUM((unsigned long)-1)); + rb_define_alloc_func(cRaindrops, alloc); rb_define_method(cRaindrops, "initialize", init, 1); diff --git a/test/test_raindrops.rb b/test/test_raindrops.rb index aab1f14..6686796 100644 --- a/test/test_raindrops.rb +++ b/test/test_raindrops.rb @@ -4,6 +4,12 @@ require 'raindrops' class TestRaindrops < Test::Unit::TestCase + def test_raindrop_counter_max + assert_kind_of Integer, Raindrops::MAX + assert Raindrops::MAX > 0 + printf "Raindrops::MAX = 0x%x\n", Raindrops::MAX + end + def test_raindrop_size assert_kind_of Integer, Raindrops::SIZE assert Raindrops::SIZE > 0 -- cgit v1.2.3-24-ge0c7