Skip to content

Commit

Permalink
Do not rely on monkey when testing
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornharrtell committed Aug 29, 2023
1 parent a5dc833 commit 454e9d2
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 16 deletions.
56 changes: 44 additions & 12 deletions test/auto/node/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@ import GeometryFactory from '../../../src/org/locationtech/jts/geom/GeometryFact
import PrecisionModel from '../../../src/org/locationtech/jts/geom/PrecisionModel.js'
import WKTReader from '../../../src/org/locationtech/jts/io/WKTReader.js'
import WKTWriter from '../../../src/org/locationtech/jts/io/WKTWriter.js'
import '../../../src/org/locationtech/jts/monkey.js'
import BufferOp from '../../../src/org/locationtech/jts/operation/buffer/BufferOp.js'
import Centroid from '../../../src/org/locationtech/jts/algorithm/Centroid.js'
import ConvexHull from '../../../src/org/locationtech/jts/algorithm/ConvexHull.js'
import BoundaryOp from '../../../src/org/locationtech/jts/operation/BoundaryOp.js'
import OverlayOp from '../../../src/org/locationtech/jts/operation/overlay/OverlayOp.js'
import UnionOp from '../../../src/org/locationtech/jts/operation/union/UnionOp.js'
import RelateOp from '../../../src/org/locationtech/jts/operation/relate/RelateOp.js'
import IsValidOp from '../../../src/org/locationtech/jts/operation/valid/IsValidOp.js'
import IsSimpleOp from '../../../src/org/locationtech/jts/operation/IsSimpleOp.js'
//import '../../../src/org/locationtech/jts/monkey.js'

import BufferResultMatcher from '../BufferResultMatcher.js'


const dom = new JSDOM('')
const $ = jquery(dom.window)

Expand Down Expand Up @@ -44,6 +52,8 @@ export default function(doc, title) {
const writer = new WKTWriter(geometryFactory)

function fail(r, e, i) {
if (!r)
throw new Error('r is falsy: ' + r)
const rt = r ? writer.write(r) : 'undefined'
throw new Error(`\nResult: ${rt}\nExpected: ${e}\nInput: ${i}`)
}
Expand All @@ -62,20 +72,42 @@ export default function(doc, title) {
const bt = b ? writer.write(b) : 'undefined'
const inputs = ' Input geometry A: ' + at + ' B: ' + bt

const getCentroid = g => {
if (g.isEmpty()) return g.getFactory().createPoint()
const coord = Centroid.getCentroid(g)
g.getPrecisionModel().makePrecise(coord)
return g.getFactory().createPoint(coord)
}

var result

// switch execution logic depending on opname
if (opname === 'buffer')
result = a[opname](parseFloat(arg2))
else if (opname === 'getCentroid')
result = a[opname]()
else
if (arg3)
result = a[opname](b, arg3)
else
result = a[opname](b)


result = BufferOp.bufferOp(a, parseFloat(arg2))
else if (opname === 'getCentroid')
result = getCentroid(a)
else if (opname === 'getBoundary')
result = BoundaryOp.getBoundary(a)
else if (opname === 'intersection' || opname === 'difference' || opname === 'symDifference')
result = OverlayOp[opname](a, b)
else if (opname === 'union')
result = UnionOp.union(a, b)
else if (opname === 'intersects' || opname === 'contains')
result = RelateOp[opname](a, b)
else if (opname === 'relate')
result = RelateOp[opname](a, b).matches(arg3)
else if (opname === 'convexHull')
result = new ConvexHull(a).getConvexHull()
else if (opname === 'isValid')
result = IsValidOp.isValid(a)
else if (opname === 'isSimple')
result = IsSimpleOp.isSimple(a)
else if (opname === 'equalsExact')
result = a.equalsExact(b)
else if (opname === 'equalsNorm')
result = a.equalsNorm(b)
else
throw new Error('Unknown opname: ' + opname)

// switch comparison logic depending on opname
// TODO: should be a cleaner approach...
Expand Down
1 change: 0 additions & 1 deletion test/manual/io/GeoJSONReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,5 @@ describe('GeoJSONReader', function() {
'coordinates': [1, 1, 1]
}
const g = reader.read(point)
console.log(g)
})
})
4 changes: 2 additions & 2 deletions test/manual/issues/414.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import WKTReader from '../../../src/org/locationtech/jts/io/WKTReader.js'
import WKTWriter from '../../../src/org/locationtech/jts/io/WKTWriter.js'
import BufferOp from '../../../src/org/locationtech/jts/operation/buffer/BufferOp.js'

import '../../../src/org/locationtech/jts/monkey.js'
//import '../../../src/org/locationtech/jts/monkey.js'

describe('Test (#414)', function() {
const reader = new WKTReader()
Expand All @@ -17,7 +17,7 @@ describe('Test (#414)', function() {
const result = BufferOp.bufferOp(gc, 0)
const actual = writer.write(result)
expect(actual).to.eql(expected)
const result2 = gc.buffer(0)
const result2 = BufferOp.bufferOp(gc, 0)
const actual2 = writer.write(result2)
expect(actual2).to.eql(expected)
})
Expand Down
3 changes: 2 additions & 1 deletion test/manual/precision/CommonBitsOp.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import WKTReader from '../../../src/org/locationtech/jts/io/WKTReader.js'
import CommonBitsOp from '../../../src/org/locationtech/jts/precision/CommonBitsOp.js'
import GeometryFactory from '../../../src/org/locationtech/jts/geom/GeometryFactory.js'
import PrecisionModel from '../../../src/org/locationtech/jts/geom/PrecisionModel.js'
import OverlayOp from '../../../src/org/locationtech/jts/operation/overlay/OverlayOp.js'

describe('CommonBitsOp', function() {
var pm = new PrecisionModel( 1e20 )
Expand All @@ -20,7 +21,7 @@ describe('CommonBitsOp', function() {

it('Tests an issue where CommonBitsRemover was not persisting changes to some kinds of CoordinateSequences', function() {
var res = cbo.intersection(g1, g2)
var expected = g1.intersection(g2)
var expected = OverlayOp.intersection(g1, g2)
//expected = read("POLYGON ((220 215, 215 215, 215 220, 220 220, 220 215))");
var result = res.norm().equalsExact(expected.norm())
expect(result).to.be.true
Expand Down

0 comments on commit 454e9d2

Please sign in to comment.