Skip to content

Commit

Permalink
AbstractCoordaintes: add random message (to be implemented in subclas…
Browse files Browse the repository at this point in the history
…ses).

Implement random for AbsoluteCoordinates.
  • Loading branch information
Pierre Laborde committed Feb 12, 2024
1 parent e33deb8 commit 26c9e54
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
16 changes: 16 additions & 0 deletions GeoTools-Tests/CoordinatesTests.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
15 changes: 15 additions & 0 deletions GeoTools/AbsoluteCoordinates.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,21 @@ AbsoluteCoordinates class >> latitudeInRadians: aLatitudeInRadians longitudeInRa
^coordinates
]

{ #category : #'instance creation' }
AbsoluteCoordinates class >> random [
<script: 'self random inspect'>

| 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 [

Expand Down

0 comments on commit 26c9e54

Please sign in to comment.