2018-08-23 18:55:06 +02:00
|
|
|
require_relative "helper"
|
|
|
|
|
|
|
|
module Parfait
|
2018-08-29 20:05:54 +02:00
|
|
|
class TestFactory < ParfaitTest
|
2018-08-23 18:55:06 +02:00
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
2019-08-24 08:46:33 +02:00
|
|
|
type = Parfait.object_space.get_type_by_class_name(:Integer)
|
|
|
|
@factory = Factory.new(type , 40)
|
2018-08-23 18:55:06 +02:00
|
|
|
end
|
|
|
|
def test_ok
|
|
|
|
assert @factory
|
|
|
|
end
|
|
|
|
def test_name_ok
|
|
|
|
assert @factory.attribute_name.to_s.start_with?("next")
|
|
|
|
end
|
|
|
|
def test_get_next
|
|
|
|
assert_nil @factory.get_next_for( Integer.new(1))
|
|
|
|
end
|
|
|
|
def test_no_next
|
|
|
|
assert_nil @factory.next_object
|
|
|
|
assert_nil @factory.reserve
|
|
|
|
end
|
|
|
|
def test_get_next_object
|
|
|
|
assert_equal Parfait::Integer , @factory.get_next_object.class
|
|
|
|
end
|
2019-02-09 11:44:35 +01:00
|
|
|
def test_default_test_page
|
2019-08-24 08:46:33 +02:00
|
|
|
assert_equal 40 , @factory.page_size
|
2019-02-08 22:03:23 +01:00
|
|
|
end
|
2018-08-29 20:05:54 +02:00
|
|
|
def test_first_is_reserve
|
|
|
|
@factory.get_next_object
|
|
|
|
assert_equal Parfait::Integer , @factory.reserve.class
|
|
|
|
end
|
2018-08-23 18:55:06 +02:00
|
|
|
def test_reserve_length
|
|
|
|
count = 0
|
|
|
|
start = @factory.get_next_object
|
|
|
|
start = @factory.reserve
|
|
|
|
while( start )
|
|
|
|
start = start.next_integer
|
|
|
|
count += 1
|
|
|
|
end
|
2019-08-24 08:46:33 +02:00
|
|
|
assert_equal 16 , count
|
2018-08-23 18:55:06 +02:00
|
|
|
end
|
2019-02-09 11:44:35 +01:00
|
|
|
class BigFactoryTest < BigParfaitTest
|
|
|
|
def setup
|
|
|
|
super
|
2019-08-24 08:46:33 +02:00
|
|
|
type = Parfait.object_space.get_type_by_class_name(:Integer)
|
|
|
|
@factory = Factory.new(type , 300)
|
2019-02-09 11:44:35 +01:00
|
|
|
end
|
|
|
|
def test_chain_length
|
|
|
|
count = 0
|
|
|
|
start = @factory.get_next_object
|
|
|
|
while( start )
|
|
|
|
start = start.next_integer
|
|
|
|
count += 1
|
|
|
|
end
|
2019-08-24 08:46:33 +02:00
|
|
|
assert_equal 300-15 , count
|
2019-02-09 11:44:35 +01:00
|
|
|
end
|
2019-08-24 08:46:33 +02:00
|
|
|
def test_page
|
|
|
|
assert_equal 300 , @factory.page_size
|
2019-02-09 11:44:35 +01:00
|
|
|
end
|
|
|
|
end
|
2018-08-23 18:55:06 +02:00
|
|
|
end
|
|
|
|
end
|