def setup(self): self.handSize = 8 self.hand1 = {'a': 3, 'b': 2, 'd': 3} self.h1 = Hand(self.handSize, self.hand1) self.hand2 = {'h': 2, 'e': 3, 'l': 4, 'o': 2} self.h2 = Hand(self.handSize, self.hand2)
def testPlayer(): """ Test the Player class. Add your own test cases. """ p = Player(1, Hand(6, {'c': 1, 'a': 1, 'b': 1, 'd': 1, 'o': 1, 'e': 1})) testResult(type(p.getHand()) == Hand) p.addPoints(5.) p.addPoints(12.) testResult(isClose(p.getPoints(), 17))
def setup(self): self.wordlist = Wordlist().getList() self.p = ComputerPlayer( 1, Hand(6, { 'c': 1, 'a': 1, 'b': 1, 'd': 1, 'o': 1, 'e': 1 }))
def testComputerPlayer(): """ Test the ComputerPlayer class. Add your own test cases. """ wordlist = Wordlist() p = ComputerPlayer( 1, Hand(6, { 'c': 1, 'a': 1, 'b': 1, 'd': 1, 'o': 1, 'e': 1 })) testResult(getWordScore(p.pickBestWord(wordlist)) == getWordScore('abode'))
def setup(self): self.h1 = Hand(10, { 'o': 1, 'm': 1, 't': 1, 'e': 1, 'r': 1, 'n': 1, 's': 1 }) self.h2 = Hand(7, {'c': 1, 'e': 2, 'p': 1, 'r': 1, 'y': 1}) self.h3 = Hand(0, {'p': 0, 'i': 0, 'n': 0, 'a': 0})
def setup(self): self.hand1 = Hand(6, {'c': 1, 'a': 1, 'd': 1, 'o': 1, 'e': 1}) self.hand2 = Hand(8, {'a': 2, 'b': 1, 'd': 2}) self.p1 = Player(1, self.hand1) self.p2 = Player(2, self.hand2)
class TestHand: def setup(self): self.handSize = 8 self.hand1 = {'a': 3, 'b': 2, 'd': 3} self.h1 = Hand(self.handSize, self.hand1) self.hand2 = {'h': 2, 'e': 3, 'l': 4, 'o': 2} self.h2 = Hand(self.handSize, self.hand2) def test_update(self): self.h1.update('bad') self.h2.update('hello') assert self.hand1 == {'a': 2, 'b': 1, 'd': 2} assert self.hand2 == {'h': 1, 'e': 2, 'l': 2, 'o': 1} def test_containsLetters(self): self.h1.update('bad') self.h2.update('hello') assert self.h1.containsLetters('abd') is True assert self.h2.containsLetters('hello') is True assert self.h1.containsLetters('aaabbddd') is False assert self.h2.containsLetters('hheelloo') is False def test_isEmpty(self): assert self.h1.isEmpty() is False assert self.h2.isEmpty() is False self.h1.update('bad') self.h1.update('dad') self.h1.update('ab') assert self.h1.isEmpty() is True def test_eq(self): assert (self.h1 == self.h2) is False assert (self.h2 == self.h1) is False def test_str(self): assert str(self.h1) == "a a a b b d d d" assert str(self.h2) == "h h e e e l l l l o o" self.h1.update('bad') self.h2.update('hello') assert str(self.h1) == "a a b d d" assert str(self.h2) == "h e e l l o"
class TestHand(): def setup(self): self.h1 = Hand(10, { 'o': 1, 'm': 1, 't': 1, 'e': 1, 'r': 1, 'n': 1, 's': 1 }) self.h2 = Hand(7, {'c': 1, 'e': 2, 'p': 1, 'r': 1, 'y': 1}) self.h3 = Hand(0, {'p': 0, 'i': 0, 'n': 0, 'a': 0}) # def test_update(self): # assert self.h1.update('no') == 'mters' # assert self.h2.update('pee') == 'cry' def test_containsLetters(self): assert self.h1.containsLetters('mestr') is True assert self.h2.containsLetters('creep') is True assert self.h2.containsLetters('crap') is False assert self.h2.containsLetters('crow') is False def test_isEmpty(self): assert self.h1.isEmpty() is False assert self.h2.isEmpty() is False assert self.h3.isEmpty() is True def test_eq(self): assert self.h1.__eq__({ 'e': 1, 'm': 1, 'n': 1, 'o': 1, 'r': 1, 's': 1, 't': 1 }) is True assert self.h2.__eq__({'c': 1, 'e': 2, 'p': 1, 'r': 1}) is False assert self.h2.__eq__({ 'c': 1, 'e': 2, 'p': 1, 'r': 1, 'y': 2 }) is False def test_str(self): assert self.h1.__str__() == 'omterns' assert self.h2.__str__() == 'ceepry'
def testHand(): """ Test the hand class. Add your own test cases """ h = Hand(8, {'a': 3, 'b': 2, 'd': 3}) h.update('bad') testResult(h.containsLetters('aabdd') and not h.isEmpty()) h.update('dad') testResult(h.containsLetters('ab') or not h.isEmpty()) h.update('ab') testResult(h.isEmpty())