示例#1
0
def test_findMostRestricted():
	b = (
		(1, 2, 3),
		(1, 1, 3),
		(2, 3, 3)
	)
	p = Puzzle(b , False)
	possibles = [
				[
					[[], [], []],
					[
						[
							[1, 0],
							[1, 1]],
						[],
						[]
					],
					[
						[],
						[],
						[
							[2, 1],
							[2, 2]
						]
					]
				],
				[
					[
						[
							[0, 0],
							[1, 0]
						],
						[],
						[]
					],
					[
						[],
						[],
						[]
					],
					[
						[],
						[],
						[
							[0, 2],
							[1, 2],
							[2, 2]
						]
					]
				]
			]
	possibles = findMostRestricted(p, possibles)

	# The first iteration should just mark bottom-right element as black
	assert(p.isBlack(2, 2))

	# All other adjacent numbers should be marked as adjacent
	assert(p.isMarkedAdjacent(0, 0))
	assert(p.isMarkedAdjacent(0, 2))
	assert(p.isMarkedAdjacent(1, 0))
	assert(p.isMarkedAdjacent(1, 1))
	assert(p.isMarkedAdjacent(1, 2))
	assert(p.isMarkedAdjacent(2, 1))

	# The other two tiles should remain marked White
	assert(p.isWhite(0, 1))
	assert(p.isWhite(2, 0))
示例#2
0
def test_findMostRestrictedCompleted():
	b = (
		(1, 2, 3),
		(1, 1, 3),
		(2, 3, 3)
	)
	p = Puzzle(b , False)
	possibles = [
				[
					[[], [], []],
					[
						[
							[1, 0],
							[1, 1]],
						[],
						[]
					],
					[
						[],
						[],
						[
							[2, 1],
							[2, 2]
						]
					]
				],
				[
					[
						[
							[0, 0],
							[1, 0]
						],
						[],
						[]
					],
					[
						[],
						[],
						[]
					],
					[
						[],
						[],
						[
							[0, 2],
							[1, 2],
							[2, 2]
						]
					]
				]
			]
	findMostRestricted(p, possibles)
	findMostRestricted(p, possibles)

	# These should be Black
	assert(p.isBlack(1, 0))
	assert(p.isBlack(0, 2))

	# These should be now marked White
	assert(p.isWhite(0, 0))
	assert(p.isWhite(1, 2))
	assert(p.isWhite(2, 1))

	# These should still be adjacent
	assert(p.isMarkedAdjacent(1, 1))

	# The other three tiles should have remained marked White
	assert(p.isWhite(0, 1))
	assert(p.isWhite(2, 0))

	# Solve the puzzle fully
	findMostRestricted(p, possibles)

	# This should now be marked White
	assert(p.isWhite(1, 1))

	# Check that the puzzle was solved
	assert(p.isSolved())