diff --git a/GeoTools-Tests/CoordinatesTests.class.st b/GeoTools-Tests/CoordinatesTests.class.st index f0c4ee8..0efa4e4 100644 --- a/GeoTools-Tests/CoordinatesTests.class.st +++ b/GeoTools-Tests/CoordinatesTests.class.st @@ -164,6 +164,22 @@ CoordinatesTests >> testAbsoluteCoordinatesPrintOn [ self assert: coord printString equals: 'an AbsoluteCoordinates lat 48.3897° lon -4.48333° alt 52m'. ] +{ #category : #tests } +CoordinatesTests >> testAbsoluteCoordinatesRandom [ + | coord | + coord := AbsoluteCoordinates random. + self deny: coord isEmpty. + self assert: coord isValid. + self deny: coord latitudeInDegrees isNil. + self deny: coord latitude isNil. + self deny: coord longitudeInDegrees isNil. + self deny: coord longitude isNil. + + "random not generate an altitude value" + self assert: coord altitudeInMeters isNil. + self assert: coord altitude isNil. +] + { #category : #tests } CoordinatesTests >> testAbsoluteCoordinatesZero [ | coord | diff --git a/GeoTools/AbsoluteCoordinates.class.st b/GeoTools/AbsoluteCoordinates.class.st index 47646d3..e5e3b05 100644 --- a/GeoTools/AbsoluteCoordinates.class.st +++ b/GeoTools/AbsoluteCoordinates.class.st @@ -122,6 +122,21 @@ AbsoluteCoordinates class >> latitudeInRadians: aLatitudeInRadians longitudeInRa ^coordinates ] +{ #category : #'instance creation' } +AbsoluteCoordinates class >> random [ + + + | random | + random := Random new. + ^ self + latitudeInDegrees: random next * 90 * (random next > 0.5 + ifTrue: [ 1 ] + ifFalse: [ 1 negated ]) + longitudeInDegrees: random next * 180 * (random next > 0.5 + ifTrue: [ 1 ] + ifFalse: [ 1 negated ]) +] + { #category : #'instance creation' } AbsoluteCoordinates class >> usaLosAngeles [