forked from pharo-project/pharo
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
1,132 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
32 changes: 32 additions & 0 deletions
32
src/Moose-Algos-Graph-Tests/MalBreadthFirstSearchPathTest.class.st
This file contains 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,32 @@ | ||
Class { | ||
#name : #MalBreadthFirstSearchPathTest, | ||
#superclass : #TestCase, | ||
#instVars : [ | ||
'bfsp' | ||
], | ||
#category : #'Moose-Algos-Graph-Tests' | ||
} | ||
|
||
{ #category : #running } | ||
MalBreadthFirstSearchPathTest >> setUp [ | ||
super setUp. | ||
bfsp := MalBreadthFirstSearchPath new | ||
] | ||
|
||
{ #category : #tests } | ||
MalBreadthFirstSearchPathTest >> testAseGraph [ | ||
MalGraphFixture aseCircuitGraph: bfsp. | ||
self assert: (#($a $b $c) hasEqualElements: (bfsp runFrom: $a to: $c)). | ||
self assert: (#($d $b $c) hasEqualElements: (bfsp runFrom: $d to: $c)). | ||
self assert: (#($e $a) hasEqualElements: (bfsp runFrom: $e to: $a)). | ||
self assert: (#($a $b $d $e) hasEqualElements: (bfsp runFrom: $a to: $e)). | ||
self assert: (#($d $b $c $f) hasEqualElements: (bfsp runFrom: $d to: $f)). | ||
self should: [ bfsp runFrom: $f to: $a ] raise: Error | ||
] | ||
|
||
{ #category : #tests } | ||
MalBreadthFirstSearchPathTest >> testSimpleGraph [ | ||
MalGraphFixture simpleGraph: bfsp. | ||
self assert: (#($a $b $c) hasEqualElements: (bfsp runFrom: $a to: $c)). | ||
self assert: (#($d $c) hasEqualElements: (bfsp runFrom: $d to: $c)) | ||
] |
89 changes: 89 additions & 0 deletions
89
src/Moose-Algos-Graph-Tests/MalCyclesCoverageTest.class.st
This file contains 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,89 @@ | ||
Class { | ||
#name : #MalCyclesCoverageTest, | ||
#superclass : #TestCase, | ||
#instVars : [ | ||
'cc' | ||
], | ||
#category : #'Moose-Algos-Graph-Tests' | ||
} | ||
|
||
{ #category : #running } | ||
MalCyclesCoverageTest >> setUp [ | ||
super setUp. | ||
cc := MalCyclesCoverage new | ||
] | ||
|
||
{ #category : #'tests-cse' } | ||
MalCyclesCoverageTest >> testAseCircuitWithCse [ | ||
cc useCircuitSpan. | ||
MalGraphFixture aseCircuitGraph: cc. | ||
cc run. | ||
self assert: 5 equals: cc circuits size. | ||
#(#($g $h) #($b $d) #($a $b) #($b $c $d) #($a $b $d $e)) | ||
do: [ :c | self assert: (cc circuits anySatisfy: [ :ci | c hasEqualElements: (cc normalize: ci) ]) ] | ||
] | ||
|
||
{ #category : #'tests-sed' } | ||
MalCyclesCoverageTest >> testAseCircuitWithSed [ | ||
cc useEdgeDecomposition. | ||
MalGraphFixture aseCircuitGraph: cc. | ||
cc run. | ||
self assert: 5 equals: cc circuits size. | ||
#(#($g $h) #($b $d) #($a $b) #($b $c $d) #($a $b $d $e)) | ||
do: [ :c | self assert: (cc circuits anySatisfy: [ :ci | c hasEqualElements: ci ]) ] | ||
] | ||
|
||
{ #category : #'tests-snd' } | ||
MalCyclesCoverageTest >> testAseCircuitWithSnd [ | ||
MalGraphFixture aseCircuitGraph: cc. | ||
cc run. | ||
self assert: 5 equals: cc circuits size. | ||
#(($g $h) ($b $d) ($a $b) ($b $c $d) ($a $b $d $e)) do: [:c| | ||
self assert: (cc circuits anySatisfy: [:ci| c hasEqualElements: ci ])]. | ||
|
||
] | ||
|
||
{ #category : #'tests-cse' } | ||
MalCyclesCoverageTest >> testAseSccWithCse [ | ||
| cse | | ||
cse := MalCircuitSpanningEdges new. | ||
MalGraphFixture aseSccGraph: cse. | ||
cse run. | ||
self assert: 4 equals: cse circuits size. | ||
self assert: (#($a $b) hasEqualElements: cse circuits first). | ||
self assert: (#($b $d) hasEqualElements: cse circuits second). | ||
self assert: (#($c $d $b) hasEqualElements: cse circuits third). | ||
self assert: (#($e $a $b $d) hasEqualElements: cse circuits fourth) | ||
] | ||
|
||
{ #category : #'tests-sed' } | ||
MalCyclesCoverageTest >> testAseSccWithSed [ | ||
| sed circuits | | ||
sed := MalSccEdgeDecomposition new. | ||
MalGraphFixture aseSccGraph: sed. | ||
sed run. | ||
self assert: 4 equals: sed circuits size. | ||
circuits := sed circuits asOrderedCollection. | ||
#(#($b $d) #($a $b) #($b $c $d) #($a $b $d $e)) | ||
do: [ :c | self assert: (circuits anySatisfy: [ :ci | c hasEqualElements: ci ]) ] | ||
] | ||
|
||
{ #category : #'tests-snd' } | ||
MalCyclesCoverageTest >> testAseSccWithSnd [ | ||
| sed circuits | | ||
sed := MalSccNodeDecomposition new. | ||
MalGraphFixture aseSccGraph: sed. | ||
sed run. | ||
self assert: 4 equals: sed circuits size. | ||
circuits := sed circuits asOrderedCollection. | ||
#(#($b $d) #($a $b) #($b $c $d) #($a $b $d $e)) | ||
do: [ :c | self assert: (circuits anySatisfy: [ :ci | c hasEqualElements: ci ]) ] | ||
] | ||
|
||
{ #category : #testing } | ||
MalCyclesCoverageTest >> testNormalize [ | ||
self assert: (#($a $b) hasEqualElements: (cc normalize: #($a $b) asOrderedCollection)). | ||
self assert: (#($a $b) hasEqualElements: (cc normalize: #($b $a) asOrderedCollection)). | ||
self assert: (#($b $c $d) hasEqualElements: (cc normalize: #($c $d $b) asOrderedCollection)). | ||
self assert: (#($a $e $b $f $d) hasEqualElements: (cc normalize: #($e $b $f $d $a) asOrderedCollection)) | ||
] |
This file contains 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,44 @@ | ||
Class { | ||
#name : #MalDijkstraTest, | ||
#superclass : #TestCase, | ||
#instVars : [ | ||
'dijsktra' | ||
], | ||
#category : #'Moose-Algos-Graph-Tests' | ||
} | ||
|
||
{ #category : #running } | ||
MalDijkstraTest >> setUp [ | ||
super setUp. | ||
dijsktra := MalDijkstra new | ||
] | ||
|
||
{ #category : #tests } | ||
MalDijkstraTest >> testAseBasicCircuit [ | ||
MalGraphFixture aseCircuitGraph: dijsktra. | ||
|
||
self assert: 1 equals: (dijsktra runFrom: $a to: $b). | ||
dijsktra reset. | ||
self assert: 3 equals: (dijsktra runFrom: $a to: $e). | ||
dijsktra reset. | ||
self assert: 2 equals: (dijsktra runFrom: $c to: $b). | ||
dijsktra reset. | ||
self assert: 5 equals: (dijsktra runFrom: $a to: $h). | ||
dijsktra reset. | ||
self assert: Float infinity equals: (dijsktra runFrom: $h to: $a) | ||
] | ||
|
||
{ #category : #tests } | ||
MalDijkstraTest >> testAseBasicCircuitBacktrack [ | ||
MalGraphFixture aseCircuitGraph: dijsktra. | ||
|
||
self assert: (#($a $b) hasEqualElements: (dijsktra runFrom: $a to: $b; backtrack)). | ||
dijsktra reset. | ||
self assert: (#($a $b $d $e) hasEqualElements: (dijsktra runFrom: $a to: $e; backtrack)). | ||
dijsktra reset. | ||
self assert: (#($c $d $b) hasEqualElements: (dijsktra runFrom: $c to: $b; backtrack)). | ||
dijsktra reset. | ||
self assert: (#($a $b $c $f $g $h) hasEqualElements: (dijsktra runFrom: $a to: $h; backtrack)). | ||
dijsktra reset. | ||
self assert: (#() hasEqualElements: (dijsktra runFrom: $h to: $a; backtrack)) | ||
] |
This file contains 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,58 @@ | ||
Class { | ||
#name : #MalDisjointSetsTest, | ||
#superclass : #TestCase, | ||
#instVars : [ | ||
'ds' | ||
], | ||
#category : #'Moose-Algos-Graph-Tests' | ||
} | ||
|
||
{ #category : #running } | ||
MalDisjointSetsTest >> setUp [ | ||
super setUp. | ||
ds := MalDisjointSets new | ||
] | ||
|
||
{ #category : #tests } | ||
MalDisjointSetsTest >> test1Component [ | ||
| components | | ||
ds nodes: (1 to: 5). | ||
ds edges: {(1 -> 2) . (2 -> 3) . (4 -> 5) . (1 -> 5)} from: #key to: #value. | ||
ds run. | ||
components := ds components. | ||
|
||
self assert: 1 equals: components size. | ||
self assert: ((1 to: 5) hasEqualElements: components first) | ||
] | ||
|
||
{ #category : #tests } | ||
MalDisjointSetsTest >> test2Components [ | ||
| components twoNodes threeNodes | | ||
ds nodes: (1 to: 5). | ||
ds edges: {(1 -> 2) . (2 -> 3) . (4 -> 5)} from: #key to: #value. | ||
ds run. | ||
components := ds components. | ||
|
||
self assert: 2 equals: components size. | ||
twoNodes := components detect: [ :c | c size = 2 ]. | ||
threeNodes := components detect: [ :c | c size = 3 ]. | ||
self assert: ((1 to: 3) hasEqualElements: threeNodes). | ||
self assert: ((4 to: 5) hasEqualElements: twoNodes) | ||
] | ||
|
||
{ #category : #tests } | ||
MalDisjointSetsTest >> test3Components [ | ||
| components twoNodes threeNodes singleNodeC | | ||
ds nodes: (1 to: 6). | ||
ds edges: {(1 -> 2) . (2 -> 3) . (4 -> 5)} from: #key to: #value. | ||
ds run. | ||
components := ds components. | ||
|
||
self assert: 3 equals: components size. | ||
twoNodes := components detect: [ :c | c size = 2 ]. | ||
threeNodes := components detect: [ :c | c size = 3 ]. | ||
singleNodeC := components detect: [ :c | c size = 1 ]. | ||
self assert: ((1 to: 3) hasEqualElements: threeNodes). | ||
self assert: ((4 to: 5) hasEqualElements: twoNodes). | ||
self assert: 6 equals: singleNodeC anyOne | ||
] |
This file contains 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,57 @@ | ||
Class { | ||
#name : #MalDominanceTest, | ||
#superclass : #TestCase, | ||
#instVars : [ | ||
'dom' | ||
], | ||
#category : #'Moose-Algos-Graph-Tests' | ||
} | ||
|
||
{ #category : #running } | ||
MalDominanceTest >> setUp [ | ||
super setUp. | ||
dom := MalDominance new | ||
] | ||
|
||
{ #category : #tests } | ||
MalDominanceTest >> testCycle [ | ||
| a b c | | ||
MalGraphFixture cycleGraph: dom. | ||
dom run. | ||
dom nodes | ||
do: [ :n | | ||
n model = $c | ||
ifTrue: [ | ||
self assert: n isDominant. | ||
self deny: n isDominated ] | ||
ifFalse: [ self deny: n isDominant. | ||
n model = $d | ||
ifTrue: [ self deny: n isDominated ] | ||
ifFalse: [ self assert: n isDominated ] ] ]. | ||
a := dom findNode: $a. | ||
b := dom findNode: $b. | ||
c := dom findNode: $c. | ||
self assert: a find equals: c. | ||
self assert: b find equals: c | ||
] | ||
|
||
{ #category : #tests } | ||
MalDominanceTest >> testSimple [ | ||
| a b c d | | ||
MalGraphFixture simpleGraph: dom. | ||
dom run. | ||
dom nodes | ||
do: [ :n | | ||
n model = $a | ||
ifTrue: [ | ||
self assert: n isDominant. | ||
self deny: n isDominated ] | ||
ifFalse: [ self deny: n isDominant ] ]. | ||
a := dom findNode: $a. | ||
b := dom findNode: $b. | ||
c := dom findNode: $c. | ||
d := dom findNode: $d. | ||
self assert: b find equals: a. | ||
self deny: c isDominated. | ||
self deny: d isDominated | ||
] |
21 changes: 21 additions & 0 deletions
21
src/Moose-Algos-Graph-Tests/MalGraphAlgorithmTest.class.st
This file contains 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,21 @@ | ||
" | ||
A MalGraphAlgorithmTest is a test class for testing the behavior of MalGraphAlgorithm | ||
" | ||
Class { | ||
#name : #MalGraphAlgorithmTest, | ||
#superclass : #TestCase, | ||
#category : #'Moose-Algos-Graph-Tests' | ||
} | ||
|
||
{ #category : #tests } | ||
MalGraphAlgorithmTest >> testAddNodesFromChildrenBlock [ | ||
| builder | | ||
builder := MalGraphReducer new. | ||
builder addNodesFrom: String childrenBlock: [ :parent | parent subclasses ]. | ||
|
||
self assert: builder nodes size equals: 6. | ||
self assertCollection: (builder nodes collect: #model) hasSameElements: (String allSubclasses copyWith: String). | ||
self assertCollection: ((builder findNode: Symbol) nextNodes collect: #model) hasSameElements: {ByteSymbol . WideSymbol}. | ||
self assertCollection: ((builder findNode: Symbol) previousNodes collect: #model) hasSameElements: {String}. | ||
self assert: (builder findNode: ByteSymbol) nextNodes isEmpty | ||
] |
Oops, something went wrong.