-
Notifications
You must be signed in to change notification settings - Fork 12
Lazy Relation #125
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
Merged
Merged
Lazy Relation #125
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
93fc0bb
enable lazy relation in fame
badetitou 73decca
introduce lazyness in baseline
badetitou 2f3e8a3
remove fr comments
badetitou 1e7cd0e
add test when adding entities to the other direction of a lazy relation
badetitou da851f7
current limitation
badetitou 90d3584
add test
badetitou e9ac654
add another currentLimitation test
badetitou 7a9e666
Apply batched suggestions from code review
badetitou b717aa7
Apply batched suggestions from code review
badetitou 947cdfb
Apply batched suggestions from code review
badetitou dc11bc7
skip test instead of commenting the cod
badetitou b6ea64c
Merge 947cdfb4a36995a96a386921426b93093d425981
badetitou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
240 changes: 240 additions & 0 deletions
240
src/Fame-LazyRelations-Tests/FMLazyRelationTest.class.st
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,240 @@ | ||
| Class { | ||
| #name : 'FMLazyRelationTest', | ||
| #superclass : 'TestCase', | ||
| #category : 'Fame-LazyRelations-Tests', | ||
| #package : 'Fame-LazyRelations-Tests' | ||
| } | ||
|
|
||
| { #category : 'tests' } | ||
| FMLazyRelationTest >> testAccessMaterializesRelation [ | ||
|
|
||
| | entity loaded relation | | ||
| entity := RPGLazyHero new. | ||
|
|
||
| loaded := false. | ||
| FMLazyValue | ||
| makeRelation: #kills | ||
| of: entity | ||
| lazyUsing: [ :rel :entit | loaded := true ]. | ||
|
|
||
| self deny: loaded. | ||
|
|
||
| relation := entity kills. | ||
|
|
||
| self assert: loaded. | ||
| self assert: relation class equals: FMSlotMultivalueLink | ||
| ] | ||
|
|
||
| { #category : 'tests' } | ||
| FMLazyRelationTest >> testAddEntitiesInRelation [ | ||
|
|
||
| | entity relation | | ||
| entity := RPGLazyHero new. | ||
|
|
||
| FMLazyValue | ||
| makeRelation: #kills | ||
| of: entity | ||
| lazyUsing: [ :rel :entit | | ||
| rel addAll: { | ||
| RPGLazyDragon new. | ||
| RPGLazyDragon new } ]. | ||
|
|
||
| relation := entity kills. | ||
|
|
||
| self assert: relation size equals: 2. | ||
| self assert: relation anyOne killedBy anyOne equals: entity | ||
| ] | ||
|
|
||
| { #category : 'tests' } | ||
| FMLazyRelationTest >> testAddToLazyRelation [ | ||
|
|
||
| | entity dragon | | ||
| entity := RPGLazyHero new. | ||
|
|
||
| FMLazyValue | ||
| makeRelation: #kills | ||
| of: entity | ||
| lazyUsing: [ :rel :entit | | ||
| rel addAll: { | ||
| RPGLazyDragon new. | ||
| RPGLazyDragon new } ]. | ||
|
|
||
| dragon := RPGLazyDragon new. | ||
|
|
||
| dragon killedBy: { entity }. | ||
|
|
||
| self assert: dragon killedBy size equals: 1. | ||
| self assert: dragon killedBy anyOne equals: entity. | ||
| self assert: entity kills size equals: 3. | ||
| self assert: entity kills last identicalTo: dragon | ||
| ] | ||
|
|
||
| { #category : 'tests' } | ||
| FMLazyRelationTest >> testByPassByDirectlyAdding [ | ||
|
|
||
| | entity dragon | | ||
| entity := RPGLazyHero new. | ||
|
|
||
| FMLazyValue | ||
| makeRelation: #kills | ||
| of: entity | ||
| lazyUsing: [ :rel :entit | | ||
| rel addAll: { | ||
| RPGLazyDragon new. | ||
| RPGLazyDragon new } ]. | ||
|
|
||
| dragon := RPGLazyDragon new. | ||
|
|
||
| entity kills: { dragon }. | ||
|
|
||
| self assert: entity kills size equals: 1. | ||
| self assert: entity kills anyOne identicalTo: dragon | ||
| ] | ||
|
|
||
| { #category : 'tests' } | ||
| FMLazyRelationTest >> testDefaultBehavior [ | ||
|
|
||
| | entity dragon | | ||
| entity := RPGLazyHero new. | ||
| dragon := RPGLazyDragon new. | ||
| dragon killedBy: { entity }. | ||
|
|
||
| self assert: dragon killedBy size equals: 1. | ||
| self assert: dragon killedBy anyOne equals: entity. | ||
| self assert: entity kills size equals: 1. | ||
| self assert: entity kills anyOne equals: dragon | ||
| ] | ||
|
|
||
| { #category : 'tests' } | ||
| FMLazyRelationTest >> testManyToOneWithlazyOne [ | ||
|
|
||
| | entity hero hero2 | | ||
| self flag: #currentLimitation. | ||
| self skip. | ||
| entity := RPGLazyTalisman new. | ||
| hero := RPGLazyHero new. | ||
| hero2 := RPGLazyHero new. | ||
|
|
||
| FMLazyValue | ||
| makeRelation: #owner | ||
| of: entity | ||
| lazyUsing: [ :rel :entit | rel value: hero ]. | ||
| hero2 talismans: { entity }. | ||
| self assert: entity owner identicalTo: hero2. | ||
| self assert: hero talismans size equals: 0. | ||
| self assert: hero2 talismans anyOne identicalTo: entity | ||
| ] | ||
|
|
||
| { #category : 'tests' } | ||
| FMLazyRelationTest >> testOneToManyRelation [ | ||
|
|
||
| | entity hero | | ||
| entity := RPGLazyTalisman new. | ||
| hero := RPGLazyHero new. | ||
|
|
||
| FMLazyValue | ||
| makeRelation: #owner | ||
| of: entity | ||
| lazyUsing: [ :rel :entit | rel value: hero ]. | ||
|
|
||
| self assert: entity owner identicalTo: hero. | ||
| self assert: hero talismans size equals: 1. | ||
| self assert: hero talismans anyOne identicalTo: entity | ||
| ] | ||
|
|
||
| { #category : 'tests' } | ||
| FMLazyRelationTest >> testOneToManyRelationTwiceCalled [ | ||
|
|
||
| | entity hero count | | ||
| entity := RPGLazyTalisman new. | ||
| hero := RPGLazyHero new. | ||
| count := 0. | ||
|
|
||
| FMLazyValue | ||
| makeRelation: #owner | ||
| of: entity | ||
| lazyUsing: [ :rel :entit | | ||
| count := count + 1. | ||
| rel value: hero ]. | ||
| entity owner. | ||
| entity owner. | ||
|
|
||
| self assert: count equals: 1 | ||
| ] | ||
|
|
||
| { #category : 'tests' } | ||
| FMLazyRelationTest >> testOneToOneRelation [ | ||
|
|
||
| | weapon hero | | ||
| weapon := RPGLazyUniqueWeapon new. | ||
| hero := RPGLazyHero new. | ||
|
|
||
| FMLazyValue | ||
| makeRelation: #owner | ||
| of: weapon | ||
| lazyUsing: [ :rel :entit | rel value: hero ]. | ||
|
|
||
| self assert: weapon owner identicalTo: hero | ||
| ] | ||
|
|
||
| { #category : 'tests' } | ||
| FMLazyRelationTest >> testOneToOneRelationReverse [ | ||
|
|
||
| | weapon weapon2 hero | | ||
| self flag: #currentLimitation. | ||
| self skip. | ||
| weapon := RPGLazyUniqueWeapon new. | ||
| hero := RPGLazyHero new. | ||
| weapon2 := RPGLazyUniqueWeapon new. | ||
|
|
||
| FMLazyValue | ||
| makeRelation: #owner | ||
| of: weapon | ||
| lazyUsing: [ :rel :entit | rel value: hero ]. | ||
|
|
||
| hero uniqueWeapon: weapon2. | ||
|
|
||
| self assert: hero uniqueWeapon identicalTo: weapon2. | ||
| self assert: weapon owner isNil. | ||
| ] | ||
|
|
||
| { #category : 'tests' } | ||
| FMLazyRelationTest >> testRelationIsLoadedOnlyOnce [ | ||
|
|
||
| | entity count first second | | ||
| entity := RPGLazyHero new. | ||
| count := 0. | ||
|
|
||
| FMLazyValue | ||
| makeRelation: #kills | ||
| of: entity | ||
| lazyUsing: [ :relation :entit | count := count + 1 ]. | ||
|
|
||
| first := entity kills. | ||
| second := entity kills. | ||
|
|
||
| self assert: count equals: 1. | ||
| self assert: first identicalTo: second | ||
| ] | ||
|
|
||
| { #category : 'tests' } | ||
| FMLazyRelationTest >> testRelationIsNotAppliedToAllEntities [ | ||
|
|
||
| | entity entity2 count first second first2 | | ||
| entity := RPGLazyHero new. | ||
| entity2 := RPGLazyHero new. | ||
| count := 0. | ||
|
|
||
| FMLazyValue | ||
| makeRelation: #kills | ||
| of: entity | ||
| lazyUsing: [ :relation :entit | count := count + 1 ]. | ||
|
|
||
| first := entity kills. | ||
| second := entity kills. | ||
|
|
||
| first2 := entity2 kills. | ||
|
|
||
| self assert: count equals: 1. | ||
| self assert: first identicalTo: second | ||
| ] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| Class { | ||
| #name : 'RPGLazyDragon', | ||
| #superclass : 'RPGLazyEntity', | ||
| #instVars : [ | ||
| '#killedBy => FMMany type: #RPGLazyHero opposite: #kills' | ||
| ], | ||
| #category : 'Fame-LazyRelations-Tests-Example', | ||
| #package : 'Fame-LazyRelations-Tests', | ||
| #tag : 'Example' | ||
| } | ||
|
|
||
| { #category : 'accessing' } | ||
| RPGLazyDragon >> killedBy [ | ||
|
|
||
| ^ killedBy | ||
| ] | ||
|
|
||
| { #category : 'accessing' } | ||
| RPGLazyDragon >> killedBy: anObject [ | ||
| "value when multimulti relation" | ||
| killedBy value: anObject | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| Class { | ||
| #name : 'RPGLazyEntity', | ||
| #superclass : 'Object', | ||
| #category : 'Fame-LazyRelations-Tests-Example', | ||
| #package : 'Fame-LazyRelations-Tests', | ||
| #tag : 'Example' | ||
| } | ||
|
|
||
| { #category : 'initialization' } | ||
| RPGLazyEntity >> initialize [ | ||
|
|
||
| super initialize. | ||
| self class initializeSlots: self | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| Class { | ||
| #name : 'RPGLazyHero', | ||
| #superclass : 'RPGLazyEntity', | ||
| #instVars : [ | ||
| '#kills => FMMany type: #RPGLazyDragon opposite: #killedBy', | ||
| '#talismans => FMMany type: #RPGLazyTalisman opposite: #owner', | ||
| '#uniqueWeapon => FMOne type: #RPGLazyUniqueWeapon opposite: #owner' | ||
| ], | ||
| #category : 'Fame-LazyRelations-Tests-Example', | ||
| #package : 'Fame-LazyRelations-Tests', | ||
| #tag : 'Example' | ||
| } | ||
|
|
||
| { #category : 'accessing' } | ||
| RPGLazyHero >> kills [ | ||
|
|
||
| ^ kills | ||
| ] | ||
|
|
||
| { #category : 'accessing' } | ||
| RPGLazyHero >> kills: anObject [ | ||
| "value when multimulti relation" | ||
|
|
||
| kills value: anObject | ||
| ] | ||
|
|
||
| { #category : 'accessing' } | ||
| RPGLazyHero >> talismans [ | ||
|
|
||
| ^ talismans | ||
| ] | ||
|
|
||
| { #category : 'accessing' } | ||
| RPGLazyHero >> talismans: anObject [ | ||
|
|
||
| talismans := anObject | ||
| ] | ||
|
|
||
| { #category : 'accessing' } | ||
| RPGLazyHero >> uniqueWeapon [ | ||
|
|
||
| ^ uniqueWeapon | ||
| ] | ||
|
|
||
| { #category : 'accessing' } | ||
| RPGLazyHero >> uniqueWeapon: anObject [ | ||
|
|
||
| uniqueWeapon := anObject | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| Class { | ||
| #name : 'RPGLazyTalisman', | ||
| #superclass : 'RPGLazyEntity', | ||
| #instVars : [ | ||
| '#owner => FMOne type: #RPGLazyHero opposite: #talismans' | ||
| ], | ||
| #category : 'Fame-LazyRelations-Tests-Example', | ||
| #package : 'Fame-LazyRelations-Tests', | ||
| #tag : 'Example' | ||
| } | ||
|
|
||
| { #category : 'accessing' } | ||
| RPGLazyTalisman >> owner [ | ||
|
|
||
| ^ owner | ||
| ] | ||
|
|
||
| { #category : 'accessing' } | ||
| RPGLazyTalisman >> owner: anObject [ | ||
|
|
||
| owner := anObject | ||
| ] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.