Sha256: a529c3494b7b1fb2e32fbfdfbd8624cd40f0203bf8089e5caa5289a52e0d61b1

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 KB

Contents

require File.join File.dirname(__FILE__), 'env.rb'

include CartoJson

describe LineString do
  before do
    @args = {:points => [
      {LAT => 45.52, LNG => -122.681944},
      {LAT => 45.53, LNG => -122.681945},
      {LAT => 45.54, LNG => -122.681946}]}
  end

  it 'should create a linestring with valid data' do
    ls = LineString.new @args
    ls.type.must_equal :linestring
    ls.class.type.must_equal :linestring
    ls.points.first.class.must_equal Point

    hash = MultiJson.decode(ls.to_json, :symbolize_keys => true)
    hash[:points].length.must_equal 3
    hash[:points].first[LAT].must_equal @args[:points].first[LAT]
    hash[:points].first[LNG].must_equal @args[:points].first[LNG]

    ls.to_wkt.must_equal "LINESTRING ((#{ls.points.dup.push(ls.points.first).collect {|p| "#{p.send(LNG)} #{p.send(LAT)}"}.join(', ')}))"
  end

  it 'should fail if less than three points' do
    @args[:points].pop
    @args[:points].pop
    lambda { LineString.new @args }.must_raise InsufficientPointsError
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
carto_json-0.0.6 spec/line_string_spec.rb