コード例 #1
0
 def test_listsSetIndex_InsertFirst(self):
     items = ['a', 'b', 'c', 'd']
     BlocklyMethods.listsSetIndex(items, 'insert', 'A', 'first')
     self.assertEqual(['A', 'a', 'b', 'c', 'd'], items)
コード例 #2
0
def run():
    global item, item2, item8, item7, item9, item4, item3, item10, item6, item5
    BlocklyMethods.listsSetIndex(item, 'set', 0, 'from_start', 0)
    BlocklyMethods.listsSetIndex(item, 'set', 0, 'from_end', 0)
    BlocklyMethods.listsSetIndex(item, 'set', 0, 'first')
    BlocklyMethods.listsSetIndex(item, 'set', 0, 'last')
    BlocklyMethods.listsSetIndex(item, 'set', 0, 'random')
    BlocklyMethods.listsSetIndex(item, 'insert', 0, 'from_start', 0)
    BlocklyMethods.listsSetIndex(item, 'insert', 0, 'from_end', 0)
    BlocklyMethods.listsSetIndex(item, 'insert', 0, 'first')
    BlocklyMethods.listsSetIndex(item, 'insert', 0, 'last')
    BlocklyMethods.listsSetIndex(item, 'insert', 0, 'random')
    BlocklyMethods.listsSetIndex(item2, 'set', True, 'from_start', 0)
    BlocklyMethods.listsSetIndex(item2, 'set', True, 'from_end', 0)
    BlocklyMethods.listsSetIndex(item2, 'set', True, 'first')
    BlocklyMethods.listsSetIndex(item2, 'set', True, 'last')
    BlocklyMethods.listsSetIndex(item2, 'set', True, 'random')
    BlocklyMethods.listsSetIndex(item2, 'insert', True, 'from_start', 0)
    BlocklyMethods.listsSetIndex(item2, 'insert', True, 'from_end', 0)
    BlocklyMethods.listsSetIndex(item2, 'insert', True, 'first')
    BlocklyMethods.listsSetIndex(item2, 'insert', True, 'last')
    BlocklyMethods.listsSetIndex(item2, 'insert', True, 'random')
    BlocklyMethods.listsSetIndex(item3, 'set', "123", 'from_start', 0)
    BlocklyMethods.listsSetIndex(item3, 'set', "123", 'from_end', 0)
    BlocklyMethods.listsSetIndex(item3, 'set', "123", 'first')
    BlocklyMethods.listsSetIndex(item3, 'set', "123", 'last')
    BlocklyMethods.listsSetIndex(item3, 'set', "123", 'random')
    BlocklyMethods.listsSetIndex(item3, 'insert', "123", 'from_start', 0)
    BlocklyMethods.listsSetIndex(item3, 'insert', "123", 'from_end', 0)
    BlocklyMethods.listsSetIndex(item3, 'insert', "123", 'first')
    BlocklyMethods.listsSetIndex(item3, 'insert', "123", 'last')
    BlocklyMethods.listsSetIndex(item3, 'insert', "123", 'random')
    BlocklyMethods.listsSetIndex(item4, 'set', 'black', 'from_start', 0)
    BlocklyMethods.listsSetIndex(item4, 'set', 'black', 'from_end', 0)
    BlocklyMethods.listsSetIndex(item4, 'set', 'black', 'first')
    BlocklyMethods.listsSetIndex(item4, 'set', 'black', 'last')
    BlocklyMethods.listsSetIndex(item4, 'set', 'black', 'random')
    BlocklyMethods.listsSetIndex(item4, 'insert', 'black', 'from_start', 0)
    BlocklyMethods.listsSetIndex(item4, 'insert', 'black', 'from_end', 0)
    BlocklyMethods.listsSetIndex(item4, 'insert', 'black', 'first')
    BlocklyMethods.listsSetIndex(item4, 'insert', 'black', 'last')
    BlocklyMethods.listsSetIndex(item4, 'insert', 'black', 'random')
    BlocklyMethods.listsSetIndex(item5, 'set', hal.waitForConnection(),
                                 'from_start', 0)
    BlocklyMethods.listsSetIndex(item5, 'set', hal.waitForConnection(),
                                 'from_end', 0)
    BlocklyMethods.listsSetIndex(item5, 'set', hal.waitForConnection(),
                                 'first')
    BlocklyMethods.listsSetIndex(item5, 'set', hal.waitForConnection(), 'last')
    BlocklyMethods.listsSetIndex(item5, 'set', hal.waitForConnection(),
                                 'random')
    BlocklyMethods.listsSetIndex(item5, 'insert', hal.waitForConnection(),
                                 'from_start', 0)
    BlocklyMethods.listsSetIndex(item5, 'insert', hal.waitForConnection(),
                                 'from_end', 0)
    BlocklyMethods.listsSetIndex(item5, 'insert', hal.waitForConnection(),
                                 'first')
    BlocklyMethods.listsSetIndex(item5, 'insert', hal.waitForConnection(),
                                 'last')
    BlocklyMethods.listsSetIndex(item5, 'insert', hal.waitForConnection(),
                                 'random')
コード例 #3
0
 def test_listsGetIndex_RemoveLast(self):
     items = ['a', 'b', 'c', 'd']
     BlocklyMethods.listsGetIndex(items, 'remove', 'last')
     self.assertEqual(['a', 'b', 'c'], items)
コード例 #4
0
 def test_listsSetIndex_SetRandom(self):
     items = ['a', 'b', 'c', 'd']
     BlocklyMethods.listsSetIndex(items, 'set', 'A', 'random')
     self.assertNotEqual(['a', 'b', 'c', 'd'], items)
     self.assertIn('A', items)
コード例 #5
0
 def test_listsGetSubList_Last(self):
     sub = BlocklyMethods.listsGetSubList(['a', 'b', 'c', 'd'], 'last', None, 'last', None)
     self.assertEqual(['d'], sub)
コード例 #6
0
 def test_findLast_Found(self):
     res = BlocklyMethods.findLast(['a', 'b', 'b', 'c'], 'b')
     self.assertEqual(2, res)
コード例 #7
0
 def test_standardDeviatioin(self):
     items = [0, 8, 4, 10]
     res = BlocklyMethods.standardDeviatioin(items)
     self.assertAlmostEqual(2.6809513, res)
コード例 #8
0
 def test_listsGetSubList_FromStart(self):
     sub = BlocklyMethods.listsGetSubList(['a', 'b', 'c', 'd'], 'from_start', 1, 'from_start', 2)
     self.assertEqual(['b', 'c'], sub)
コード例 #9
0
 def test_averageOnList(self):
     items = [0, 8, 4, 10]
     res = BlocklyMethods.averageOnList(items)
     self.assertEqual(5.5, res)
コード例 #10
0
 def test_medianOnList(self):
     items = [0, 8, 4, 10]
     res = BlocklyMethods.medianOnList(items)
     self.assertEqual(6.0, res)
コード例 #11
0
def run():
    global item, item2, item7, item4, item3, item6, item5
    item6 = BlocklyMethods.length( item)
    item6 = BlocklyMethods.length( item2)
    item6 = BlocklyMethods.length( item3)
    item6 = BlocklyMethods.length( item4)
    item6 = BlocklyMethods.length( item5)
    item7 = BlocklyMethods.isEmpty( item)
    item7 = BlocklyMethods.isEmpty( item2)
    item7 = BlocklyMethods.isEmpty( item3)
    item7 = BlocklyMethods.isEmpty( item4)
    item7 = BlocklyMethods.isEmpty( item5)
    item6 = BlocklyMethods.sumOnList(item)
    item6 = BlocklyMethods.minOnList(item)
    item6 = BlocklyMethods.maxOnList(item)
    item6 = BlocklyMethods.averageOnList(item)
    item6 = BlocklyMethods.medianOnList(item)
    item6 = BlocklyMethods.standardDeviatioin(item)
    item6 = BlocklyMethods.randOnList(item)
コード例 #12
0
import math

class BreakOutOfALoop(Exception): pass
class ContinueLoop(Exception): pass

_brickConfiguration = {
    'wheel-diameter': 5.6,
    'track-width': 18.0,
    'actors': {
    },
    'sensors': {
    },
}
hal = Hal(_brickConfiguration)

item = BlocklyMethods.createListWith(0, 0, 0)
item2 = BlocklyMethods.createListWith(True, True, True)
item3 = BlocklyMethods.createListWith("", "", "")
item4 = BlocklyMethods.createListWith('white', 'white', 'white')
item5 = BlocklyMethods.createListWith(None, None, None)
item6 = 0
item7 = True
def run():
    global item, item2, item7, item4, item3, item6, item5
    item6 = BlocklyMethods.length( item)
    item6 = BlocklyMethods.length( item2)
    item6 = BlocklyMethods.length( item3)
    item6 = BlocklyMethods.length( item4)
    item6 = BlocklyMethods.length( item5)
    item7 = BlocklyMethods.isEmpty( item)
    item7 = BlocklyMethods.isEmpty( item2)
コード例 #13
0
def run():
    global item, item2, item7, item4, item3, item6, item5
    item = BlocklyMethods.createListWithItem(0, 5)
    item2 = BlocklyMethods.createListWithItem(True, 5)
    item3 = BlocklyMethods.createListWithItem("", 5)
    item4 = BlocklyMethods.createListWithItem('white', 5)
    item5 = BlocklyMethods.createListWithItem(hal.waitForConnection(), 5)
    item = BlocklyMethods.listsGetSubList(item, 'from_start', 0, 'from_start',
                                          0)
    item2 = BlocklyMethods.listsGetSubList(item2, 'from_start', 0,
                                           'from_start', 0)
    item3 = BlocklyMethods.listsGetSubList(item3, 'from_start', 0,
                                           'from_start', 0)
    item4 = BlocklyMethods.listsGetSubList(item4, 'from_start', 0,
                                           'from_start', 0)
    item5 = BlocklyMethods.listsGetSubList(item5, 'from_start', 0,
                                           'from_start', 0)
    item6 = BlocklyMethods.findFirst(item, 0)
    item6 = BlocklyMethods.findFirst(item2, True)
    item6 = BlocklyMethods.findFirst(item3, "")
    item6 = BlocklyMethods.findFirst(item4, 'white')
    item6 = BlocklyMethods.findFirst(item5, hal.waitForConnection())
    item6 = BlocklyMethods.findLast(item, 0)
    item6 = BlocklyMethods.findLast(item2, True)
    item6 = BlocklyMethods.findLast(item3, "")
    item6 = BlocklyMethods.findLast(item4, 'white')
    item6 = BlocklyMethods.findLast(item5, hal.waitForConnection())
コード例 #14
0
 def test_createListWith(self):
     self.assertEqual(['x', 'yz'], BlocklyMethods.createListWith('x', 'yz'))
コード例 #15
0
 def test_randOnList(self):
     items = ['a', 'b', 'c', 'd']
     res = BlocklyMethods.randOnList(items)
     self.assertIn(res, items)
コード例 #16
0
 def test_createListWithItem(self):
     self.assertEqual(['x', 'x'], BlocklyMethods.createListWithItem('x', 2))
コード例 #17
0
 def test_modeOnList_all(self):
     items = ['a', 'b', 'c', 'd']
     res = BlocklyMethods.modeOnList(items)
     self.assertEqual(items, res)
コード例 #18
0
 def test_listsGetSubList_FromEnd(self):
     sub = BlocklyMethods.listsGetSubList(['a', 'b', 'c', 'd'], 'from_end', 2, 'from_end', 1)
     self.assertEqual(['b', 'c'], sub)
コード例 #19
0
 def test_modeOnList_One(self):
     items = ['a', 'b', 'a', 'd']
     res = BlocklyMethods.modeOnList(items)
     self.assertEqual(['a'], res)
コード例 #20
0
 def test_findLast_NotFound(self):
     res = BlocklyMethods.findLast(['a', 'b', 'b', 'd'], 'x')
     self.assertEqual(-1, res)
コード例 #21
0
 def test_textJoin_EmptyList(self):
     self.assertEqual("", BlocklyMethods.textJoin())
コード例 #22
0
 def test_listsGetIndex_GetFirst(self):
     res = BlocklyMethods.listsGetIndex(['a', 'b', 'c', 'd'], 'get', 'first')
     self.assertEqual('a', res)
コード例 #23
0
 def test_textJoin_Single(self):
     self.assertEqual("x", BlocklyMethods.textJoin('x'))
コード例 #24
0
 def test_listsGetIndex_GetFromStart(self):
     res = BlocklyMethods.listsGetIndex(['a', 'b', 'c', 'd'], 'get', 'from_start', 1)
     self.assertEqual('b', res)
コード例 #25
0
 def test_textJoin_Three(self):
     self.assertEqual("xyz", BlocklyMethods.textJoin('x', 'yz'))
コード例 #26
0
 def test_randInt(self):
     v = BlocklyMethods.randInt(5, 10)
     self.assertGreaterEqual(v, 5)
     self.assertLessEqual(v, 10)
コード例 #27
0
 def test_length(self):
     self.assertEqual(2, BlocklyMethods.length(['x', 'yz']))
コード例 #28
0
 def test_listsSetIndex_InsertFromStart(self):
     items = ['a', 'b', 'c', 'd']
     BlocklyMethods.listsSetIndex(items, 'insert', 'A', 'from_start', 1)
     self.assertEqual(['a', 'A', 'b', 'c', 'd'], items)
コード例 #29
0
def run():
    global item, item2, item8, item7, item9, item4, item3, item10, item6, item5
    item6 = BlocklyMethods.listsGetIndex(item, 'get', 'from_start', 0)
    item6 = BlocklyMethods.listsGetIndex(item, 'get', 'from_end', 0)
    item6 = BlocklyMethods.listsGetIndex(item, 'get', 'first')
    item6 = BlocklyMethods.listsGetIndex(item, 'get', 'last')
    item6 = BlocklyMethods.listsGetIndex(item, 'get', 'random')
    item6 = BlocklyMethods.listsGetIndex(item, 'get_remove', 'from_start', 0)
    item6 = BlocklyMethods.listsGetIndex(item, 'get_remove', 'from_end', 0)
    item6 = BlocklyMethods.listsGetIndex(item, 'get_remove', 'first')
    item6 = BlocklyMethods.listsGetIndex(item, 'get_remove', 'last')
    item6 = BlocklyMethods.listsGetIndex(item, 'get_remove', 'random')
    BlocklyMethods.listsGetIndex(item, 'remove', 'from_start', 0)
    BlocklyMethods.listsGetIndex(item, 'remove', 'from_end', 0)
    BlocklyMethods.listsGetIndex(item, 'remove', 'first')
    BlocklyMethods.listsGetIndex(item, 'remove', 'last')
    BlocklyMethods.listsGetIndex(item, 'remove', 'random')
    item7 = BlocklyMethods.listsGetIndex(item2, 'get', 'from_start', 0)
    item7 = BlocklyMethods.listsGetIndex(item2, 'get', 'from_end', 0)
    item7 = BlocklyMethods.listsGetIndex(item2, 'get', 'first')
    item7 = BlocklyMethods.listsGetIndex(item2, 'get', 'last')
    item7 = BlocklyMethods.listsGetIndex(item2, 'get', 'random')
    item7 = BlocklyMethods.listsGetIndex(item2, 'get_remove', 'from_start', 0)
    item7 = BlocklyMethods.listsGetIndex(item2, 'get_remove', 'from_end', 0)
    item7 = BlocklyMethods.listsGetIndex(item2, 'get_remove', 'first')
    item7 = BlocklyMethods.listsGetIndex(item2, 'get_remove', 'last')
    item7 = BlocklyMethods.listsGetIndex(item2, 'get_remove', 'random')
    BlocklyMethods.listsGetIndex(item2, 'remove', 'from_start', 0)
    BlocklyMethods.listsGetIndex(item2, 'remove', 'from_end', 0)
    BlocklyMethods.listsGetIndex(item2, 'remove', 'first')
    BlocklyMethods.listsGetIndex(item2, 'remove', 'last')
    BlocklyMethods.listsGetIndex(item2, 'remove', 'random')
    item8 = BlocklyMethods.listsGetIndex(item3, 'get', 'from_start', 0)
    item8 = BlocklyMethods.listsGetIndex(item3, 'get', 'from_end', 0)
    item8 = BlocklyMethods.listsGetIndex(item3, 'get', 'first')
    item8 = BlocklyMethods.listsGetIndex(item3, 'get', 'last')
    item8 = BlocklyMethods.listsGetIndex(item3, 'get', 'random')
    item8 = BlocklyMethods.listsGetIndex(item3, 'get_remove', 'from_start', 0)
    item8 = BlocklyMethods.listsGetIndex(item3, 'get_remove', 'from_end', 0)
    item8 = BlocklyMethods.listsGetIndex(item3, 'get_remove', 'first')
    item8 = BlocklyMethods.listsGetIndex(item3, 'get_remove', 'last')
    item8 = BlocklyMethods.listsGetIndex(item3, 'get_remove', 'random')
    BlocklyMethods.listsGetIndex(item3, 'remove', 'from_start', 0)
    BlocklyMethods.listsGetIndex(item3, 'remove', 'from_end', 0)
    BlocklyMethods.listsGetIndex(item3, 'remove', 'first')
    BlocklyMethods.listsGetIndex(item3, 'remove', 'last')
    BlocklyMethods.listsGetIndex(item3, 'remove', 'random')
    item9 = BlocklyMethods.listsGetIndex(item4, 'get', 'from_start', 0)
    item9 = BlocklyMethods.listsGetIndex(item4, 'get', 'from_end', 0)
    item9 = BlocklyMethods.listsGetIndex(item4, 'get', 'first')
    item9 = BlocklyMethods.listsGetIndex(item4, 'get', 'last')
    item9 = BlocklyMethods.listsGetIndex(item4, 'get', 'random')
    item9 = BlocklyMethods.listsGetIndex(item4, 'get_remove', 'from_start', 0)
    item9 = BlocklyMethods.listsGetIndex(item4, 'get_remove', 'from_end', 0)
    item9 = BlocklyMethods.listsGetIndex(item4, 'get_remove', 'first')
    item9 = BlocklyMethods.listsGetIndex(item4, 'get_remove', 'last')
    item9 = BlocklyMethods.listsGetIndex(item4, 'get_remove', 'random')
    BlocklyMethods.listsGetIndex(item4, 'remove', 'from_start', 0)
    BlocklyMethods.listsGetIndex(item4, 'remove', 'from_end', 0)
    BlocklyMethods.listsGetIndex(item4, 'remove', 'first')
    BlocklyMethods.listsGetIndex(item4, 'remove', 'last')
    BlocklyMethods.listsGetIndex(item4, 'remove', 'random')
    item10 = BlocklyMethods.listsGetIndex(item5, 'get', 'from_start', 0)
    item10 = BlocklyMethods.listsGetIndex(item5, 'get', 'from_end', 0)
    item10 = BlocklyMethods.listsGetIndex(item5, 'get', 'first')
    item10 = BlocklyMethods.listsGetIndex(item5, 'get', 'last')
    item10 = BlocklyMethods.listsGetIndex(item5, 'get', 'random')
    item10 = BlocklyMethods.listsGetIndex(item5, 'get_remove', 'from_start', 0)
    item10 = BlocklyMethods.listsGetIndex(item5, 'get_remove', 'from_end', 0)
    item10 = BlocklyMethods.listsGetIndex(item5, 'get_remove', 'first')
    item10 = BlocklyMethods.listsGetIndex(item5, 'get_remove', 'last')
    item10 = BlocklyMethods.listsGetIndex(item5, 'get_remove', 'random')
    BlocklyMethods.listsGetIndex(item5, 'remove', 'from_start', 0)
    BlocklyMethods.listsGetIndex(item5, 'remove', 'from_end', 0)
    BlocklyMethods.listsGetIndex(item5, 'remove', 'first')
    BlocklyMethods.listsGetIndex(item5, 'remove', 'last')
    BlocklyMethods.listsGetIndex(item5, 'remove', 'random')