kyu_3.battleship_field_validator package
Submodules
kyu_3.battleship_field_validator.test_battleship_validator module
Testing Battleship field validator.
Created by Egor Kostan. GitHub: https://github.com/ikostan
- class kyu_3.battleship_field_validator.test_battleship_validator.BattleshipFieldValidatorTestCase(methodName='runTest')[source]
Bases:
TestCaseTesting Battleship field validator.
- _classSetupFailed = False
- _class_cleanups = []
- test_validate_battlefield = None
- test_validate_battlefield_0(**kw)
Testing Battleship field validator [with field=[[0, 0, 0, 0, 1, 0, 0, 1, 0, 0],… [0, 0, 0, 0, 0, 0, 0, 0, 1, 1]], expected=True, message=’Must return TRUE for valid field’].
Testing a method that takes a field for well-known board game “Battleship” as an argument and returns true if it has a valid disposition of ships, false otherwise. Argument is guaranteed to be 10*10 two-dimension array. Elements in the array are numbers, 0 if the cell is free and 1 if occupied by ship.
- test_validate_battlefield_1(**kw)
Testing Battleship field validator [with field=[[1, 0, 0, 0, 0, 0, 0, 0, 0, 0],… [0, 0, 0, 0, 1, 0, 1, 0, 0, 0]], expected=True, message=’Must return TRUE for valid field’].
Testing a method that takes a field for well-known board game “Battleship” as an argument and returns true if it has a valid disposition of ships, false otherwise. Argument is guaranteed to be 10*10 two-dimension array. Elements in the array are numbers, 0 if the cell is free and 1 if occupied by ship.
- test_validate_battlefield_2(**kw)
Testing Battleship field validator [with field=[[1, 0, 0, 0, 0, 1, 1, 0, 0, 0],… [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], expected=True, message=’Must return TRUE for valid field’].
Testing a method that takes a field for well-known board game “Battleship” as an argument and returns true if it has a valid disposition of ships, false otherwise. Argument is guaranteed to be 10*10 two-dimension array. Elements in the array are numbers, 0 if the cell is free and 1 if occupied by ship.
- test_validate_battlefield_3(**kw)
Testing Battleship field validator [with field=[[1, 0, 0, 0, 0, 1, 1, 0, 0, 0],… [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], expected=False, message=’Must return FALSE if unwanted ships are present’].
Testing a method that takes a field for well-known board game “Battleship” as an argument and returns true if it has a valid disposition of ships, false otherwise. Argument is guaranteed to be 10*10 two-dimension array. Elements in the array are numbers, 0 if the cell is free and 1 if occupied by ship.
- test_validate_battlefield_4(**kw)
Testing Battleship field validator [with field=[[1, 0, 0, 0, 0, 1, 1, 0, 0, 0],… [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], expected=False, message=’Must return FALSE if number of ships of some type is incorrect’].
Testing a method that takes a field for well-known board game “Battleship” as an argument and returns true if it has a valid disposition of ships, false otherwise. Argument is guaranteed to be 10*10 two-dimension array. Elements in the array are numbers, 0 if the cell is free and 1 if occupied by ship.
- test_validate_battlefield_5(**kw)
Testing Battleship field validator [with field=[[0, 0, 0, 0, 0, 1, 1, 0, 0, 0],… [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], expected=False, message=’Must return FALSE if some of ships is missing’].
Testing a method that takes a field for well-known board game “Battleship” as an argument and returns true if it has a valid disposition of ships, false otherwise. Argument is guaranteed to be 10*10 two-dimension array. Elements in the array are numbers, 0 if the cell is free and 1 if occupied by ship.
- test_validate_battlefield_6(**kw)
Testing Battleship field validator [with field=[[1, 0, 0, 0, 0, 1, 1, 0, 0, 0],… [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], expected=False, message=’Must return FALSE if some of sh… incorrect shape (non-straight)’].
Testing a method that takes a field for well-known board game “Battleship” as an argument and returns true if it has a valid disposition of ships, false otherwise. Argument is guaranteed to be 10*10 two-dimension array. Elements in the array are numbers, 0 if the cell is free and 1 if occupied by ship.
- test_validate_battlefield_7(**kw)
Testing Battleship field validator [with field=[[1, 0, 0, 0, 0, 0, 0, 0, 0, 0],… [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], expected=False, message=’Must return FALSE if the number and length of ships is not ok’].
Testing a method that takes a field for well-known board game “Battleship” as an argument and returns true if it has a valid disposition of ships, false otherwise. Argument is guaranteed to be 10*10 two-dimension array. Elements in the array are numbers, 0 if the cell is free and 1 if occupied by ship.
- test_validate_battlefield_8(**kw)
Testing Battleship field validator [with field=[[1, 0, 0, 0, 0, 1, 1, 0, 0, 0],… [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], expected=False, message=’Must return FALSE if ships are in contact’].
Testing a method that takes a field for well-known board game “Battleship” as an argument and returns true if it has a valid disposition of ships, false otherwise. Argument is guaranteed to be 10*10 two-dimension array. Elements in the array are numbers, 0 if the cell is free and 1 if occupied by ship.
kyu_3.battleship_field_validator.validator module
Solution for -> Battleship field validator.
Created by Egor Kostan. GitHub: https://github.com/ikostan
- kyu_3.battleship_field_validator.validator.all_cells_valid(**kwargs)[source]
Validate all cells.
- Parameters:
kwargs
- Returns:
- kyu_3.battleship_field_validator.validator.check_horizontal(row, col, field) bool[source]
Verify horizontal direction.
- Parameters:
row
col
field – list, board game “Battleship” (list)
- Returns:
- kyu_3.battleship_field_validator.validator.check_submarine(**kwargs) bool[source]
Check submarine.
Check if submarine already in list (avoid duplicates) Validates if submarine cell has contacts with other ships/cells ships: dict, collection of valid ships (dict) field: list, board game “Battleship” (list) cell: list, candidate for single ship/submarine :return: bool
- kyu_3.battleship_field_validator.validator.check_vertical(row, col, field) bool[source]
Verify vertical direction.
- Parameters:
row
col
field – list, board game “Battleship” (list)
- Returns:
- kyu_3.battleship_field_validator.validator.is_valid_cell(**kwargs) bool[source]
Check if cell is valid.
Validates if single cell result is valid (valid submarine or single ship cell) :return: bool
- kyu_3.battleship_field_validator.validator.ship_counter_by_col(field: list, ships: dict)[source]
Ship counter by col.
- Parameters:
field – list
ships – dict
- Returns:
- kyu_3.battleship_field_validator.validator.ship_counter_by_row(field: list, ships: dict)[source]
Ship counter by row.
- Parameters:
field – list
ships – dict
- Returns:
- kyu_3.battleship_field_validator.validator.validate_battlefield(field: list) bool[source]
Validate battlefield.
A method that takes a field for well-known board game “Battleship” as an argument and returns true if it has a valid disposition of ships, false otherwise. Argument is guaranteed to be 10*10 two-dimension array. Elements in the array are numbers, 0 if the cell is free and 1 if occupied by ship. :param field: 2D list, board game “Battleship” :return: bool, true if there is a valid disposition of ships
Module contents
Codewars kyu_3 package: Battleship field validator.