Sha256: 6daa7227556fff9f776d3129bc0451914d2ee27c408382b6500ca130c37de2af

Contents?: true

Size: 1.93 KB

Versions: 1

Compression:

Stored size: 1.93 KB

Contents

require 'shape'
require 'test/unit'

class ShapeTest < Test::Unit::TestCase

  def test_abstract
    # Shape.new.svg
  end

end


class LineTest <  Test::Unit::TestCase

  def test_point
    line = Line[ :points, [ V2D[ 0.0, 0.0], V2D[ 0.0, 1.0] ] ]
    # puts Line.instance_methods(false)
    assert_equal( V2D[0.0, 0.3], line.point( 0.3 ) )
  end

  def test_tangent
    line = Line[ :points, [ V2D[ 0.0, 0.0], V2D[ 0.0, 2.0] ] ]
    assert_equal( V2D[0.0, 1.0], line.tangent( 0.3 ) )
  end

  def test_frame
    line = Line[ :points, [ V2D[ 0.0, 0.0], V2D[ 0.0, 1.0] ] ]
    result = Frame[ :center, V2D[0.0,0.5], :vector,  V2D[0.0,0.0], :rotation,  0.0, :scale, 1.0 ]
    assert_equal( result, line.frame( 0.5 ) )
  end


  def test_svg
    line = Line[ :points, [ V2D[ 0.0, 0.0], V2D[ 0.0, 1.0], V2D[ 0.0, 2.0] ] ]
    assert_equal( '<path d="M 0.0 0.0 L 0.0 1.0L 0.0 2.0"/>', line.svg )
  end

  def test_samples
    [Line[].samples(3), [V2D[0.0,0.0], V2D[0.5,0.5], V2D[1.0,1.0]] ].forzip do |v1, v2|
      assert( V2D.vequal?( v1, v2 ) )
    end
  end
end

class CircleTest < Test::Unit::TestCase

  def test_default
    circle = Circle[]
    assert_equal( '<circle cx="0.0" cy="0.0" r="1.0"/>', circle.svg )
  end    

  def test_svg
    circle = Circle[ :center, V2D[ 0.0, 0.0 ], :radius, 1.0 ]
    assert_equal( '<circle cx="0.0" cy="0.0" r="1.0"/>', circle.svg )
  end

  def test_viewbox
    circle = Circle[ :center, V2D[ 0.0, 0.0 ], :radius, 1.0 ]
    assert_equal( [-1.0, -1.0, 1.0, 1.0], circle.viewbox )
  end

  def test_samples
    [Circle[].samples(3), [V2D[1.0,0.0], V2D[-1.0,0.0], V2D[1.0,0.0]] ].forzip do |v1, v2|
      assert( V2D.vequal?( v1, v2 ) )
    end
  end

  def test_diameter
    cd = Circle.diameter( V2D[0.0,1.0], V2D[0.0,-1.0] )
    c2 = Circle[ :center, V2D::O, :radius, 1.0 ]
    assert( V2D.vequal?( cd.center, c2.center ) )
    assert_equal( cd.radius, c2.radius )
    assert( V2D.vequal?( V2D[0.0,1.0], cd.point( 0.0 ) ) )
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
xrvg-0.0.3 test/test_shape.rb