def test_is_angle_in_random_range(): """Test that for a range of angles and angular ranges, the is_angle_in_range function correctly calculates if the angle is in the range.""" # Create a number of ranges between 0 and 360 to see if they are within range num_range = 100 for n in range(num_range): angular_range = (int(random.random() * 360), int(random.random()) * 360) # If A < B or A > B if angular_range[0] < angular_range[1]: # Check that the following are true # angle in range 0 -> A = False # angle in range A -> B = True # angle in range B -> 360 = False for angle in range(0, angular_range[0]): assert is_angle_in_range(angular_range, angle, True) is False for angle in range(angular_range[0], angular_range[1] + 1): assert is_angle_in_range(angular_range, angle, True) is True for angle in range(angular_range[1] + 1, 360): assert is_angle_in_range(angular_range, angle, True) is False else: # Check that the following are true # angle in range 0 -> B = True # angle in range B -> A = False # angle in range A -> 360 = True for angle in range(0, angular_range[1] + 1): assert is_angle_in_range(angular_range, angle, True) is True for angle in range(angular_range[1] + 1, angular_range[0]): assert is_angle_in_range(angular_range, angle, True) is False for angle in range(angular_range[0], 360): assert is_angle_in_range(angular_range, angle, True) is True
def tst_is_angle_in_range(): """Test that for a range of angles and angular ranges, the is_angle_in_range function correctly calculates if the angle is in the range. """ from random import random # Some helper lambda functions mod_360 = lambda x: x - 360.0 * floor(x / 360.0) mod_360_range = lambda x: (mod_360(x[0]), mod_360(x[1])) random_0_360 = lambda: int(random() * 360.0) # Create a number of ranges between 0 and 360 and check 360 degrees worth # of angles to see if they are within the range num_range = 100 for n in range(num_range): angular_range = (random_0_360(), random_0_360()) # If A < B or A > B if angular_range[0] < angular_range[1]: # Check that the following are true # angle in range 0 -> A = False # angle in range A -> B = True # angle in range B -> 360 = False for angle in range(0, angular_range[0]): assert(is_angle_in_range(angular_range, angle, True) == False) for angle in range(angular_range[0], angular_range[1]+1): assert(is_angle_in_range(angular_range, angle, True) == True) for angle in range(angular_range[1]+1, 360): assert(is_angle_in_range(angular_range, angle, True) == False) else: # Check that the following are true # angle in range 0 -> B = True # angle in range B -> A = False # angle in range A -> 360 = True for angle in range(0, angular_range[1]+1): assert(is_angle_in_range(angular_range, angle, True) == True) for angle in range(angular_range[1]+1, angular_range[0]): assert(is_angle_in_range(angular_range, angle, True) == False) for angle in range(angular_range[0], 360): assert(is_angle_in_range(angular_range, angle, True) == True) # Create a range over 360 and make sure all angles are valid angular_range = (-10, 370) for angle in range(0, 360): assert(is_angle_in_range(angular_range, angle, True) == True) # Test passed print "OK"
def test_is_angle_sweep_in_range(): # Create a range over 360 and make sure all angles are valid angular_range = (-10, 370) for angle in range(0, 360): assert is_angle_in_range(angular_range, angle, True) is True