예제 #1
0
def test_manhattan():
    ''' function: test_manhattan
        Input: none
        Returns: int, # of tests that failed
        Does: tests a few different inputs on the manhattan
              distance function, makes sure each distance value
              is as-expected.
    '''

    num_failed = 0

    # Test 1: (20, 15), (25, 30)
    # Distance should be 20
    actual = manhattan(20, 15, 25, 30)
    expected = 20
    print('Input (20, 15), (25, 30).\n'
          'Expected result', expected, 'and actual result =', actual)
    if absolute(actual - expected) < EPSILON:
        print('SUCCESS!\n')
    else:
        print('FAIL :( \n')
        num_failed += 1

    # Test 2: (20, 15), (25, 32).
    # Distance is 22.32
    actual = manhattan(20.90, 15, 25.25, 32.97)
    expected = 22.32
    print('Input (20.90, 15), (25.25, 32.97).\n'
          'Expected result', expected, 'and actual result =', actual)
    if absolute(actual - expected) < EPSILON:
        print('SUCCESS!\n')
    else:
        print('FAIL :( \n')
        num_failed += 1

    # Test 3: (-5.3, 4.8), (-14, 0.7)
    # Distance is 12.8
    actual = manhattan(-5.3, 4.8, -14, 0.7)
    expected = 12.8
    print('Input (-5.3, 4.8), (-14, 0.7).\n'
          'Expected result', expected, 'and actual result =', actual)
    if absolute(actual - expected) < EPSILON:
        print('SUCCESS!\n')
    else:
        print('FAIL :( \n')
        num_failed += 1

    # Test 4: (7.9, 5), (-17.2, 3)
    # Distance is 27.1
    actual = manhattan(7.9, 5, -17.2, 3)
    expected = 27.1
    print('Input (7.9, 5), (-17.2, 3).\n'
          'Expected result', expected, 'and actual result =', actual)
    if absolute(actual - expected) < EPSILON:
        print('SUCCESS!\n')
    else:
        print('FAIL :(\n')
        num_failed += 1

    return num_failed
예제 #2
0
def test_euclidean():
    ''' function test_euclidean
        Input: none
        Returns: int, # of tests that failed
        Does: tests a few different inputs on the euclidean
              distance function, makes sure each distance value
              is as-expected.
    '''

    num_failed = 0

    # Test 1: (0, 0), (0, 0)
    # Distance should be 0
    actual = euclidean(0, 0, 0, 0)
    expected = 0.0
    print('Input (0, 0), (0, 0).\n'
          'Expected result', expected, 'and actual result =', actual)
    if absolute(actual - expected) < EPSILON:
        print('SUCCESS!\n')
    else:
        print('FAIL :( \n')
        num_failed += 1

    # Test 2: (2, -1), (-2, 2).
    # Distance is 5.0
    actual = euclidean(2, -1, -2, 2)
    expected = 5.0
    print('Input (2, -1), (-2, 2).\n'
          'Expected result', expected, 'and actual result =', actual)
    if absolute(actual - expected) < EPSILON:
        print('SUCCESS!\n')
    else:
        print('FAIL :( \n')
        num_failed += 1

    # Test 3: (1, 1), (0, 1)
    # Distance is 1.0
    actual = euclidean(1, 1, 0, 1)
    expected = 1.0
    print('Input (1, 1), (0, 1).\n'
          'Expected result', expected, 'and actual result =', actual)
    if absolute(actual - expected) < EPSILON:
        print('SUCCESS!\n')
    else:
        print('FAIL :( \n')
        num_failed += 1

    # Test 4: (-5.2, 3.8), (-13.4, 0.2)
    # Distance is 8.955445
    actual = euclidean(-5.2, 3.8, -13.4, 0.2)
    expected = 8.955445
    print('Input (-5.2, 3.8), (-13.4, 0.2).\n'
          'Expected result', expected, 'and actual result =', actual)
    if absolute(actual - expected) < EPSILON:
        print('SUCCESS!\n')
    else:
        print('FAIL :(\n')
        num_failed += 1

    return num_failed
예제 #3
0
def test_absolute():
    ''' function test_absolute
        Input: none
        Returns: int, # of tests that failed
        Does: tests a few different inputs on the absolute function,
        makes sure each value is as-expected.
    '''

    num_failed = 0
    #Test 1: -5
    #Absolute value should be 5
    actual = absolute(-5)
    expected = 5
    print('Input (-5).\n'
          'Expected result', expected, 'and actual result =', actual)
    if absolute(actual - expected) < EPSILON:
        print('SUCCESS!\n')
    else:
        print('FAIL :( \n')
        num_failed += 1

    #Test 2: 3.95
    #Absolute value should be 3.95
    actual = absolute(3.95)
    expected = 3.95
    print('Input (3.95).\n'
          'Expected result', expected, 'and actual result =', actual)
    if absolute(actual - expected) < EPSILON:
        print('SUCCESS!\n')
    else:
        print('FAIL :( \n')
        num_failed += 1

    #Test 3: 0
    #Absolute value should be 0
    actual = absolute(0)
    expected = 0
    print('Input (0).\n'
          'Expected result', expected, 'and actual result =', actual)
    if absolute(actual - expected) < EPSILON:
        print('SUCCESS!\n')
    else:
        print('FAIL :( \n')
        num_failed += 1

    #Test 4: -45.45
    #Absolute value should be -45.45
    actual = absolute(-45.45)
    expected = 45.45
    print('Input (-45.45).\n'
          'Expected result', expected, 'and actual result =', actual)
    if absolute(actual - expected) < EPSILON:
        print('SUCCESS!\n')
    else:
        print('FAIL :( \n')
        num_failed += 1

    return num_failed
예제 #4
0
def test_manhattan():
    ''' function test_manhattan
        Input: none
        Returns: int, # of tests that failed
        Does: tests a few different inputs on manhattan function, makes sure each manhattan distance value output is as-expected.
    '''

    print('\n \n' 'Running Manhattan Test')
    num_failed = 0

    # Test 1: (0, 0), (0, 0)
    # Manhattan output value should be 0
    actual = manhattan(0, 0, 0, 0)
    expected = 0.0
    print('Input ((0, 0), (0, 0)).\n'
          'Expected result', expected, 'and actual result =', actual)
    if absolute(actual - expected) < EPSILON:
        print('SUCCESS!\n')
    else:
        print('FAIL :( \n')
        num_failed += 1

    # Test 2: (8.4, 1.2), (-7.3, 26)
    # Manhattan output value should be 40.5
    actual = manhattan(8.4, 1.2, -7.3, 26)
    expected = 40.5
    print('Input ((8.4, 1.2), (-7.3, 26)).\n'
          'Expected result', expected, 'and actual result =', actual)
    if absolute(actual - expected) < EPSILON:
        print('SUCCESS!\n')
    else:
        print('FAIL :( \n')
        num_failed += 1

    # Test 3: (-34, -23.9), (6.24, -54.138)
    # Manhattan output value should be 70.478
    actual = manhattan(-34, -23.9, 6.24, -54.138)
    expected = 70.478
    print('Input ((-34, -23.9), (6.24, -54.138)).\n'
          'Expected result', expected, 'and actual result =', actual)
    if absolute(actual - expected) < EPSILON:
        print('SUCCESS!\n')
    else:
        print('FAIL :( \n')
        num_failed += 1

    # Test 4: (1, 3), (1, 3)
    # Manhattan output value should be 0.0
    actual = manhattan(1, 3, 1, 3)
    expected = 0.0
    print('Input ((1, 3), (1, 3)).\n'
          'Expected result', expected, 'and actual result =', actual)
    if absolute(actual - expected) < EPSILON:
        print('SUCCESS!\n')
    else:
        print('FAIL :( \n')
        num_failed += 1

    # Test 5: (9.72, -45.8), (- 13.6, -67.2)
    # Manhattan output value should be 44.72
    actual = manhattan(9.72, -45.8, -13.6, -67.2)
    expected = 44.72
    print('Input ((9.72, -45.8), (- 13.6, -67.2)).\n'
          'Expected result', expected, 'and actual result =', actual)
    if absolute(actual - expected) < EPSILON:
        print('SUCCESS!\n')
    else:
        print('FAIL :( \n')
        num_failed += 1

    return num_failed
예제 #5
0
def test_absolute():
    ''' function test_absolute
        Input: none
        Returns: int, # of tests that failed
        Does: tests a few different inputs on absolute function, makes sure each absolute value output is as-expected.
    '''

    print('\n \n' 'Running Absolute Test')
    num_failed = 0

    # Test 1: -9
    # Absolute value should be 9.0
    actual = absolute(-9)
    expected = 9.0
    print('Input (-9).\n'
          'Expected result', expected, 'and actual result =', actual)
    if absolute(actual - expected) < EPSILON:
        print('SUCCESS!\n')
    else:
        print('FAIL :( \n')
        num_failed += 1

    # Test 2: 35
    # Absolute value should be 35.0
    actual = absolute(35)
    expected = 35.0
    print('Input (35).\n'
          'Expected result', expected, 'and actual result =', actual)
    if absolute(actual - expected) < EPSILON:
        print('SUCCESS!\n')
    else:
        print('FAIL :( \n')
        num_failed += 1

    # Test 3: -13.7
    # Absolute value should be 13.7
    actual = absolute(-13.7)
    expected = 13.7
    print('Input (-13.7).\n'
          'Expected result', expected, 'and actual result =', actual)
    if absolute(actual - expected) < EPSILON:
        print('SUCCESS!\n')
    else:
        print('FAIL :( \n')
        num_failed += 1

    # Test 4: 45.3
    # Absolute value should be 45.3
    actual = absolute(45.3)
    expected = 45.3
    print('Input (45.3).\n'
          'Expected result', expected, 'and actual result =', actual)
    if absolute(actual - expected) < EPSILON:
        print('SUCCESS!\n')
    else:
        print('FAIL :( \n')
        num_failed += 1

    # Test 5: 0
    # Absolute value should be 0
    actual = absolute(0)
    expected = 0
    print('Input (0).\n'
          'Expected result', expected, 'and actual result =', actual)
    if absolute(actual - expected) < EPSILON:
        print('SUCCESS!\n')
    else:
        print('FAIL :( \n')
        num_failed += 1

    return num_failed