Sha256: 884f89eb99a433ab4cced7ca09eadbc45d1fa90053010463ca031d58f38f95ae

Contents?: true

Size: 1.96 KB

Versions: 1

Compression:

Stored size: 1.96 KB

Contents

RSpec.describe H3 do
  include_context "constants"

  describe ".polyfill" do
    let(:geojson) do
      File.read(File.join(File.dirname(__FILE__), "support/fixtures/banbury_without_holes.json"))
    end
    let(:resolution) { 9 }
    let(:expected_count) { 14_369 }

    subject(:polyfill) { H3.polyfill(geojson, resolution) }

    it "has the correct number of hexagons" do
      expect(polyfill.count).to eq expected_count
    end

    context "when banbury area has two holes in it" do
      let(:geojson) do
        File.read(File.join(File.dirname(__FILE__), "support/fixtures/banbury.json"))
      end
      let(:expected_count) { 13_526 }

      it "has fewer hexagons" do
        expect(polyfill.count).to eq expected_count
      end
    end

    context "when polyfilling australia" do
      let(:geojson) do
        File.read(File.join(File.dirname(__FILE__), "support/fixtures/australia.json"))
      end
      let(:expect_count) { 92 }

      it "has the correct number of hexagons" do
        expect(polyfill.count).to eq expect_count
      end
    end
  end

  describe ".max_polyfill_size" do
    let(:geojson) do
      File.read(File.join(File.dirname(__FILE__), "support/fixtures/banbury.json"))
    end
    let(:resolution) { 9 }
    let(:expected_count) { 75_367 }

    subject(:max_polyfill_size) { H3.max_polyfill_size(geojson, resolution) }

    it "has the correct number of hexagons" do
      expect(max_polyfill_size).to eq expected_count
    end
  end

  describe ".h3_set_to_linked_geo" do
    let(:geojson) do
      File.read(File.join(File.dirname(__FILE__), "support/fixtures/banbury.json"))
    end
    let(:resolution) { 8 }
    let(:hexagons) { H3.polyfill(geojson, resolution) }

    subject(:h3_set_to_linked_geo) { H3.h3_set_to_linked_geo(hexagons) }
    
    it "has 3 outlines" do
      h3_set_to_linked_geo.count == 3
    end

    it "can be converted to GeoJSON" do
      expect(H3.coordinates_to_geo_json(h3_set_to_linked_geo)).to be_truthy
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
h3-3.6.2 spec/regions_spec.rb