def test_isGameOver(self):
     userPiecesRepository = Repository()
     userPiecesRepository.add(Piece(0, 0))
     userPiecesRepository.add(Piece(1, 1))
     userPiecesRepository.add(Piece(2, 2))
     userPiecesRepository.add(Piece(3, 3))
     userPiecesRepository.add(Piece(4, 4))
     aiPiecesRepository = Repository()
     validator = Validator(userPiecesRepository, aiPiecesRepository)
     userPiecesService = UserService(userPiecesRepository, validator)
     aiPiecesService = AIService(aiPiecesRepository, userPiecesRepository,
                                 validator)
     gameService = GameService(userPiecesService, aiPiecesService)
     self.assertEqual(gameService.isGameOver(), True)
     userPiecesRepository = Repository()
     userPiecesRepository.add(Piece(0, 0))
     userPiecesRepository.add(Piece(1, 1))
     userPiecesRepository.add(Piece(3, 3))
     userPiecesRepository.add(Piece(4, 4))
     aiPiecesRepository = Repository()
     validator = Validator(userPiecesRepository, aiPiecesRepository)
     userPiecesService = UserService(userPiecesRepository, validator)
     aiPiecesService = AIService(aiPiecesRepository, userPiecesRepository,
                                 validator)
     gameService = GameService(userPiecesService, aiPiecesService)
     self.assertEqual(gameService.isGameOver(), False)
Exemplo n.º 2
0
 def execute_script(self):
     script_path = self.script_name.replace('.py', '')
     self.stop_button.setEnabled(True)
     self.run_button.setEnabled(False)
     self.validator = Validator(self.script_timeout.value(), script_path,
                                self.progress_terminal)
     self.validator.validate()
     self.stop_script()
Exemplo n.º 3
0
 def __init__(self) -> None:
     super().__init__()
     userPiecesRepository = Repository()
     aiPiecesRepository = Repository()
     validator = Validator(userPiecesRepository, aiPiecesRepository)
     userPiecesService = UserService(userPiecesRepository, validator)
     aiPiecesService = AIService(aiPiecesRepository, userPiecesRepository,
                                 validator)
     gameService = GameService(userPiecesService, aiPiecesService)
     self.console = Console(userPiecesService, aiPiecesService, gameService)
Exemplo n.º 4
0
 def __init__(self, clientController, movieController, rentalController, undoStack, commandsStack, redoStack, undoRunner) -> None:
     self.printer = Printer()
     self.validator = Validator()
     self.constants = Constants()
     self.clientController = clientController
     self.movieController = movieController
     self.rentalController = rentalController
     self.undoStack = undoStack
     self.commandsStack = commandsStack
     self.redoStack = redoStack
     self.undoRunner = undoRunner
 def test_addBestPlayPiece(self):
     userPiecesRepository = Repository()
     aiPiecesRepository = Repository()
     aiPiecesRepository.add(Piece(0, 0))
     aiPiecesRepository.add(Piece(1, 1))
     validator = Validator(userPiecesRepository, aiPiecesRepository)
     aiPiecesService = AIService(aiPiecesRepository, userPiecesRepository,
                                 validator)
     aiPiecesService.addPiece()
     self.assertEqual(
         aiPiecesService.getList(),
         [Piece(0, 0), Piece(1, 1), Piece(2, 2)])
 def test_addPieceToBlock(self):
     userPiecesRepository = Repository()
     userPiecesRepository.add(Piece(0, 0))
     userPiecesRepository.add(Piece(1, 1))
     userPiecesRepository.add(Piece(2, 2))
     userPiecesRepository.add(Piece(3, 3))
     aiPiecesRepository = Repository()
     validator = Validator(userPiecesRepository, aiPiecesRepository)
     aiPiecesService = AIService(aiPiecesRepository, userPiecesRepository,
                                 validator)
     aiPiecesService.addPiece()
     self.assertEqual(aiPiecesService.getList(), [Piece(4, 4)])
Exemplo n.º 7
0
 def setUpClass(self):
     resources = c.resource_dir
     self.logger = logging.getLogger('test_validator')
     hdlr = logging.FileHandler(
         os.path.join(c.log_dir, 'test_validator.log'))
     formatter = logging.Formatter(
         '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
     hdlr.setFormatter(formatter)
     self.logger.addHandler(hdlr)
     self.logger.setLevel(logging.INFO)
     self.wdl = os.path.join(resources, 'test.wdl')
     self.json = os.path.join(resources, 'test.json')
     self.validator = Validator(wdl=self.wdl, json=self.json)
     self.logger.info('Starting Validator tests...')
     self.wdl_args = self.validator.get_wdl_args()
     self.json_args = self.validator.get_json()
 def test_isValid(self):
     repository1 = Repository()
     repository1.add(Piece(0, 0))
     repository1.add(Piece(1, 1))
     repository2 = Repository()
     repository2.add(Piece(13, 13))
     repository2.add(Piece(14, 14))
     validator = Validator(repository1, repository2)
     self.assertTrue(validator.isValid(Piece(3, 3)))
     self.assertTrue(validator.isValid(Piece(3, 8)))
     self.assertFalse(validator.isValid(Piece(-1, 5)))
     self.assertFalse(validator.isValid(Piece(-1, -9)))
     self.assertFalse(validator.isValid(Piece(21, 5)))
     self.assertFalse(validator.isValid(Piece(1, 55)))
     self.assertFalse(validator.isValid(Piece(0, 0)))
     self.assertFalse(validator.isValid(Piece(14, 14)))
def validate(allOpt: bool, install: bool, dialog: bool, talk: bool,
             verbose: int):
    """
	This is the Command Line Interface of the JsonValidator for all Modules
	of Project Alice. Currently the following commands are supported.
	"""
    if allOpt:
        install = dialog = talk = True
    if True in {install, dialog, talk}:
        valid = Validator(installer=install,
                          dialog=dialog,
                          talk=talk,
                          verbosity=verbose)
        error = valid.validate()
        valid.printResult()
        sys.exit(error)
    else:
        click.echo(click.get_current_context().get_help())
Exemplo n.º 10
0
def call_validate(args):
    """
    Calls the Validator to validate input json. Exits with feedback to user regarding errors in json or reports no
    errors found.
    :param args: validation subparser arguments.
    :return:
    """
    logger.info("Validation requested.")
    validator = Validator(wdl=args.wdl, json=args.json)
    result = validator.validate_json()
    if len(result) != 0:
        e = "{} input file contains the following errors:\n{}".format(args.json, "\n".join(result))
        # This will also print to stdout so no need for a print statement
        logger.critical(e)
        sys.exit(1)
    else:
        s = 'No errors found in {}'.format(args.wdl)
        print(s)
        logger.info(s)
 def test_addPiece(self):
     repository1 = Repository()
     repository1.add(Piece(0, 0))
     repository1.add(Piece(1, 1))
     repository2 = Repository()
     repository2.add(Piece(13, 13))
     repository2.add(Piece(14, 14))
     validator = Validator(repository1, repository2)
     userService = UserService(repository1, validator)
     userService.addPiece(5, 5)
     self.assertEqual(
         userService.getList(),
         [Piece(0, 0), Piece(1, 1), Piece(5, 5)])
     with self.assertRaises(ValidException):
         userService.addPiece(0, 0)
     with self.assertRaises(ValidException):
         userService.addPiece(13, 13)
     with self.assertRaises(ValidException):
         userService.addPiece(-1, 0)
     with self.assertRaises(ValidException):
         userService.addPiece(0, 199)