require 'test/unit' require 'eymiha' class TC_object < Test::Unit::TestCase def test_raise assert_raise(TypeError) { raise_no_conversion(self,true) } end end class TC_hash < Test::Unit::TestCase def setup @hash1 = { 1 => 'one' } @hash2 = { [ :common ] => { 'time' => 'money' } } @hash3 = { :elements => [ :earth, :air, :fire, :water] } @hash4 = { 2 => 'two', 3=> 'three' } end def test_to_s assert(@hash1.to_s == "{ 1 => one }") assert(@hash2.to_s == "{ [ common ] => { time => money } }") assert(@hash3.to_s == "{ elements => [ earth, air, fire, water ] }") s = @hash4.to_s assert((s == "{ 2 => two, 3 => three }") || (s == "{ 3 => three, 2 => two }")) end end class TC_array < Test::Unit::TestCase def setup @array = [ 1, 'one', { 'time' => 'money' }, :elements, [ :earth, :air, :fire, :water] ] end def test_to_s assert(@array.to_s == "[ 1, one, { time => money }, elements, [ earth, air, fire, water ] ]") end end class TC_class_name < Test::Unit::TestCase def test_class_name assert(class_name == "TC_class_name") assert(self.class.class_name == "TC_class_name") assert("foo".class_name == "String") assert(String.class_name == "String") end end class Reader class_attr_reader :read_me class_attr_reader :read_me1, :read_me2 end class Writer class_attr_writer :write_me class_attr_writer :write_me1, :write_me2 end class Accessor class_attr_accessor :access_me class_attr_accessor :access_me1, :access_me2 def to_s "'#{@@access_me}'" end def to_s1 "'#{@@access_me1}'" end def to_s2 "'#{@@access_me2}'" end end class TC_class_attr < Test::Unit::TestCase def test_class_attr_reader assert(Reader.read_me == nil) assert(Reader.read_me1 == nil) assert(Reader.read_me2 == nil) end def test_class_attr_writer assert_nothing_raised {Writer.write_me = "write"} assert_nothing_raised {Writer.write_me1 = "write1"} assert_nothing_raised {Writer.write_me2 = "write2"} end def test_class_attr_accessor a = Accessor.new assert(Accessor.access_me == nil) assert(a.to_s == "''") assert(Accessor.access_me1 == nil) assert(a.to_s1 == "''") assert(Accessor.access_me2 == nil) assert(a.to_s2 == "''") assert_nothing_raised {Accessor.access_me = "access"} assert_nothing_raised {Accessor.access_me1 = "access1"} assert_nothing_raised {Accessor.access_me2 = "access2"} assert(Accessor.access_me == "access") assert(a.to_s == "'access'") assert(Accessor.access_me1 == "access1") assert(a.to_s1 == "'access1'") assert(Accessor.access_me2 == "access2") assert(a.to_s2 == "'access2'") end end