MCDependencySorterTest.st
changeset 302 46cd82921877
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MCDependencySorterTest.st	Sat Aug 20 14:20:16 2011 +0200
@@ -0,0 +1,121 @@
+"{ Package: 'stx:goodies/monticello' }"
+
+TestCase subclass:#MCDependencySorterTest
+	instanceVariableNames:''
+	classVariableNames:''
+	poolDictionaries:''
+	category:'Monticello-Tests'
+!
+
+
+!MCDependencySorterTest methodsFor:'asserting'!
+
+assertItems: anArray orderAs: depOrder withRequired: missingDeps toLoad: unloadableItems
+	self assertItems: anArray orderAs: depOrder withRequired: missingDeps  toLoad: unloadableItems  extraProvisions: #()
+!
+
+assertItems: anArray orderAs: depOrder withRequired: missingDeps toLoad: unloadableItems extraProvisions: provisions
+	| order sorter items missing unloadable |
+	items := anArray collect: [:ea | self itemWithSpec: ea].
+	sorter := MCDependencySorter items: items.
+	sorter addExternalProvisions: provisions.
+	order := (sorter orderedItems collect: [:ea | ea name]) asArray.
+	self assert: order = depOrder.
+	missing := sorter externalRequirements.
+	self assert: missing asSet = missingDeps asSet.
+	unloadable := (sorter itemsWithMissingRequirements collect: [:ea | ea name]) asArray.
+	self assert: unloadable asSet = unloadableItems asSet
+! !
+
+!MCDependencySorterTest methodsFor:'building'!
+
+itemWithSpec: anArray
+	^ MCMockDependentItem new
+		name: anArray first;
+		provides: anArray second;
+		requires: anArray third
+! !
+
+!MCDependencySorterTest methodsFor:'tests'!
+
+testCascadingUnresolved
+	self assertItems: #(
+		(a (x) (z))
+		(b () (x))
+		(c () ()))
+	orderAs: #(c)
+	withRequired: #(z)
+	toLoad: #(a b)	
+!
+
+testCycle
+	self assertItems: #(
+		(a (x) (y))
+		(b (y) (x)))
+	orderAs: #()
+	withRequired: #()
+	toLoad: #(a b)	
+!
+
+testExtraProvisions
+	self assertItems:
+		#((a (x) (z))
+		(b () (x)))
+	orderAs: #(a b)
+	withRequired: #()
+	toLoad: #()	
+	extraProvisions: #(x z)
+!
+
+testMultiRequirementOrdering
+	self assertItems: #(
+		(a (x) (z))
+		(b (y) ())
+		(c (z) ())
+		(d () (x y z)))
+		orderAs: #(b c a d)
+		withRequired: #()
+		toLoad: #()
+!
+
+testSimpleOrdering
+	self assertItems: #((a (x) ())
+								 (c () (y))
+								 (b (y) (x)))
+		orderAs: #(a b c)
+		withRequired: #()
+		toLoad: #()
+!
+
+testSimpleUnresolved
+	self assertItems: #(
+		(a () (z)))
+	orderAs: #()
+	withRequired: #(z)
+	toLoad: #(a)
+		
+!
+
+testUnusedAlternateProvider
+	self assertItems: #(
+		(a (x) (z))
+		(b () (x))
+		(c (x) ()))
+	orderAs: #(c b)
+	withRequired: #(z)
+	toLoad: #(a)	
+! !
+
+!MCDependencySorterTest class methodsFor:'documentation'!
+
+version
+    ^ '$Header: /cvs/stx/stx/goodies/monticello/MCDependencySorterTest.st,v 1.1 2011-08-20 12:20:16 cg Exp $'
+!
+
+version_CVS
+    ^ '$Header: /cvs/stx/stx/goodies/monticello/MCDependencySorterTest.st,v 1.1 2011-08-20 12:20:16 cg Exp $'
+!
+
+version_SVN
+    ^ '§Id: MCDependencySorterTest.st 5 2010-08-29 07:30:29Z vranyj1 §'
+! !