Update of /cvsroot/wtfibs/WTFibs/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26387/test
Modified Files:
test_Backgammon.py
Log Message:
Added more tests
Index: test_Backgammon.py
===================================================================
RCS file: /cvsroot/wtfibs/WTFibs/test/test_Backgammon.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- test_Backgammon.py 10 Aug 2005 21:05:27 -0000 1.2
+++ test_Backgammon.py 11 Aug 2005 00:08:16 -0000 1.3
@@ -31,8 +31,9 @@
## this way is easiest, i think
## just add the path to your working src directory to sys.path
-#sys.path.append("C:/Development/WTFibs/trunk/src")
+
sys.path.append("src")
+
import py.test
import Backgammon
@@ -67,7 +68,6 @@
assert type(p.pop()) == type(None)
def test_Die():
-
d = Backgammon.Die()
assert d.sides == 6
assert d.sides != 0
@@ -77,3 +77,60 @@
d.roll()
assert d.face >= 1 and d.face <= 6
cnt -= 1
+
+def test_ExtraBoardPoint():
+ bp = Backgammon.ExtraBoardPoint("Bar","White")
+ assert hasattr(bp, 'color')
+ assert hasattr(bp, 'name')
+ assert hasattr(bp, 'checkers')
+ assert len(bp.checkers) == 0
+ bp.push(Backgammon.Checker("White"))
+ assert len(bp.checkers) == 1
+ bp.pop()
+ assert len(bp.checkers) == 0
+ assert type(bp.pop()) == type(None)
+
+def test_Board():
+ b = Backgammon.Board()
+ assert hasattr(b, 'points')
+ assert hasattr(b, 'buildPoints')
+ assert hasattr(b, 'setInitialPosition')
+ assert hasattr(b, 'whiteBar')
+ assert hasattr(b, 'blackBar')
+ assert hasattr(b, 'whiteBearOff')
+ assert hasattr(b, 'blackBearOff')
+
+ assert len(b.points) == 24
+
+ pts = {1 : 2,
+ 6 : 5,
+ 8 : 3,
+ 12 : 5,
+ 13 : 5,
+ 17 : 3,
+ 19 : 5,
+ 24 : 2 }
+
+ for k in pts.keys():
+ assert len(b.points[k-1].checkers) == pts[k]
+ ##
+ # Move some checkers around, make sure the counts are correct
+ ##
+
+ b.move(1,3)
+ assert len(b.points[3-1].checkers) == 1 # funky indexing - this is right
+ b.move(3,1)
+ assert len(b.points[3-1].checkers) == 0
+
+ b.moveToBar("White",1)
+ assert type(b.whiteBar.checkers[0]) == type(Backgammon.Checker("White"))
+ assert len(b.whiteBar.checkers) == 1
+ b.moveFromBar("White",1)
+ assert len(b.whiteBar.checkers) == 0
+ assert type(b.whiteBar.pop()) == type(None)
+
+ b.bearOff("White",1)
+ assert len(b.whiteBearOff.checkers) == 1
+
+ py.test.raises(Exception, 'b.move(0,100)')
+ py.test.raises(Exception, 'b.move(-1,10)')
|