#QUALITY by cg
authorClaus Gittinger <cg@exept.de>
Wed, 07 Sep 2016 15:25:27 +0200
changeset 1534 65f4fdae8ad0
parent 1529 32bd39e0e14e
child 1536 0a11606bb095
#QUALITY by cg class: RegressionTests::QueueTest added: #coveredClassNames #testChangeCapacity
RegressionTests__QueueTest.st
--- a/RegressionTests__QueueTest.st	Fri Sep 02 19:17:22 2016 +0200
+++ b/RegressionTests__QueueTest.st	Wed Sep 07 15:25:27 2016 +0200
@@ -10,6 +10,12 @@
 !
 
 
+!QueueTest class methodsFor:'queries'!
+
+coveredClassNames
+    ^ #( Queue )
+! !
+
 !QueueTest methodsFor:'Testing'!
 
 testBasic1
@@ -147,6 +153,52 @@
     "
 !
 
+testChangeCapacity
+    "tests all kinds of boundary conditions in the capacity-change code
+     (i.e. especially wraps)"
+     
+     |q|
+
+     #(false true) do:[:wrap |
+        1 to:10 do:[:fill |
+            1 to:fill do:[:read |
+                 Transcript show:'wrap: '; show:wrap; show:' fill: '; show:fill; show:' read: '; showCR:read.
+                
+                 q := Queue new:10.
+                 self assert:(q capacity == 10).
+                 wrap ifTrue:[
+                     1 to:5 do:[:i | q nextPut:#foo ].
+                 ].
+
+                 1 to:fill do:[:i | q nextPut:i.
+                                    (i==1 and:[wrap]) ifTrue:[ 1 to:5 do:[:i | q next ] ].
+                              ].
+                "/ (wrap and:[fill==9 and:[read == 8]]) ifTrue:[self halt].
+                 read timesRepeat:[ q next ].
+                 q capacity:12.
+                 self assert:(q capacity == 12).
+                 self assert:(q size == (fill-read)).
+                 self assert:((Array streamContents:[:s | q do:[:e |s nextPut:e]]) = (read+1 to:fill) asArray).
+                 self assert:(q size == (fill-read)).
+                 fill==read ifTrue:[
+                     self assert:(q isEmpty).
+                     self assert:(q notEmpty not).
+                     self assert:(q size == 0).
+                     self assert:(q nextOrNil == nil).
+                     self assert:(q peekOrNil == nil).
+                     self should:[q at:1] raise:SubscriptOutOfBoundsError.
+                 ] ifFalse:[
+                     self assert:(q notEmpty).
+                     self assert:(q isEmpty not).
+                     self assert:(q at:1) == (read+1).
+                     self assert:(q peek) == (read+1).
+                     self assert:(q peekOrNil) == (read+1).
+                 ].        
+            ].    
+        ].    
+     ]. 
+!
+
 testRemoveAll
     0 to:10 do:[:i|
 	self removeAllSize:10 fill:i.