def test_contains(alist: list):
    from_list = MyList(list(alist))
    from_alist = MyList(alist)
    from_mylist = MyList(MyList(alist))
    for element in alist:
        assert element in from_alist
        assert element in from_list
        assert element in from_mylist
    for idx, element in enumerate(alist):
        assert element == from_alist[idx]
        assert element == from_list[idx]
        assert element == from_mylist[idx]
Example #2
0
def test_max_diff():
    from mylist import MyList
    test_input_list = [[10, 8, 5, 17, 16], [2, -7, 1.5]]
    test_output_value = [12, 9]
    for n, t in enumerate(test_input_list):
        test = MyList(test_input_list[n])
        assert test.output_max_diff == test_output_value[n]

    with pytest.raises(ImportError):  # Test ImportError?
        import scipy
    with pytest.raises(TypeError):  # Type error when None inputted
        MyList()
        MyList(['sing'])
    with pytest.raises(ValueError):  # ValueError can occur when only 1 # given
        max([])  # This is where it fails in return_max_difference
Example #3
0
def test_min_max():
    from mylist import MyList
    test_input_list = [[-1, 5, 8, 100], [5, -8, 9, 45, 88, 34, 65],
                       [-5, 8.234, -99023, 342, 9.452]]
    test_output_values = ((100, -1), (88, -8), (342, -99023))

    for count, elem in enumerate(test_input_list):
        test = MyList(test_input_list[count])
        assert test.output_min_max == test_output_values[count]
        assert isinstance(test.output_min_max, tuple)  # should be true

    with pytest.raises(TypeError):
        MyList(['string', 'why'])
    with pytest.raises(ValueError):
        MyList([])
Example #4
0
 def post(self):
         self.response.headers['Content-Type'] = 'text/html'
         user = users.get_current_user()
         newword = self.request.get('addword')
         lexico_order=''.join(sorted(set(newword)))
         userid=users.get_current_user().email()
         userid = hashlib.sha1('%s' % (userid)).hexdigest()
         key = ndb.Key('MyList', lexico_order+userid)
         my_list = key.get()
         if my_list==None:
             my_list=MyList(id=lexico_order+userid)
             my_list.put()
         key = ndb.Key('MyList', lexico_order+userid)
         my_list = key.get()
         action=self.request.get('button')
         if action == 'Submit':
             string = self.request.get('addword')
             if string == None or string == '':
                 self.redirect('/')
                 return
             my_list.list_of_words.append(newword)
             my_list.lexicographical=lexico_order
             my_list.word_count=len(my_list.list_of_words)
             my_list.letter_count=len(my_list.lexicographical)
             my_list.user_id=userid
         my_list.put()
         self.redirect('/add')
Example #5
0
 def post(self):
     self.response.headers['Content-Type'] = 'text/html'
     user = users.get_current_user()
     string = self.request.get('input')
     string7 = ''.join(k for k, g in groupby(sorted(string)))
     emailsample = users.get_current_user().email()
     key = ndb.Key('MyList', string7 + emailsample)
     my_list = key.get()
     if my_list == None:
         my_list = MyList(id=string7 + emailsample)
         my_list.put()
     key = ndb.Key('MyList', string7 + emailsample)
     my_list = key.get()
     action = self.request.get('button')
     if action == 'add':
         string = self.request.get('input')
         if string == None or string == '':
             self.redirect('/')
             return
         my_list.strings.append(string)
         my_list.lexographical = string7
         my_list.wordcount = len(my_list.strings)
         my_list.lettercount = len(my_list.lexographical)
         my_list.email = emailsample
     my_list.put()
     self.redirect('/add')
Example #6
0
def start():
    try:
        mlist = MyList()
        mlist.fill_list()

        for value in mlist.mylist:
            print value

        mlist.mylist.append(60)
        if 60 in mlist.mylist:
            end("This is over!")
    except MyListError as lerr:
        print lerr
Example #7
0
def test_sum():
    from mylist import MyList
    list1 = MyList([1, 3, 5, 7, 9])
    list2 = MyList([-2, -5, -6, -1])
    list3 = MyList([4, -6, 9, -1])
    list4 = MyList([2.2, 5.1, 9.1, 1.2])
    list5 = MyList([-1.1, -5.2, -1.4, -3.8])
    list6 = MyList([-1.1, 2.2, -3.1])
    assert list1.output_sum == 25
    assert list2.output_sum == -14
    assert list3.output_sum == 6
    assert list4.output_sum == pytest.approx(17.6)
    assert list5.output_sum == pytest.approx(-11.5)
    assert list6.output_sum == pytest.approx(-2)
    with pytest.raises(TypeError):
        np.sum(['hello', 'hi'])
    with pytest.raises(ValueError):
        MyList([])
Example #8
0
 def post(self):
     self.response.headers['Content-Type'] = 'text/html'
     user = users.get_current_user().email()
     textfile = self.request.get("myFile")
     textfile = textfile.split()
     for x in textfile:
         line = ''.join(k for k, g in groupby(sorted(x)))
         key = ndb.Key('MyList', line + user)
         my_list = key.get()
         if my_list == None:
             my_list = MyList(id=line + user)
             my_list.put()
         key = ndb.Key('MyList', line + user)
         my_list = key.get()
         my_list.strings.append(x)
         my_list.lexographical = line
         my_list.wordcount = len(my_list.strings)
         my_list.lettercount = len(my_list.lexographical)
         my_list.email = user
         my_list.put()
     self.redirect('/')
Example #9
0
 def post(self):
     self.response.headers['Content-Type'] = 'text/html'
     userid = users.get_current_user().email()
     userid = hashlib.sha1('%s' % (userid)).hexdigest()
     textfile = self.request.get("myFile")
     textfile = textfile.split()
     for x in textfile:
         line=''.join(sorted(set(x)))
         key = ndb.Key('MyList', line+userid)
         my_list = key.get()
         if my_list==None:
             my_list=MyList(id=line+userid)
             my_list.put()
         key = ndb.Key('MyList', line+userid)
         my_list = key.get()
         my_list.list_of_words.append(x)
         my_list.lexicographical=line
         my_list.word_count=len(my_list.list_of_words)
         my_list.letter_count=len(my_list.lexicographical)
         my_list.user_id=userid
         my_list.put()
     self.redirect('/')
Example #10
0
from drone import Drone
from robot import Robot
from mylist import MyList

def execute(robot):
    try:
        lista.append(robot.detect_object("red"))
        if lista[0][2] >   300:
            robot.move("forward", 1)
        
    except KeyboardInterrupt:
        raise

if __name__ == '__main__':
    mylist=MyList()
    if len(sys.argv) == 2:
        path = os.getcwd()
        open_path = path[:path.rfind('src')] + 'cfg/'
        filename = sys.argv[1]

    else:
        sys.exit("ERROR: Example:python my_generated_script.py cfgfile.yml")

    # loading the ICE and ROS parameters
    cfg = config.load(open_path + filename)
    stream = open(open_path + filename, "r")
    yml_file = yaml.load(stream)

    for section in yml_file:
        if section == 'drone':
Example #11
0
import pytest

sys.path.append('.')
from mylist import MyList

lists = [
    [1, 2, 3, 4],
    [4, 3, 2, 1],
    ['a', 'b', 'c', 'd'],
    [1, 2, 'a', 'b']]

lists_ids = [str(element) for element in lists]

alist = lists[0]
from_list = MyList(list(alist))
from_alist = MyList(alist)
from_mylist = MyList(MyList(alist))


def test_repr():
    assert str(from_alist) == str(from_alist.data)
    assert str(from_mylist) == str(from_mylist.data)
    assert str(from_list) == str(from_list.data)


def test_init():
    assert type(from_mylist.data) == type(from_list.data)
    assert from_mylist.data == from_list.data
    assert from_mylist.data == from_alist.data