def sort_array():

    """
    Sorts array

    Calls basic_list_exception.make_list. Converts integer list to integer array. Sorts array
    with a loop. Returns copy of sorted array list

    :return: return_list: copy of sorted array list
    """
    # Call for list and convert to array
    return_list = []
    fun_list = basic_list_exception.make_list()
    fun_array = arr('i', fun_list)

    # Sort array
    for x in range(0, len(fun_array)):
        for y in range(x+1, len(fun_array)):
            if fun_array[x] > fun_array[y]:
                temp = fun_array[x]
                fun_array[x] = fun_array[y]
                fun_array[y] = temp
        return_list.append(fun_array[x])

    # Returning a copy of the sorted array list because it satisfies the test. Return requirements
    # were not provided so I just returned a list.
    return return_list
Beispiel #2
0
def sort_list():
    """
    Sorts list

    Calls basic_list_exception.make_list(). The return is assigned variable name
    fun_list. Fun_list is sorted and returned.

    :return: fun_list: sorted list
    """
    fun_list = basic_list_exception.make_list()
    fun_list.sort()
    return fun_list
Beispiel #3
0
def search_list(search):
    """
    Returns the index of the desired list item

    Calls basic_list_exception.make_list(). This return is assigned variable name
    fun_list. Parameter 'search' is searched for in fun_list and the index returned.
    An invalid search will return -1. This function will only return the first occurrence
    of the desired item. Multiple occurrences are not accounted for.


    :param search: integer to search for
    :return: location: integer index of desired search in fun_list
    """
    fun_list = basic_list_exception.make_list()
    for x in range(len(fun_list)):
        try:
            location = fun_list.index(search)
            return location
        except ValueError:
            return -1
def search_array(search):

    """
    Searches array for value and returns index

    Calls basic_list.make_list() and accepts list return. Converts list to
    signed integer array. Takes param search and returns index or -1
    if not found.


    :param search: integer to search for
    :return: search_index: integer index of search
    """
    # Call for list
    fun_list = basic_list_exception.make_list()
    fun_array = arr('i', fun_list)

    # Search for index of search value
    try:
        search_index = fun_array.index(search)
        print(str(search) + ' is at ' + str(search_index))
        return search_index
    except ValueError:
        return -1
Beispiel #5
0
 def test_make_list_above_50(self, input):
     with self.assertRaises(ValueError):
         list.make_list()
Beispiel #6
0
 def test_make_list_below_1(self, input):
     with self.assertRaises(ValueError):
         list.make_list()
 def test_make_list_above_range(self, input):
     with self.assertRaises(ValueError):  # Above 50
         topic1.make_list()
 def test_make_list_above_range(self, input):  # pass input
     with self.assertRaises(ValueError):  # this is familiar
         basic_list_exception.make_list()  # call the function!
 def test_make_list_above_range(self, input):
     with self.assertRaises(ValueError):
         basic_list_exception.make_list()
Beispiel #10
0
def search_list(item):
    list_to_search = topic1.make_list()
    try:
        return list_to_search.index(item)
    except ValueError as err:
        return -1
Beispiel #11
0
 def test_make_list_non_numeric(self, input):
     basic_list_exception.make_list()
Beispiel #12
0
 def test_make_list_above_range(self, input):
     with self.assertRaises(ValueError):
         ble.make_list()
 def test_make_list(self, input):
     self.assertEqual(topic1.make_list(), [6, 6, 6])
 def test_make_list(self, input):
     self.assertEqual(basic_list_exception.make_list(input), [6, 89, -9])
 def test_make_list_non_numeric(self, input):
     with self.assertRaises(ValueError):
         basic_list_exception.make_list()
 def test_something(self, input):
     self.assertEqual(topic1.make_list(), [5, 5, 5])
Beispiel #17
0
 def test_make_list_non_numeric(self, input):  # pass input
     with self.assertRaises(ValueError):  # this is familiar
         make_list()  # call the function!
Beispiel #18
0
 def test_make_list(self, input):
     self.assertEqual(make_list(), [5, 5, 5])
 def test_make_list_below_range(self, input):
     with self.assertRaises(ValueError):
         topic1.make_list()
 def test_make_list_non_numeric(self, input):  # pass input
     with self.assertRaises(ValueError):  # this is familiar
         basic_list_exception.make_list()
Beispiel #21
0
 def test_make_list_non_numeric(self, input):
     with self.assertRaises(ValueError):
         ble.make_list()
 def test_make_list_below_range(self, input):  # pass input
     with self.assertRaises(ValueError):  # this is familiar
         basic_list_exception.make_list()
import unittest
from fun_with_collections.sort_and_search_list import search_list
from fun_with_collections.sort_and_search_list import sort_list
from fun_with_collections.basic_list_exception import make_list


class MyTestCase(unittest.TestCase):
    def test_item_found(self):
        self.assertEqual(search_list(x, 1), 0)

    def test_item_not_found(self):
        self.assertEqual(search_list(x, 66), -1)

    def test_sort_list(self):
        self.assertEqual(sort_list(x), [1, 4, 6])


x = make_list()
if __name__ == '__main__':
    unittest.main()
 def test_make_list_non_numeric(self, input):                        # pass input
     with self.assertRaises(ValueError):                             # this is familiar
         topic1.make_list()
Beispiel #25
0
def sort_list():
    list_to_sort = topic1.make_list()
    list_to_sort.sort()
    return list_to_sort
 def test_make_list_below_range(self, input):
     with self.assertRaises(ValueError):  #when list is less than 1
         topic1.make_list()
 def test_make_list_in_range(selfself, input):
     basic_list_exception.make_list()
 def test_make_list_above_range(self, input):
     with self.assertRaises(ValueError):  #when list is greater than 50
         topic1.make_list()
 def test_make_list(self, input):
     self.assertEqual(basic_list_exception.make_list(), [5, 5, 5])
 def test_make_list_within_range(self, input):
     self.assertEqual([25, 25, 25], basic_list_exception.make_list())