Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toHaveMinGeometryCount #45

Closed
M-Scott-Lassiter opened this issue Jun 8, 2022 · 1 comment
Closed

toHaveMinGeometryCount #45

M-Scott-Lassiter opened this issue Jun 8, 2022 · 1 comment

Comments

@M-Scott-Lassiter
Copy link
Owner

M-Scott-Lassiter commented Jun 8, 2022

Description

A GeoJSON GeometryCollection contains a "geometries" member with an array of GeoJSON geometry objects.

This matcher uses the toBeGeometryCollection functionality to verify the input is a properly formatted GeometryCollection object, and then determine if it has more than or equal to the MinCount value. It will throw an error for any of the other geometry types as it is a trivial comparison on those.

Omitting MinCount will assume a minimum value of 1. Passing a number less than 0 will throw an error. Decimals will get truncated.

Example Matcher Usage

const testCollection = {
    "type": "GeometryCollection",
    "geometries": [{
        "type": "Point",
        "coordinates": [100.0, 0.0]
    }, {
        "type": "LineString",
        "coordinates": [
            [101.0, 0.0],
            [102.0, 1.0]
        ]
    }, {
        "type": "Polygon",
        "coordinates": [
            [
                [102.0, 2.0],
                [103.0, 2.0],
                [103.0, 3.0],
                [102.0, 3.0],
                [102.0, 2.0]
            ]
        ]
    }, {
        "type": "Point",
        "coordinates": [150.0, 73.0]
    }]
}
const emptyCollection = {
    "type": "GeometryCollection",
    "geometries": []
}
const polygon = {
    type: 'Polygon',
    coordinates: [
        [
            [100.0, 0.0],
            [101.0, 0.0],
            [101.0, 1.0],
            [100.0, 1.0],
            [100.0, 0.0]
        ]
    ]
}

expect(testCollection).toHaveMinGeometryCount()
expect(testCollection).toHaveMinGeometryCount(4)

expect(testCollection).not.toHaveMinGeometryCount(5)
expect(emptyCollection).not.toHaveMinGeometryCount()
expect(polygon).not.toHaveMinGeometryCount(1)

Passing Tests

Good GeometryCollection

  • Known good GeometryCollection with a single geometry
    • .toHaveMinGeometryCount()
    • .toHaveMinGeometryCount(0.9)
    • .toHaveMinGeometryCount(1)
    • .toHaveMinGeometryCount(1.2)
  • Known good GeometryCollection with 4 geometries
    • .toHaveMinGeometryCount()
    • .toHaveMinGeometryCount(3)
    • .toHaveMinGeometryCount(4)
    • .toHaveMinGeometryCount(4.999)
  • Stress test: Known good GeometryCollection with 100 geometries
    • .toHaveMinGeometryCount()
    • .toHaveMinGeometryCount(1)
    • .toHaveMinGeometryCount(50)
    • .toHaveMinGeometryCount(100)
  • Empty Geometry
    • .toHaveMinGeometryCount(0)
    • .toHaveMinGeometryCount(0.1)
    • .toHaveMinGeometryCount(0.9)

Failing Tests

Invalid Inputs To Matcher

Rejects each of the following:

  • Each of the seven Geometry objects except GeometryCollection
  • An invalid GeometryCollection
  • Feature and FeatureCollection object
  • undefined, null, false, true, 0, NaN
  • { someProp: 'I am not GeoJSON', id: 4 }
  • {}
  • '',
  • 'Random Feature',
  •   JSON.stringify({
          "type": "GeometryCollection",
          "geometries": [{
              "type": "Point",
              "coordinates": [100.0, 0.0]
          }, {
              "type": "LineString",
              "coordinates": [
                  [101.0, 0.0],
                  [102.0, 1.0]
              ]
          }, {
              "type": "Polygon",
              "coordinates": [
                  [
                      [102.0, 2.0],
                      [103.0, 2.0],
                      [103.0, 3.0],
                      [102.0, 3.0],
                      [102.0, 2.0]
                  ]
              ]
          }, {
              "type": "Point",
              "coordinates": [150.0, 73.0]
          }]
      })

Valid GeometryCollection With Bad MinCount

  • Good GeometryCollection with MinCount as each of the values in "Invalid Inputs To Matcher" except 0

Valid GeometryCollection With Out of Range MinCount

  • Known good GeometryCollection with a single geometry
    • .not.toHaveMinGeometryCount(-1)
    • .not.toHaveMinGeometryCount(2)
  • Known good GeometryCollection with 4 geometries
    • .not.toHaveMinGeometryCount(-10)
    • .not.toHaveMinGeometryCount(-0.001)
    • .not.toHaveMinGeometryCount(5)
  • Stress test: Known good GeometryCollection with 100 geometries
    • .not.toHaveMinGeometryCount(-Infinity)
    • .not.toHaveMinGeometryCount(101)
  • Empty Geometry
    • .not.toHaveMinGeometryCount(-1)
    • .not.toHaveMinGeometryCount(1)
    • .not.toHaveMinGeometryCount()
@M-Scott-Lassiter M-Scott-Lassiter added the new matcher proposal Proposal for a new GeoJSON matcher label Jun 8, 2022
@M-Scott-Lassiter M-Scott-Lassiter self-assigned this Jun 8, 2022
@M-Scott-Lassiter M-Scott-Lassiter added matchers/geometries and removed new matcher proposal Proposal for a new GeoJSON matcher labels Jun 12, 2022
github-actions bot pushed a commit that referenced this issue Jun 12, 2022
## [1.6.0](v1.5.0...v1.6.0) (2022-06-12)

### 🧭 API Documentation Changes

* **toHaveGeometryCount:** improve error messages and description for nested GeometryCollections behavior ([01fe745](01fe745))

### 🐞 Bug Fixes

* **toHaveGeometryCount:** correct issue where empty collections would fail when provided with a valid range ([93dadff](93dadff)), closes [#58](#58)

### 🎁 Feature Changes

* **toHaveMaxGeometryCount:** add new matcher ([8a1f103](8a1f103)), closes [#47](#47)
* **toHaveMinGeometryCount:** add new matcher ([c71c21a](c71c21a)), closes [#45](#45)
@M-Scott-Lassiter
Copy link
Owner Author

🎉 This issue has been resolved in version 1.6.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant