Пример #1
0
    def test_dividing(self):

        divider = Divider()

        for x in range(5, 10):
            for y in range(5, 10):
                self.assertEqual(x / y, divider.calc(x, y))
Пример #2
0
    def __init__(self,
                 app=None,
                 show=False,
                 title='[ A Window ]',
                 show_divider=lambda:True,
                 get_lexer=lambda: None,
                 height=Dimension(preferred=1),
                 wrap_lines=False,
                 scroll_offsets=ScrollOffsets()):
        self.app = app
        self.show = show
        self.buffer = Buffer(document=Document(),
                             multiline=True)
        self.control = BufferControl(buffer=self.buffer,
                                     focusable=True,
                                     lexer=self.lexer,
                                     focus_on_click=True)
        self.window = PromptWindow(content=self.control,
                                   height=height,
                                   wrap_lines=wrap_lines,
                                   scroll_offsets=scroll_offsets)

        self.divider = Divider(self, show=show_divider)
        self.info = InfoLine(title, width=240)
        self.container = ConditionalContainer(
            content=VSplit([
                self.divider.get_ui(),
                HSplit([self.info.get_ui(), self.window])]),
            filter=Condition(lambda: self.show))
Пример #3
0
    def doWork(self, root, fileName):
        if not fileName.endswith(".xml"):
            return

        srcFile = root + "/" + fileName
        resultFilePath = srcFile

        if self.dataFileExists(fileName, srcFile):
            soup = self.integrateParentWithData(fileName, srcFile)
        else:
            xmlDataFile = codecs.open(srcFile, "r", "utf-8")
            xmlData = xmlDataFile.read()
            xmlData = html.unescape_string(xmlData)
            xmlDataFile.close()
            soup = BeautifulSoup(xmlData, "lxml")

        soup = self.semantify(soup, resultFilePath)

        # 最后做断句处理
        divider = Divider(soup, self.config_file_path)
        soup = divider.doWork()

        resultFile = codecs.open(resultFilePath, "w", "utf-8")
        resultFile.write(self.beautiful_soup_tag_to_unicode(soup))
        resultFile.close()

        self.count += 1
        print "Processed: %d" % self.count
Пример #4
0
    def test_dividing(self):
        divider = Divider()

        for i in range(-10, 10):
            for j in range(-10, 10):
                if j != 0:
                    self.assertEqual(i / j, divider.calc(i, j))
Пример #5
0
 def test_divider(self):
     divider = Divider()
     try:
         for i in range(-10, 10):
             for j in range(-10, 10):
                 self.assertEqual(i / j, divider.calc(i, j))
     except ZeroDivisionError:
         return 0
Пример #6
0
    def test_dividing(self):
        divider = Divider()

        for i in range(-10, 10):
            for j in range(-10, 10):
                if i == 0 or j == 0:
                    continue
                else:
                    self.assertEqual(i / j, divider.calc(i, j))
Пример #7
0
    def test_divider(self):
        divider = Divider()

        for i in range(-10, 10):
            for j in range(-10, 10):
                try:
                    self.assertEqual(i / j, divider.calc(i, j))
                except ZeroDivisionError:
                    # print("skipping zero division cases")
                    pass
Пример #8
0
    def test_dividing(self):
        """Test diider functionalty"""
        divider = Divider()

        for i in range(-10, 10):
            for j in range(-10, 10):
                if i == 0 or j == 0:
                    continue
                else:
                    self.assertEqual(i / j, divider.calc(i, j))
Пример #9
0
 def setUp(self):
     self.adder = Adder()
     self.subtracter = Subtracter()
     self.multiplier = Multiplier()
     self.divider = Divider()
     self.calculator = Calculator(self.adder, self.subtracter,
                                  self.multiplier, self.divider)
Пример #10
0
def run_game():
    # Initialize pygame, settings, and screen object.
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("Pong")
    stats = GameStats(ai_settings)
    winner = stats.winner
    play_button = Button(screen, "PLAY GAME", "PONG", "AI -- NO WALLS", winner)
    sb = Scoreboard(ai_settings, screen, stats)
    # Make paddles, ball, divider
    divider = Divider(ai_settings, screen)
    ball = Ball(ai_settings, screen)
    paddles = Paddle(ai_settings, screen, divider, ball)
    effect = pygame.mixer.Sound('audio/pop2.wav')

    # Start the main loop for the game.
    while True:
        gf.check_events(ai_settings, paddles, play_button, sb)
        if ai_settings.game_active:
            gf.update_paddles(paddles)
            gf.update_ball(ball, ai_settings, paddles, divider, stats, sb,
                           effect, play_button)
        gf.update_screen(ai_settings, screen, paddles, ball, divider,
                         play_button, sb)
Пример #11
0
    def test_module(self):

        calculator = Calculator(Adder(), Subtracter(), Multiplier(), Divider())

        calculator.enter_number(5)
        calculator.enter_number(2)

        calculator.multiply()

        calculator.enter_number(46)

        calculator.add()

        calculator.enter_number(8)

        calculator.divide()

        calculator.enter_number(1)

        result = calculator.subtract()

        self.assertEqual(6, result)

        # pulled from the unittest file, testing that there is not
        # a missing operand
        with self.assertRaises(InsufficientOperands):
            calculator.add()
Пример #12
0
    def setUp(self):
        """Setup function to add modules to calculator"""
        self.adder = Adder()
        self.subtracter = Subtracter()
        self.multiplier = Multiplier()
        self.divider = Divider()

        self.calculator = Calculator(self.adder, self.subtracter,
                                     self.multiplier, self.divider)
    def test_division(self):
        calculator = Calculator(Adder(), Subtracter(), Multiplier(), Divider())

        calculator.enter_number(2)
        calculator.enter_number(10)

        result = calculator.divide()
        self.assertEqual(5, result)
        del calculator
    def test_subtraction_error(self):
        calculator = Calculator(Adder(), Subtracter(), Multiplier(), Divider())

        calculator.enter_number(24)
        calculator.enter_number(12)

        result = calculator.subtract()
        self.assertEqual(12, result)
        del calculator
    def test_subtraction(self):
        calculator = Calculator(Adder(), Subtracter(), Multiplier(), Divider())

        calculator.enter_number(-2)
        calculator.enter_number(10)

        result = calculator.add()
        self.assertEqual(8, result)
        del calculator
    def test_multiplication(self):
        calculator = Calculator(Adder(), Subtracter(), Multiplier(), Divider())

        calculator.enter_number(10)
        calculator.enter_number(12)

        result = calculator.multiply()
        self.assertEqual(120, result)
        del calculator
Пример #17
0
    def test_module(self):
        calculator = Calculator(Adder(), Subtracter(), Multiplier(), Divider())

        calculator.enter_number(5)
        calculator.enter_number(2)

        calculator.multiply()

        calculator.enter_number(46)

        calculator.add()

        calculator.enter_number(8)

        calculator.divide()

        calculator.enter_number(1)

        result = calculator.subtract()

        self.assertEqual(6, result)
    def test_module(self):
        calculator = Calculator(Adder(), Subtracter(), Multiplier(), Divider())

        calculator.enter_number(3)
        calculator.enter_number(4)

        self.assertEqual(12, calculator.multiply())

        calculator.enter_number(2)

        self.assertEqual(10, calculator.subtract())

        calculator.enter_number(10)

        self.assertEqual(calculator.add(), 20)

        calculator.enter_number(5)

        result = calculator.divide()

        self.assertEqual(4, result)
Пример #19
0
    def test_module(self):

        calculator = Calculator(Adder(), Subtracter(), Multiplier(), Divider())

        calculator.enter_number(5)
        calculator.enter_number(2)

        r1 = calculator.multiply()
        print('multiplication result:', r1)
        calculator.enter_number(46)

        r2 = calculator.add()
        print('addition result:', r2)
        calculator.enter_number(8)

        r3 = calculator.divide()
        print('division result:', r3)
        calculator.enter_number(1)

        result = calculator.subtract()
        print('result after final step of subtraction:', result)
        self.assertEqual(6, result)
Пример #20
0
    def test_modules(self):
        """Function to test each of the modules and function calls"""

        calculator = Calculator(Adder(), Subtracter(), Multiplier(), Divider())

        calculator.enter_number(5)
        calculator.enter_number(2)

        calculator.multiply()

        calculator.enter_number(46)

        calculator.add()

        calculator.enter_number(8)

        calculator.divide()

        calculator.enter_number(1)

        result = calculator.subtract()

        self.assertEqual(6, result)
Пример #21
0
def main(width, height):
	screen = pygame.display.set_mode((width,height),pygame.RESIZABLE)
	pygame.display.set_caption("Tankball!")

	background = pygame.Surface(screen.get_size())
	background = background.convert()
	background.fill((255, 255, 255))
	screen.blit(background, (0, 0))

	state = "PAUSED"

	#sound effect
	victorySound = pygame.mixer.Sound("victory.wav")
	victoryPlayed = False
	
	#create players and ball
	player1 = Player(screen, 1)
	player2 = Player(screen, 2)
	turret1 = Turret(player1)
	turret2 = Turret(player2)
	print("Players have been created.")

	ball = Ball(screen, player1, player2, "PAUSED")
	print("Ball has been created.")

	#create bullets
	p1Bullets = [None]*1
	p2Bullets = [None]*1

	for i in range(1):
		p1Bullets[i] = Bullet(screen,player1,ball)
		p2Bullets[i] = Bullet(screen,player2,ball)
	print("Populated list of bullets.")

	player1.setBullets(p1Bullets)
	player2.setBullets(p2Bullets)
	print("Finished passing bullets to players.")
	divider = Divider(screen)

	#group sprites
	ballSprite = pygame.sprite.Group(ball)
	playerSprites = pygame.sprite.Group(player1,player2)
	turretSprites = pygame.sprite.Group(turret1,turret2)
	p1BulletSprites = pygame.sprite.Group()
	p2BulletSprites = pygame.sprite.Group()

	for i in range(1):
		p1BulletSprites.add(p1Bullets[i])
		p2BulletSprites.add(p2Bullets[i])
	uiSprites = pygame.sprite.Group(divider)

	#UI
	title_text = pygame.font.SysFont('Consolas', int(screen.get_width() / 10)).render("Tankball!", True, pygame.color.Color("Black"))

	pause_text = pygame.font.SysFont('Consolas', int(screen.get_width() / 20)).render("Paused (Return/P)", True, pygame.color.Color("Red"))

	controls_text = pygame.font.SysFont('Consolas', int(screen.get_width() / 40)).render("Controls", True, pygame.color.Color("Red"))

	unpause_text = pygame.font.SysFont('Consolas', int(screen.get_width() / 40)).render("Return or P - Pause/Unpause", True, pygame.color.Color("Red"))
	
	move_text = pygame.font.SysFont('Consolas', int(screen.get_width() / 40)).render("A/D or Left/Right - Move", True, pygame.color.Color("Red"))

	aim_text = pygame.font.SysFont('Consolas', int(screen.get_width() / 40)).render("W/S or Up/Down - Aim", True, pygame.color.Color("Red"))

	fire_text = pygame.font.SysFont('Consolas', int(screen.get_width() / 40)).render("Spacebar or Right CTRL - Fire", True, pygame.color.Color("Red"))

	win_text1 = pygame.font.SysFont('Consolas', int(screen.get_width() / 20)).render("Player 1 wins!", True, pygame.color.Color("Black"))

	win_text2 = pygame.font.SysFont('Consolas', int(screen.get_width() / 20)).render("Player 2 wins!", True, pygame.color.Color("Black"))
	
	restart_text = pygame.font.SysFont('Consolas', int(screen.get_width() / 40)).render("R to Restart", True, pygame.color.Color("Black"))

	clock = pygame.time.Clock()
	print("Clock set.")
	keepGoing = True
	print("Running main game loop...")
	while keepGoing:
		clock.tick(30)
		for event in pygame.event.get():
			if event.type == pygame.QUIT:
				keepGoing = False
			if event.type == pygame.VIDEORESIZE:
				screen = pygame.display.set_mode((event.w, event.h),pygame.RESIZABLE)
				background = pygame.Surface(screen.get_size())
				background = background.convert()
				background.fill((255, 255, 255))
				
				#recenter ball
				ball.x = screen.get_width() / 2
				ball.y = screen.get_height() / 3

				#resize UI
				title_text = pygame.font.SysFont('Consolas', int(screen.get_width() / 10)).render("Tankball!", True, pygame.color.Color("Black"))

				pause_text = pygame.font.SysFont('Consolas', int(screen.get_width() / 20)).render("Paused", True, pygame.color.Color("Red"))

				controls_text = pygame.font.SysFont('Consolas', int(screen.get_width() / 40)).render("Controls", True, pygame.color.Color("Red"))

				unpause_text = pygame.font.SysFont('Consolas', int(screen.get_width() / 40)).render("Return or P - Pause/Unpause", True, pygame.color.Color("Red"))
				
				move_text = pygame.font.SysFont('Consolas', int(screen.get_width() / 40)).render("A/D or Left/Right - Move", True, pygame.color.Color("Red"))

				aim_text = pygame.font.SysFont('Consolas', int(screen.get_width() / 40)).render("W/S or Up/Down - Aim", True, pygame.color.Color("Red"))

				fire_text = pygame.font.SysFont('Consolas', int(screen.get_width() / 40)).render("Spacebar or Right CTRL - Fire", True, pygame.color.Color("Red"))

				win_text1 = pygame.font.SysFont('Consolas', int(screen.get_width() / 20)).render("Player 1 wins!", True, pygame.color.Color("Black"))

				win_text2 = pygame.font.SysFont('Consolas', int(screen.get_width() / 20)).render("Player 2 wins!", True, pygame.color.Color("Black"))
				
				restart_text = pygame.font.SysFont('Consolas', int(screen.get_width() / 40)).render("R to Restart", True, pygame.color.Color("Black"))
				
			if event.type == pygame.KEYDOWN:
				#return key or p key (ascii)
				if event.key == 13 or event.key == 112:
					#unpause
					if state == "PAUSED":
						for ball in ballSprite.sprites():
							ball.unpause()
						for player in playerSprites.sprites():
							player.unpause()

						state = "RUNNING"
					#pause
					elif state == "RUNNING":
						for ball in ballSprite.sprites():
							ball.pause()
						for player in playerSprites.sprites():
							player.pause()

						state = "PAUSED"
				#r key
				if event.key == 114:
					if state == "END":
						return True, screen.get_width(), screen.get_height()

		screen.blit(background, (0, 0))

		#clear sprites
		ballSprite.clear(screen, background)
		playerSprites.clear(screen, background)
		uiSprites.clear(screen, background)

		#update sprites
		ballSprite.update()
		turretSprites.update()
		playerSprites.update()
		p1BulletSprites.update()
		p2BulletSprites.update()
		uiSprites.update()

		#draw sprites
		ballSprite.draw(screen)
		p1BulletSprites.draw(screen)
		p2BulletSprites.draw(screen)
		playerSprites.draw(screen)
		turretSprites.draw(screen)
		uiSprites.draw(screen)

		score_text1 = pygame.font.SysFont('Consolas', int(screen.get_width() / 10)).render("{0}".format(player1.score), True, pygame.color.Color("Black"))
		score_text2 = pygame.font.SysFont('Consolas', int(screen.get_width() / 10)).render("{0}".format(player2.score), True, pygame.color.Color("Black"))

		screen.blit(score_text1, (0, 0))
		screen.blit(score_text2, (screen.get_width() - score_text2.get_width(), 0))
		if state == "PAUSED":
			screen.blit(title_text, (screen.get_width() / 2 - (title_text.get_width() / 2), 0))

			offset = score_text1.get_height()
			screen.blit(pause_text, (0, offset))
			offset += pause_text.get_height()
			screen.blit(controls_text, (0, offset))
			offset += controls_text.get_height()
			screen.blit(unpause_text, (0, offset))
			offset += unpause_text.get_height()
			screen.blit(move_text, (0, offset))
			offset += move_text.get_height()
			screen.blit(aim_text, (0, offset))
			offset += aim_text.get_height()
			screen.blit(fire_text, (0, offset))

		if player1.score >= 5:
			screen.blit(win_text1, ((screen.get_width() / 2) - (win_text1.get_width() / 2), (screen.get_height() / 2) - (win_text1.get_height() / 2)))
			screen.blit(restart_text, ((screen.get_width() / 2) - (restart_text.get_width() / 2), (screen.get_height() / 2) + win_text1.get_height()))

			if victoryPlayed == False:
				victorySound.play()
				victoryPlayed = True
			
			for ball in ballSprite.sprites():
				ball.pause()
			for player in playerSprites.sprites():
				player.pause()

			state = "END"
		elif player2.score >= 5:
			screen.blit(win_text2, ((screen.get_width() / 2) - (win_text2.get_width() / 2), (screen.get_height() / 2) - (win_text2.get_height() / 2)))
			screen.blit(restart_text, ((screen.get_width() / 2) - (restart_text.get_width() / 2), (screen.get_height() / 2) + win_text2.get_height()))

			if victoryPlayed == False:
				victorySound.play()
				victoryPlayed = True
			
			for ball in ballSprite.sprites():
				ball.pause()
			for player in playerSprites.sprites():
				player.pause()

			state = "END"

		pygame.display.flip()

	return False, 0, 0
Пример #22
0
def main_loop():
    start = False
    game_exit = False
    game_over = False

    player1 = Player(1, white, screen_width, screen_height)
    player2 = Player(2, white, screen_width, screen_height)

    ball = Ball(Direction.No, white, screen_width, screen_height)
    divider = Divider(white, screen_width)

    while not game_exit:
        for event in pygame.event.get():
            if event.type == QUIT:
                game_exit = True

            # Escape game when escape key is pressed
            if event.type == KEYDOWN:
                if event.key == K_ESCAPE:
                    game_exit = True

                # Move players with arrow keys and WASD
                if start:
                    if event.key == K_w:
                        player1.move_up()
                    if event.key == K_s:
                        player1.move_down()

                    if event.key == K_UP:
                        player2.move_up()
                    if event.key == K_DOWN:
                        player2.move_down()

                # Press Space to start game
                if event.key == K_SPACE:
                    if not start:
                        start = True
                        ball.__init__(Direction.Left, white, screen_width,
                                      screen_height)
                    if game_over:
                        main_loop()

            # Stop moving player if arrows or WASD is up
            if event.type == KEYUP:
                if event.key == K_w or event.key == K_s:
                    player1.stop()
                if event.key == K_UP or event.key == K_DOWN:
                    player2.stop()

        # Fill black background
        game_surface.fill(black)

        # Render game objects and UI
        if start:
            ball.draw(game_surface)
        divider.draw(game_surface, screen_height)

        player1.draw(game_surface, screen_height)
        player2.draw(game_surface, screen_height)

        if not start and not game_over:
            game_surface.blit(start_text, [240, 200])

        display_score(player1)
        display_score(player2)

        # Check collisions
        if not game_over:
            if ball.check_collision_player(
                    player1) or ball.check_collision_player(player2):
                ball.change_direction_horizontal()

            if ball.check_collision_wall(screen_height):
                ball.change_direction_vertical()

            if ball.check_score(player1, player2, screen_width) == player1:
                ball.__init__(Direction.Left, white, screen_width,
                              screen_height)
                player1.add_score()
            elif ball.check_score(player1, player2, screen_width) == player2:
                ball.__init__(Direction.Right, white, screen_width,
                              screen_height)
                player2.add_score()

        # Handle game winning
        if winner(player1, player2, ball) != None:
            player_win(winner(player1, player2, ball), ball)

            start = False
            game_over = True

        # Render game at 60 fps
        clock.tick(60)
        pygame.display.update()

    quit_game()
Пример #23
0
from divider import Divider
from paddle import Paddle
from ball import Ball
import time

screen = Screen()
screen.setup(800, 600)
screen.bgcolor("black")
screen.title(
    "pong_game (use key W & S for left paddle and I & J for right paddle)")
screen.tracer(0)

# two paddle created
r_paddle = Paddle((350, 0))
l_paddle = Paddle((-350, 0))
divider = Divider()

screen.listen()
screen.onkey(r_paddle.go_up, "i")
screen.onkey(r_paddle.go_down, "j")
screen.onkey(l_paddle.go_up, "w")
screen.onkey(l_paddle.go_down, "s")

ball = Ball()
scoreboard = Scoreboard()
game_is_on = True

while game_is_on:
    time.sleep(ball.move_speed)
    screen.update()
    ball.move()
Пример #24
0
 def test_divider(self):
     div = Divider()
     for i in range(-10, 10):
         for j in [x for x in range(-10, 10) if x != 0]:
             self.assertEqual(i / j, div.calc(i, j))
Пример #25
0
import math
import time

from divider import Divider
from rtneo_address import WeHave
from searcher import Search

start_time = time.time()
a = WeHave('зима', 'Зима', '38:35')

# a.create_rtneo_file()

a = Search('')

a.put_daughter()

a.put_info(5000)

a.reformat_uk_json()
a.put_uk_info()

b = Divider()
b.divide_by_assignation_code()
b.divide_by_type_uk()
b.only_uk()
b.without_uk()

print("Отработано за %s секунд" % math.ceil(time.time() - start_time))
Пример #26
0
# solution.py

from divider import Divider

x = int(raw_input())
y = int(raw_input())

d = Divider()
try:
    print "Quotient is %d" % d.divide(x, y)
except ValueError:
    print "Cannot divide by zero"
    
from divider import Divider

divider = Divider()

print divider.divide(10,5);
Пример #28
0
from divider import Divider

divider = Divider()

print divider.divide(10, 5)
Пример #29
0
 def test_divider(self):
     divider = Divider()
     for i in range(1, 10):
         for j in range(1, 10):
             self.assertEqual(i / j, divider.calc(i, j))