-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRobozzle.py
More file actions
82 lines (63 loc) · 2.47 KB
/
Robozzle.py
File metadata and controls
82 lines (63 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import unittest
class Game():
def __init__( self, starsPositions):
self.starsPositions = starsPositions
def newPosition( self, currentPosition, move ):
pos = currentPosition
if move == 'f':
pos = ( pos[0] + 1, pos[1])
return pos
def move( self, moves ):
numberOfStars = 0
interestingStarPosition = (0,0)
for i in range( len(moves) ): # 0, 1
interestingStarPosition = self.newPosition( interestingStarPosition, moves[i] )
if moves[i] == 'f':
if interestingStarPosition in self.starsPositions:
numberOfStars += 1
return numberOfStars
class RobozzleTest(unittest.TestCase):
def test_true(self):
self.assertEquals(True, True)
def test_0_move_0_star(self):
starsPositions=[]
game = Game(starsPositions)
numberOfStarGot = game.move("")
self.assertEquals(len(starsPositions),numberOfStarGot)
def test_1_move_1_star(self):
starsPositions = [ (1,0) ]
game = Game( starsPositions)
numberOfStarGot = game.move("f")
self.assertEquals( len(starsPositions), numberOfStarGot)
def test_0_move_1_star( self ):
starsPositions = [ (1,0) ]
game = Game( starsPositions)
numberOfStarGot = game.move("")
self.assertEquals( 0, numberOfStarGot)
def test_1_move_1_star_0_starsgot( self ):
starsPositions = [ (-1,0)]
game = Game (starsPositions)
numberOfStarGot = game.move("f")
self.assertEquals(0, numberOfStarGot)
def test_2_move_1_star_1_starsgot( self ):
starsPositions = [ (1,0)]
game = Game (starsPositions)
numberOfStarGot = game.move("fr")
self.assertEquals(1, numberOfStarGot)
def test_2_move_1_star_0_starsgot( self ):
starsPositions = [ (-1,0)]
game = Game (starsPositions)
numberOfStarGot = game.move("fr")
self.assertEquals(0, numberOfStarGot)
def test_2_move_2_star_2_starsgot( self ):
starsPositions = [ (1,0), (2,0) ]
game = Game( starsPositions )
numberOfStarGot = game.move( "ff" )
self.assertEquals(2, numberOfStarGot)
def test_2_move_2_star_reversed_2_starsgot( self ):
starsPositions = [ (2,0), (1,0) ]
game = Game( starsPositions )
numberOfStarGot = game.move( "ff" )
self.assertEquals(2, numberOfStarGot)
if __name__ == "__main__":
unittest.main()