Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
48 lines (39 sloc) 1.06 KB
$VERBOSE = true
require_relative 'test_helper'
class TestBasicCase < Test::Unit::TestCase
class Material
include Flyweight
def initialize(looks, price)
@looks, @price = looks, price
end
def values
[@looks, @price]
end
end
class SubMaterial < Material
end
def test_normaly
a = Material.intern :metal, 2000
b = Material.intern :metal, 2000
c = Material.new :metal, 2000
d = Material.intern :paper, 50
e = SubMaterial.intern :metal, 2000
assert_equal b, a
assert_same b, a
assert_equal c, a
assert_same false, c.equal?(a)
assert_same false, c.__id__.equal?(a.__id__)
assert_same false, (d == a)
assert_same false, d.equal?(a)
assert_same false, d.__id__.equal?(a.__id__)
assert_equal e.values, a.values
assert_same false, (e == a)
assert_same false, e.equal?(a)
assert_same false, e.__id__.equal?(a.__id__)
hash = {a => true}
assert_same true, hash[b]
assert_same true, hash[c]
assert_nil hash[d]
assert_nil hash[e]
end
end
Jump to Line
Something went wrong with that request. Please try again.