Ejemplo n.º 1
0
def test_player_update():
    # NEEDS TA ACTION!!! For this one please comment out
    # self.flip_tiles(x, y, True) from player_update in disks.py
    d = Disks(400, 400, 100, gr)
    d.player_update(50, 150)
    assert d.black_score == 2
    assert d.gr.player_turn is True
    gr1 = GameRef(gc, 100)
    d1 = Disks(400, 400, 100, gr1)
    d1.legal_table = set([(1, 0)])
    d1.player_update(50, 150)
    assert d1.black_score == 3
    assert d1.gr.player_turn is False
    gr2 = GameRef(gc, 100)
    d2 = Disks(400, 400, 100, gr2)
    d2.legal_table = set([(1, 0)])
    d2.table[1][0] = 3
    d2.player_update(50, 150)
    assert d2.black_score == 2
    assert d2.gr.player_turn is True
    gr3 = GameRef(gc, 100)
    d3 = Disks(400, 400, 100, gr3)
    d3.legal_table = set([(1, 2)])
    d3.player_update(250, 150)
    assert d3.black_score == 2
    assert d3.gr.player_turn is True
Ejemplo n.º 2
0
def test_check_legal():
    """Test if the method store correct legal moves into the set."""
    d = Disks(400, 400, 100, gr)
    d.check_legal(True)
    assert d.legal_table == set([(1, 0), (0, 1), (2, 3), (3, 2)])
    d1 = Disks(800, 800, 100, gr)
    d1.check_legal(False)
    assert d1.legal_table == set([(2, 4), (3, 5), (4, 2), (5, 3)])
Ejemplo n.º 3
0
def test_move_right_up():
    """Test if the method correctly return the coordinate on the upper right
    of current position."""
    d = Disks(100, 100, 50, gr)
    position = (0, 1)
    assert d._move_right_up(position) == (-1, 2)
    d1 = Disks(100, 100, 50, gr)
    position = (-1, -3)
    assert d._move_right_up(position) == (-2, -2)
    d2 = Disks(100, 100, 50, gr)
    position = (3, 7)
    assert d2._move_right_up(position) == (2, 8)
Ejemplo n.º 4
0
def test__flip_tiles_one_dir():
    # NEEDS TA ACTION!!! _flip_tiles_one_dir contains display,
    # please comment out everything below if next result:....
    gr5 = GameRef(gc, 100)
    d5 = Disks(400, 400, 100, gr5)
    assert d5._flip_tiles_one_dir((5, 0), d5._move_right, True) is False
    gr6 = GameRef(gc, 100)
    d6 = Disks(400, 400, 100, gr6)
    assert d6._flip_tiles_one_dir((1, 0), d6._move_right, True) is False
    gr7 = GameRef(gc, 100)
    d7 = Disks(400, 400, 100, gr7)
    assert d7._flip_tiles_one_dir((1, 2), d6._move_right, True) is True
Ejemplo n.º 5
0
def test_check_adjacent():
    """Test if the method correctly check the adjacent position
    for legal moves."""
    d = Disks(400, 400, 100, gr)
    d.check_adjacent(1, 1, 0, -1, True)
    assert d.legal_table == set([(1, 0)])
    d1 = Disks(400, 400, 100, gr)
    d1.check_adjacent(1, 3, 0, 1, True)
    assert d1.legal_table == set([(1, 3)])
    d2 = Disks(400, 400, 100, gr)
    d2.check_adjacent(2, 1, 1, 0, False)
    assert d2.legal_table == set([(3, 1)])
Ejemplo n.º 6
0
def test_is_position_valid():
    """Test if the method correctly return the boolean of a given position
    that is within the board size.."""
    d = Disks(100, 100, 50, gr)
    position = (0, 0)
    assert d._is_position_valid(position) is True
    d1 = Disks(100, 100, 50, gr)
    position = (-1, -3)
    assert d1._is_position_valid(position) is False
    d2 = Disks(100, 100, 50, gr)
    position = (3, 7)
    assert d2._is_position_valid(position) is False
Ejemplo n.º 7
0
def test_move_right_down():
    """Test if the method correctly return the coordinate on the right down
    of current position."""
    d = Disks(100, 100, 50, gr)
    position = (0, 1)
    assert d._move_right_down(position) == (1, 2)
    d1 = Disks(100, 100, 50, gr)
    position = (-1, -3)
    assert d._move_right_down(position) == (0, -2)
    d2 = Disks(100, 100, 50, gr)
    position = (3, 7)
    assert d2._move_right_down(position) == (4, 8)
Ejemplo n.º 8
0
def test_move_right():
    """Test if the method correctly return the coordinate on the right
    of current position."""
    d = Disks(100, 100, 50, gr)
    position = (0, 0)
    assert d._move_right(position) == (0, 1)
    d1 = Disks(100, 100, 50, gr)
    position = (-1, -2)
    assert d._move_right(position) == (-1, -1)
    d2 = Disks(100, 100, 50, gr)
    position = (3, 7)
    assert d2._move_right(position) == (3, 8)
Ejemplo n.º 9
0
def test_create():
    ds = Disks(800, 800, 100, 20, 0, 1)
    ds.create(50, 50, 1)
    assert ds.matrix[0][0].color == 1
    assert ds.black_count == 0
    assert ds.white_count == 1
    assert ds.total_disks == 1
Ejemplo n.º 10
0
def test_computer_update():
    # NEEDS TA ACTION!!! For this one please comment out
    # elf.flip_tiles(x, y, True) from computer_update in disks.py
    gr4 = GameRef(gc, 100)
    d4 = Disks(400, 400, 100, gr4)
    d4.computer_update(50, 150)
    assert d4.white_score == 3
    assert d4.gr.player_turn is True
Ejemplo n.º 11
0
def test_is_full():
    ds = Disks(800, 800, 100, 20, 0, 1)
    for j in range(8):
        ds.create(50 + j * 100, 50, 0)
    assert ds.is_full() is False
    for i in range(1, 8):
        for j in range(8):
            ds.create(50 + j * 100, 50 + i * 100, 0)
    assert ds.is_full() is True
Ejemplo n.º 12
0
def test_constructor():
    """Test constructor"""
    score_file_name = "score.txt"
    s = ScoreSheet(score_file_name)
    gc = GameController(600, 400, 50, s)
    gr = GameRef(gc, 100)
    d = Disks(600, 400, 50, gr)
    b = Board(600, 400, 50, d)
    assert b.WIDTH == 600
    assert b.HEIGHT == 400
    assert b.CELL == 50
    assert b.disk is d
Ejemplo n.º 13
0
 def __init__(self, WIDTH, HEIGHT, CELL_WIDTH, EDGE, game_controller,
              HUMAN_COLOR, AI_COLOR):
     '''draw the chess board and handles interaction
     between game controller, player, and disks'''
     self.WIDTH = WIDTH
     self.HEIGHT = HEIGHT
     self.CELL_WIDTH = CELL_WIDTH
     self.EDGE = EDGE
     self.gc = game_controller
     self.disks = Disks(WIDTH, HEIGHT, CELL_WIDTH, EDGE, HUMAN_COLOR,
                        AI_COLOR)
     self.human_color = HUMAN_COLOR
     self.ai_color = AI_COLOR
     # create the beginning 4 disks in the middle
     self.initial_four(WIDTH, HEIGHT, CELL_WIDTH, HUMAN_COLOR, AI_COLOR)
Ejemplo n.º 14
0
def test_constructor():
    ds = Disks(800, 800, 100, 20, 0, 1)
    assert ds.WIDTH == 800
    assert ds.HEIGHT == 800
    assert ds.CELL_WIDTH == 100
    assert ds.EDGE == 20
    assert ds.num_of_rows == int(ds.HEIGHT / ds.CELL_WIDTH)
    assert ds.num_of_cols == int(ds.WIDTH / ds.CELL_WIDTH)
    assert ds.matrix == [[None] * ds.num_of_cols
                         for i in range(ds.num_of_rows)]
    assert ds.black_count == 0
    assert ds.white_count == 0
    assert ds.total_disks == 0
    assert ds.human_color == 0
    assert ds.ai_color == 1
Ejemplo n.º 15
0
 def add_server(self, details={}):
     '''
     Add a server to the Environment
     '''
     server = {}
     server.update({'memory': Memory(details)})
     server.update({'disks': Disks(details)})
     server.update({'cpus': CPUS(details)})
     server.update({
         'processes':
         Processes(cpus=server.get('cpus'),
                   memory=server.get('memory'),
                   disks=server.get('disks'),
                   conf=details)
     })
     return server
Ejemplo n.º 16
0
 def __init__(self, WIDTH, HEIGHT, CELL_WIDTH, EDGE, game_controller):
     '''draw the chess board and handles interaction
     between game controller, player, and disks'''
     self.WIDTH = WIDTH
     self.HEIGHT = HEIGHT
     self.CELL_WIDTH = CELL_WIDTH
     self.EDGE = EDGE
     self.gc = game_controller
     self.disks = Disks(WIDTH, HEIGHT, CELL_WIDTH, EDGE)
     # create the beginning 4 disks in the middle
     self.disks.create(WIDTH / 2 + CELL_WIDTH / 2,
                       HEIGHT / 2 - CELL_WIDTH / 2)
     self.disks.create(WIDTH / 2 - CELL_WIDTH / 2,
                       HEIGHT / 2 - CELL_WIDTH / 2)
     self.disks.create(WIDTH / 2 - CELL_WIDTH / 2,
                       HEIGHT / 2 + CELL_WIDTH / 2)
     self.disks.create(WIDTH / 2 + CELL_WIDTH / 2,
                       HEIGHT / 2 + CELL_WIDTH / 2)
Ejemplo n.º 17
0
def test_constructor():
    """Test constructor"""
    d = Disks(100, 100, 50, gr)
    assert d.WIDTH == 100
    assert d.HEIGHT == 100
    assert d.cell == 50
    num_start_disks = 4
    assert d.black_score == 2
    assert d.white_score == 2
    assert d.total_count == 4
    assert d.gr is gr
    assert d.total_col == 2
    assert d.total_row == 2
    assert d.table == [[d.disk3, d.disk1], [d.disk2, d.disk4]]
    half_cell = d.cell / 2
    assert half_cell == 25
    assert repr(d.disk1) == "Black"
    assert repr(d.disk2) == "Black"
    assert repr(d.disk3) == "White"
    assert repr(d.disk4) == "White"
    assert d.disk3.draw_black is False
    assert d.disk4.draw_black is False
    assert d.legal_table == set()
Ejemplo n.º 18
0
	parser_back.add_argument('--drive', '-d', dest='drive', type=str, help="Disk drive where the backups should be put to.")

	parser_del  = subparsers.add_parser('delete', help='Delete a Backup')
	parser_del.add_argument('--date', '-t', dest='date', type=int, required=True, help="Unix time of the backup to delete")
	parser_del.add_argument('--drive', '-d', dest='drive', type=str, help="Disk drive where the backups should be put to.")

	options = parser.parse_args()
	#print
	#print "Options:",options
	#print

	op = Operations()

	if options.subcommand == 'ld':
		from disks import Disks
		disks = Disks()
		for i, dinfo in enumerate(disks.list_devices()):
			print "%2d. Device: %s   Label: %s"%(i+1, dinfo.dev_file(), dinfo.label())

	if options.subcommand == 'prepare':
		latest_dir = os.path.join(options.backup_dir, 'latest')
		if 1:
			logger.info("* Unmounting Volume")
			ret = op.unmount_backup(options.drive)
			logger.info(ret)
		if 1:
			logger.info("* Creating Volume")
			ret = op.create_btrfs(options.drive, 'backup_volume')
			logger.info(ret)
		if not os.path.exists(options.backup_dir):
			logger.info("* mkdir mountpoint")
Ejemplo n.º 19
0
from encryptor import Encryptor
from disks import Disks
from constants import SHIFT

if __name__ == '__main__':

    text = 'Some encrypted tex'
    discs = Disks().discs

    out = Encryptor().jefferson_encryption(text, discs, SHIFT, reverse=False)
    print(out)

Ejemplo n.º 20
0
from game_controller import GameController
from game_ref import GameRef
from score_sheet import ScoreSheet
import time
import random
from disks import Disks

score_file_name = "score.txt"
s = ScoreSheet(score_file_name)
gc = GameController(400, 400, 100, s)
gr = GameRef(gc, 100)
d = Disks(400, 400, 100, gr)


def test_constructor():
    gr1 = GameRef(gc, 100)
    assert gr1.player_turn is True
    assert gr1.gc is gc
    assert gr1.cell == 100


# Both player_move and computer_move includes methods that display drawing
# on screen, so I was not able to test for those two functions.