def test_concat(self): first = orange.StringList("abcde") second = orange.StringList("abcde") empty = orange.StringList() self.assertEqual(first + second, "abcdeabcde") self.assertEqual(first + first, "abcdeabcde") self.assertEqual(first + "", "abcde")
def test_insert(self): r = list("abcde") self.l.insert(0, "x") r.insert(0, "x") self.assertEqual(self.l, r) self.l.insert(2, "y") r.insert(2, "y") self.assertEqual(self.l, r) r.insert(7, "z") self.l.insert(7, "z") self.assertEqual(self.l, r) self.l.insert(-2, "u") r.insert(-2, "u") self.assertEqual(self.l, r) self.l.insert(-20, "v") r.insert(-20, "v") self.assertEqual(self.l, r) self.l.insert(20, "w") r.insert(20, "w") self.assertEqual(self.l, r) empty = orange.StringList() empty.insert(0, "a") self.assertEqual(empty, "a") empty = orange.StringList() empty.insert(10, "a") self.assertEqual(empty, "a") empty = orange.StringList() empty.insert(-10, "a") self.assertEqual(empty, "a")
def test_slice_and_cmp(self): self.assertEqual(self.l[1:3], "bc") self.assertGreater(self.l[1:3], "ab") self.assertGreater(self.l[2:5], orange.StringList("ab")) self.assertGreater(self.l[2:5], orange.StringList()) with self.assertRaises(TypeError): self.assertGreater(self.l[2:5], orange.IntList([1, 2]))
def test_sort(self): import random r = [chr(random.randint(65, 90)) for i in range(20)] l = orange.StringList(r) l.sort() r.sort() self.assertEqual(l, r)
def test_reverse(self): self.l.reverse() self.assertEqual(self.l, "edcba") empty = orange.StringList() empty.reverse() self.assertEqual(empty, []) self.assertFalse(empty)
def test_pop(self): self.assertEqual(self.l.pop(), "e") self.assertEqual(self.l, "abcd") l = orange.StringList("a") self.assertEqual(l.pop(), "a") self.assertFalse(l) with self.assertRaises(IndexError): l.pop()
def createExampleTable(self): # Create orange.ExampleTable datalabels = [] data = list(self.combiner.outputSlot) labels = list(self.labels()) for vec, label in zip(data, labels): datalabels.append(list(vec) + [str(label)]) domain = orange.Domain( [orange.FloatVariable('a%i' % x) for x in xrange(len(data[0]))] + [ orange.EnumVariable( "class", values=orange.StringList( [str(x) for x in self.labels().container.classes])) ]) print domain[50] orngTable = orange.ExampleTable(domain, datalabels) print orngTable.domain.classVar self.send("Table", orngTable)
def test_repeat(self): self.assertEqual(self.l * 3, "abcde" * 3) self.assertEqual(orange.StringList([]) * 3, [])
def test_empty(self): l = orange.StringList() self.assertEqual(len(l), 0) l = orange.StringList([]) self.assertEqual(len(l), 0)
def setUp(self): self.l = orange.StringList("abcde")