diff options
author | Jari Vetoniemi <jari.vetoniemi@indooratlas.com> | 2020-03-16 18:49:26 +0900 |
---|---|---|
committer | Jari Vetoniemi <jari.vetoniemi@indooratlas.com> | 2020-03-30 00:39:06 +0900 |
commit | fcbf63e62c627deae76c1b8cb8c0876c536ed811 (patch) | |
tree | 64cb17de3f41a2b6fef2368028fbd00349946994 /jni/ruby/test/rake/test_rake_cpu_counter.rb |
Fresh start
Diffstat (limited to 'jni/ruby/test/rake/test_rake_cpu_counter.rb')
-rw-r--r-- | jni/ruby/test/rake/test_rake_cpu_counter.rb | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/jni/ruby/test/rake/test_rake_cpu_counter.rb b/jni/ruby/test/rake/test_rake_cpu_counter.rb new file mode 100644 index 0000000..87d0601 --- /dev/null +++ b/jni/ruby/test/rake/test_rake_cpu_counter.rb @@ -0,0 +1,68 @@ +require File.expand_path('../helper', __FILE__) + +class TestRakeCpuCounter < Rake::TestCase + + def setup + super + + @cpu_counter = Rake::CpuCounter.new + end + + def test_count + num = @cpu_counter.count + skip 'cannot count CPU' if num == nil + assert_kind_of Numeric, num + assert_operator num, :>=, 1 + end + + def test_count_with_default_nil + def @cpu_counter.count; nil; end + assert_equal(8, @cpu_counter.count_with_default(8)) + assert_equal(4, @cpu_counter.count_with_default) + end + + def test_count_with_default_raise + def @cpu_counter.count; raise; end + assert_equal(8, @cpu_counter.count_with_default(8)) + assert_equal(4, @cpu_counter.count_with_default) + end + + class TestClassMethod < Rake::TestCase + def setup + super + + @klass = Class.new(Rake::CpuCounter) + end + + def test_count + @klass.class_eval do + def count; 8; end + end + assert_equal(8, @klass.count) + end + + def test_count_nil + counted = false + @klass.class_eval do + define_method(:count) do + counted = true + nil + end + end + assert_equal(4, @klass.count) + assert_equal(true, counted) + end + + def test_count_raise + counted = false + @klass.class_eval do + define_method(:count) do + counted = true + raise + end + end + assert_equal(4, @klass.count) + assert_equal(true, counted) + end + end +end |