Skip to content

Commit

Permalink
Added tests to showcase more query examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mtabacman committed Jan 12, 2024
1 parent e1a8298 commit 6386b29
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,44 @@ GemStoneRepositoryProviderTest >> setUpRepositoryWith: aConflictCheckingStrategy
checkingConflictsAccordingTo: aConflictCheckingStrategy
]

{ #category : 'tests' }
GemStoneRepositoryProviderTest >> testMothershipQuery [

| fleets mothers motherships |

fleets := {
{
( Spaceship named: 'VF-1A' ).
( Spaceship named: 'VF-1D' ).
( Spaceship named: 'VF-1J' ).
( Spaceship named: 'VF-1S' ) } asSet.
{
( Spaceship named: 'VF-2A' ).
( Spaceship named: 'VF-2D' ).
( Spaceship named: 'VF-2J' ).
( Spaceship named: 'VF-2S' ) } asSet }.

mothers := {
( Mothership named: 'SDF-1' withAll: fleets first ).
( Mothership named: 'SDF-2' withAll: fleets last ).
( Mothership named: 'SDF-1' withAll: fleets last ) }.

motherships := GemStoneRepositoryProvider new
createRepositoryStoringObjectsOfType: Mothership
checkingConflictsAccordingTo: DoNotCheckForConflictsStrategy new.
motherships configureWith: [ :repository |
repository
indexByEquality: 'name' typed: String;
indexByEquality: 'fleet.*.name' typed: String
].

mothers do: [ :mother | motherships store: mother ].

motherships
withQueryFrom: '(each.fleet.*.name = ''VF-1D'') & (each.name = ''SDF-1'')'
do: [ :query | self assertCollection: query asArray hasSameElements: { mothers first } ]
]

{ #category : 'tests' }
GemStoneRepositoryProviderTest >> testQueryingWhenCollectionIsLargeAndIndexed [

Expand Down Expand Up @@ -52,7 +90,7 @@ GemStoneRepositoryProviderTest >> testQueryingWhenCollectionIsLargeAndIndexed [
]
]
]
notTakeMoreThanMilliseconds: 1
notTakeMoreThanMilliseconds: 2
]

{ #category : 'tests' }
Expand Down Expand Up @@ -96,6 +134,27 @@ GemStoneRepositoryProviderTest >> testQueryingWhenCollectionIsLargeButNotIndexed
notTakeMoreThanMilliseconds: 17
]

{ #category : 'tests' }
GemStoneRepositoryProviderTest >> testSpaceshipFirepowerRangeQuery [

| solvalou solgrado zeodalley |

self setUpRepositoryWithNoConflictChecking.
ships configureWith: [ :repository | repository indexByEquality: 'firepower' typed: Integer ].

solvalou := Spaceship withoutFirepowerNamed: 'Solvalou'.
solgrado := Spaceship named: 'Solgrado' firepower: 7650.
zeodalley := Spaceship named: 'Zeodalley' firepower: 2117.

ships store: solvalou.
ships store: solgrado.
ships store: zeodalley.

ships
withQueryFrom: '2117 < each.firepower <= 8000'
do: [ :query | self assertCollection: query queryResult asSet hasSameElements: { solgrado } ]
]

{ #category : 'tests' }
GemStoneRepositoryProviderTest >> testSpaceshipQueryingForPositiveFirepower [

Expand Down
4 changes: 3 additions & 1 deletion source/Sagan-GemStone/GemStoneRepository.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ GemStoneRepository >> withOneMatching: aCriteriaOrBlock sortedBy: aSortFunction
{ #category : 'querying' }
GemStoneRepository >> withQueryFrom: aQueryString do: aBlock [

^ aBlock value: ( ( GsQuery fromString: aQueryString )
^ aBlock value: ( ( GsQuery
fromString: aQueryString
options: GsQueryOptions default + GsQueryOptions cacheQueryResult )
on: contents;
yourself )
]

0 comments on commit 6386b29

Please sign in to comment.