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

toContainNumericIDs #50

Open
M-Scott-Lassiter opened this issue Jun 8, 2022 · 0 comments
Open

toContainNumericIDs #50

M-Scott-Lassiter opened this issue Jun 8, 2022 · 0 comments
Assignees
Labels
new matcher proposal Proposal for a new GeoJSON matcher

Comments

@M-Scott-Lassiter
Copy link
Owner

Description

GeoJSON Features have an optional ID member that can be any string or number. This matcher verifies that all Features within a FeatureCollection contain IDs and that they are all type number.

If a Feature has a commonly used identifier, that identifier SHOULD be included as a member of the Feature object with the name "id", and the value of this member is either a JSON string or number.

~ https://datatracker.ietf.org/doc/html/rfc7946#section-3.2

An "id" member on a non-feature object gets treated as a foreign member instead of an ID. Therefore, this matcher rejects non-FeatureCollection objects.

This test will fail if any of the IDs have a type string, do not have an ID, or if the "features" member is an empty array.

Example Matcher Usage

const goodTtestCollection = {
    type: "FeatureCollection",
    features: [{
        type: "Feature",
        geometry: {...},
        properties: {...},
        id: 1
    }, {
        type: "Feature",
        geometry: {...},
        properties: {...},
        id: 2
    }, {
        type: "Feature",
        geometry: {...},
        properties: {...},
        id: 3
    }]
}
const badTestCollection1 = {
    type: "FeatureCollection",
    features: [{
        type: "Feature",
        geometry: {...},
        properties: {...},
        id: "Test 1"
    }, {
        type: "Feature",
        geometry: {...},
        properties: {...},
        id: 2
    }]
}

const badTestCollection2 = {
    type: "FeatureCollection",
    features: [{
        type: "Feature",
        geometry: {...},
        properties: {...},
        id: 11
    }, {
        type: "Feature",
        geometry: {...},
        properties: {...},
    }]
}

expect(goodTtestCollection).toContainNumericIDs()

expect(badTestCollection1).not.toContainNumericIDs()
expect(badTestCollection2).not.toContainNumericIDs()
expect(goodTtestCollection.features[0]).not.toContainNumericIDs()

Passing Tests

Unique Numeric IDs

  • FeatureCollection with Single Feature with ID
  • FeatureCollection with 5 Features and unique IDs
  • Stress Test: FeatureCollection with 100 Features and unique IDs

Identical Numeric IDs

  • FeatureCollection with 5 Features and some repeated IDs
  • FeatureCollection with 5 Features and all repeated IDs

Failing Tests

Invalid Inputs To Matcher

Rejects each of the following:

  • Each of the seven Geometry objects
  • FeatureCollection object
  • undefined, null, false, true, 0
  • { someProp: 'I am not GeoJSON', id: 4 }
  • '',
  • 'Random Feature',
  • JSON.stringify({
          type: 'FeatureCollection',
          features: []
      })

Only Some Have Numeric IDs, the Rest Null or Not Mentioned

  • FeatureCollection with 5 Features, 1 has no "id" member
  • FeatureCollection with 5 Features, 1 has an "id" member with null

FeatureCollection with Empty Features Array

Should fail because there are no features to check IDs on.

FeatureCollection with No ID

Should fail with a single feature that has no ID.

All Have String IDs

  • FeatureCollection with Single Feature and ID
  • FeatureCollection with 5 Features and unique IDs
  • FeatureCollection with 5 Features and repeated IDs

Only Some Have String IDs, the Rest Numeric ID, Null, or Not Mentioned

  • FeatureCollection with 5 Features
  • FeatureCollection with 100 Features
@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new matcher proposal Proposal for a new GeoJSON matcher
Projects
None yet
Development

No branches or pull requests

1 participant