Class: Use

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/test/tc_task.rb,
lib/test/tc_taskmanager.rb

Instance Method Summary collapse

Instance Method Details

#fibonacci(n) ⇒ Object



5
6
7
8
9
10
# File 'lib/test/tc_taskmanager.rb', line 5

def fibonacci(n)
    if n == 1 || n == 2 then
        return 1
    end
    return fibonacci(n - 1) + fibonacci(n - 2)
end

#test_taskmanagerObject



11
12
13
14
15
16
17
18
# File 'lib/test/tc_taskmanager.rb', line 11

def test_taskmanager()
    taskmanager = TaskManager.new
    10.upto(22) do |index|
        taskmanager.add_task(index) { |index| puts fibonacci(index) }
    end
    taskmanager.join()
    assert(TaskQueue.run_times == 13, 'some thread loss ...')
end

#test_use_taskObject



5
6
7
8
9
10
11
12
13
14
# File 'lib/test/tc_task.rb', line 5

def test_use_task()
    begin
        task = Task.new('hello') do |arg|
            arg.capitalize
        end
        assert(task.run() == 'Hello', 'task run test failed')
    rescue => exception
        assert(false, "occur exception: #{exception.message}")
    end
end