def is_term_tests(): seq = Sequence([1, 2, 4], 3) res = seq.is_term() expect(False, res) seq = Sequence([1, 2, 3], 3) res = seq.is_term() expect(True, res)
def contains_arithmetic_sequence_tests(): seq = Sequence([1, 3, 5], 3) res = seq.contains_arithmetic_sequence(3, 2, 1) expect(True, res) seq = Sequence([1, 3, 5, 6], 3) res = seq.contains_arithmetic_sequence(3, 2, 2) expect(False, res)
def evaluate_for_k_greater_than_n(): seq = Sequence([1], 2) res = seq.evaluate() expect(0, res) seq = Sequence([1, 2], 3) res = seq.evaluate() expect(0, res)
def second_player_chooses_a_winning_move(): ab = AlfaBeta([1, 2, 3, 4, 5], [1, 0, 2, 2, 1], 3, 2, 1) res = ab.get_move() expect(1, res) ab = AlfaBeta([1, 2, 3, 4, 5], [0, 0, 2, 2, 1], 3, 2, 1) res = ab.get_move() expect(1, res)
def first_player_chooses_a_winning_move(): ab = AlfaBeta([1, 2, 3, 4, 5], [2, 0, 1, 1, 2], 3, 1, 2) res = ab.get_move() expect(1, res) ab = AlfaBeta([1, 2, 3, 4, 5], [0, 0, 1, 1, 2], 3, 1, 2) res = ab.get_move() expect(1, res)
def search_startidx_tests(): sequence = Sequence([2, 4, 6, 7, 11], 3) res = sequence.search(2, 1) expect(-1, res) res = sequence.search(7, 1) expect(3, res) res = sequence.search(7, 3) expect(3, res) res = sequence.search(7, 4) expect(-1, res)
def evaluate_tests(): seq = Sequence([1, 2, 3], 3) res = seq.evaluate() expect(1, res) seq = Sequence([1, 2, 4], 3) res = seq.evaluate() expect(0, res) seq = Sequence([1, 2, 4, 5, 6], 3) res = seq.evaluate() expect(2, res) seq = Sequence([1, 2, 3, 4, 5], 3) res = seq.evaluate() expect(4, res)
def evaluate_for_k_equals_two(): seq = Sequence([1, 2], 2) res = seq.evaluate() expect(1, res) seq = Sequence([1, 2, 3], 2) res = seq.evaluate() expect(3, res) seq = Sequence([1, 2, 4, 7], 2) res = seq.evaluate() expect(6, res) seq = Sequence([1, 2, 4, 7, 11], 2) res = seq.evaluate() expect(10, res)
def can_reach_last_element_of_arithmetic_sequence_tests(): seq = Sequence([1, 2, 4], 3) res = seq.can_reach_last_element_of_arithmetic_sequence(1, 1) expect(True, res) seq = Sequence([1, 3, 4], 3) res = seq.can_reach_last_element_of_arithmetic_sequence(1, 2) expect(False, res) seq = Sequence([1, 3, 5], 3) res = seq.can_reach_last_element_of_arithmetic_sequence(1, 2) expect(True, res)
def calculate_terminal_node_value_tests(): ab = AlfaBeta([1, 2, 3], [0, 0, 0], 2, 1, 2) res = ab.calculate_terminal_node_value(1) is_none(res) res = ab.calculate_terminal_node_value(2) is_none(res) ab = AlfaBeta([1, 2, 3, 4], [0, 1, 0, 2], 2, 1, 2) res = ab.calculate_terminal_node_value(1) is_none(res) res = ab.calculate_terminal_node_value(2) is_none(res) ab = AlfaBeta([1, 2, 3, 4, 5], [1, 1, 2, 2, 2], 3, 1, 2) res = ab.calculate_terminal_node_value(1) is_none(res) res = ab.calculate_terminal_node_value(2) expect(-max_value, res) ab = AlfaBeta([1, 2, 3, 4, 5], [1, 2, 1, 2, 1], 3, 1, 2) res = ab.calculate_terminal_node_value(1) expect(max_value, res) res = ab.calculate_terminal_node_value(2) is_none(res) ab = AlfaBeta([1, 2, 3, 4, 5], [1, 2, 1, 2, 1], 3, 2, 1) res = ab.calculate_terminal_node_value(1) expect(-max_value, res) res = ab.calculate_terminal_node_value(2) is_none(res)
def search_with_startidx_equals_zero(): sequence = Sequence([2, 4, 6, 7, 11], 3) res = sequence.search(1, 0) expect(-1, res) res = sequence.search(5, 0) expect(-1, res) res = sequence.search(8, 0) expect(-1, res) res = sequence.search(13, 0) expect(-1, res) res = sequence.search(2, 0) expect(0, res) res = sequence.search(6, 0) expect(2, res) res = sequence.search(11, 0) expect(4, res)
def assert_find_longest_ap(element_list, expected_value): res = Game._find_longest_ap(element_list) expect(res, expected_value)
def evaluate_node_tests(): ab = AlfaBeta([1, 2, 3], [0, 0, 0], 2, 1, 2) res = ab.evaluate_node(1) expect(3, res) res = ab.evaluate_node(2) expect(-3, res) ab = AlfaBeta([1, 2, 3, 4], [0, 1, 0, 2], 2, 1, 2) res = ab.evaluate_node(1) expect(3, res) res = ab.evaluate_node(2) expect(-3, res) ab = AlfaBeta([1, 2, 3, 4, 5], [1, 1, 2, 2, 2], 3, 1, 2) res = ab.evaluate_node(1) expect(0, res) res = ab.evaluate_node(2) expect(-1, res) ab = AlfaBeta([1, 2, 3, 4, 5], [1, 0, 1, 2, 1], 3, 1, 2) res = ab.evaluate_node(1) expect(2, res) res = ab.evaluate_node(2) expect(0, res) ab = AlfaBeta([1, 2, 3, 4, 5], [1, 2, 0, 2, 0], 3, 2, 1) res = ab.evaluate_node(1) expect(-1, res) res = ab.evaluate_node(2) expect(2, res) ab = AlfaBeta([1, 2, 3, 4, 5, 6, 7], [1, 2, 0, 2, 0, 0, 0], 3, 2, 1) res = ab.evaluate_node(1) expect(-3, res) res = ab.evaluate_node(2) expect(6, res)
def second_player_blocks_a_winning_move_of_first_player(): ab = AlfaBeta([1, 2, 3, 4, 5, 6], [0, 0, 0, 1, 1, 2], 3, 2, 1) res = ab.get_move() expect(2, res)
def second_player_chooses_move_to_win(): ab = AlfaBeta([1, 2, 3, 4, 5, 6, 7], [1, 1, 2, 0, 0, 0, 2], 3, 2, 1) res = ab.get_move() expect(4, res)
def first_player_chooses_move_to_win(): ab = AlfaBeta([1, 2, 3, 4, 5, 6, 7], [2, 2, 1, 0, 0, 0, 1], 3, 1, 2) res = ab.get_move() expect(4, res)