require 'test/unit' require 'eymiha/math/rectify' class TC_rectify < Test::Unit::TestCase def test_wrap_rectify assert(0.5.wrap_rectify(1) == 0.5) assert(5.5.wrap_rectify(1) =~ 0.5) assert(-7.25.wrap_rectify(2) =~ 0.75) assert(-7.25.wrap_rectify(2,0.5) =~ 1.75) assert(-7.25.wrap_rectify(0.5,2) =~ 1.75) assert(2.wrap_rectify(0.5,2) == 0.5) assert(0.5.wrap_rectify(0.5,2) == 0.5) assert(0.5.wrap_rectify(0,0) == 0) end def test_cut_rectify assert(0.5.cut_rectify(1) == 0.5) assert(5.5.cut_rectify(1) == 1) assert(-7.25.cut_rectify(2) == 0) assert(-7.25.cut_rectify(2,0.5) == 0.5) assert(-7.25.cut_rectify(0.5,2) == 0.5) assert(2.cut_rectify(0.5,2) == 2) assert(0.5.cut_rectify(0.5,2) == 0.5) assert(0.5.cut_rectify(0,0) == 0) end def test_at_most assert((-5..5).collect{|v| v.at_most(2)} == [-5,-4,-3,-2,-1,0,1,2,2,2,2]) end def test_at_least assert((-5..5).collect{|v| v.at_least(-1.5)} == [-1.5,-1.5,-1.5,-1.5,-1,0,1,2,3,4,5]) end end