def test_get_equation_params_non_integer_slope(self):
     edge = Edge(
         Point(0, 0),
         Point(10, 1))
     self.assertEqual(
         edge.get_equation_params(),
         (0.1, 0, (0, 10), (0, 1)))
 def test_distance_x_horizontal_line(self):
     edge = Edge(
         Point(3, 10),
         Point(10, 10))
     point = Point(0, 10)
     self.assertEqual(
         edge.distance_x(point),
         3)
    def test_is_false_for_line_in_the_bottom_left_corner(self):
        corner = Point(
            self.obstacle.rect.left,
            self.obstacle.rect.bottom)
        
        # Build a line so that the player is on its edge
        line = Polygon([
            corner + Point(-10, -10),
            corner + Point(10, 10)])

        self.assertFalse(
            self.obstacle.is_to_the_right(line))
Exemple #4
0
from unittest import TestCase

import numpy as np
import pygame

from skater.rendering.edge import Edge
from skater.rendering.point import Point
from skater.rendering.shape import Polygon, rectangle
""" A set of points used by the tests
A---B
-----
--C--
-----
D---E
"""
A = Point(0, 0)
B = Point(4, 0)
C = Point(2, 2)
D = Point(0, 4)
E = Point(4, 4)


class TestPolygon(TestCase):
    # TODO: group into classes by method
    def test_centre(self):
        polygon = Polygon([A, B, E, D])
        self.assertEqual(polygon.centre(), C)

    def test_radius(self):
        polygon = Polygon([A, B, E, D])
        self.assertEqual(polygon.radius(), ceil(2 * sqrt(2)))
from unittest import TestCase

from skater.camera import Camera
from skater.rendering.point import Point
from skater.rendering.shape import rectangle

screen_width = 400
screen_height = 300
screen_center_x = screen_width / 2
screen_center_y = screen_height / 2

screen = rectangle(Point(0, 0), Point(screen_width, screen_height))

# The player is in the center of the screen
base_player = rectangle(Point(screen_center_x - 10, screen_center_y - 10),
                        Point(screen_center_x + 10, screen_center_y + 10))


class TestAdjustX(TestCase):
    def test_does_nothing_if_player_in_the_center(self):
        camera = Camera()
        camera.adjust_x(screen, base_player)
        self.assertEqual(camera.x, 0)

    def test_increases_x_if_player_on_the_right(self):
        camera = Camera()
        player = base_player.shifted(x_shift=screen_width)
        camera.adjust_x(screen, player)
        self.assertGreater(camera.x, 0)

    def test_decreases_x_if_player_on_the_left(self):
Exemple #6
0
 def test_within_positive(self):
     point = Point(10, 10)
     self.assertTrue(point.within((0, 20), (0, 20)))
Exemple #7
0
 def test_within_negative(self):
     point = Point(10, 10)
     self.assertFalse(point.within((0, 20), (0, 5)))
from unittest import TestCase

from skater.rendering.edge import Edge
from skater.rendering.point import Point

""" A set of points used by the tests
A---B
-F---
--C--
-----
D---E
"""
A = Point(0, 0)
B = Point(100, 0)
C = Point(50, 50)
D = Point(0, 100)
E = Point(100, 100)
F = Point(25, 25)

class TestEdge(TestCase):
    def test_get_equation_params(self):
        edge = Edge(D, B)
        self.assertEqual(
            edge.get_equation_params(),
            (-1, 100, (0, 100), (0, 100)))

    def test_get_equation_params_non_zero_x(self):
        edge = Edge(C, E)
        self.assertEqual(
            edge.get_equation_params(),
            (1, 0, (50, 100), (50, 100)))