def test4(self): L = DictSet(s2d('a1 c5666788')) with self.assertRaises(TypeError) as cm: L.add('d', []) self.assertEqual(str(cm.exception), "unhashable type: 'list'")
def test99(self): """Make sure that direct calls to update do not clear previous contents""" L = DictSet(a='1', b='2') L.__init__(b='3', c='4') self.assertEqual(d2l(L), s2l('a1b23c4'))
def test1(self): L = DictSet(s2d('a1 c5678')) M=L.copy() M.add('d','9') R2 = s2l('a1 c5678 d9') self.assertEqual(d2l(M),R2)
def test1(self): L = DictSet(s2d('a1 c5678')) R1 = s2l('a1 c5678') M=L.fromkeys(['a','b'],'567') self.assertEqual(d2l(L),R1) self.assertEqual(d2l(M),s2l('a567b567'))
def test0(self): L = DictSet(s2d('a1 c5678')) R1 = s2l('a1 c5678') M=L.copy() M.add('d','9') self.assertEqual(d2l(L),R1)
def test99(self): """Make sure that direct calls to update do not clear previous contents""" L=DictSet(a='1',b='2') L.__init__(b='3',c='4') self.assertEqual(d2l(L),s2l('a1b23c4'))
def test1(self): L = DictSet(s2d('a12 c5666788 d0')) g = L.unique_combinations() self.assertEqual([v for v in g], [['1', '5'], ['1', '6'], ['1', '7'], ['1', '8'], ['2', '5'], ['2', '6'], ['2', '7'], ['2', '8']])
def test1(self): L = DictSet(s2d('a1 c5678')) M = L.copy() M.add('d', '9') R2 = s2l('a1 c5678 d9') self.assertEqual(d2l(M), R2)
def test1(self): L = DictSet(s2d('a1 c5678')) R1 = s2l('a1 c5678') M = L.fromkeys(['a', 'b'], '567') self.assertEqual(d2l(L), R1) self.assertEqual(d2l(M), s2l('a567b567'))
def test0(self): L = DictSet(s2d('a1 c5678')) R1 = s2l('a1 c5678') M = L.fromkeys(['a', 'b']) self.assertEqual(d2l(L), R1) self.assertEqual(d2l(M), s2l('a0b0'))
def test2(self): L = DictSet(s2d('a12 c5666788 d12345')) g = L.unique_combinations(keys=['a', 'c']) self.assertEqual([v for v in g], [['1', '5'], ['1', '6'], ['1', '7'], ['1', '8'], ['2', '5'], ['2', '6'], ['2', '7'], ['2', '8']])
def test3(self): L = DictSet(s2d('a12 c5666788 d12345')) g = L.unique_combinations(keys=['c', 'a']) self.assertEqual([v for v in g], [['5', '1'], ['5', '2'], ['6', '1'], ['6', '2'], ['7', '1'], ['7', '2'], ['8', '1'], ['8', '2']])
def test0(self): L = DictSet(s2d('a1 c5678')) R1 = s2l('a1 c5678') M = L.copy() M.add('d', '9') self.assertEqual(d2l(L), R1)
def test0(self): L = DictSet(s2d('a1 c5678')) R1 = s2l('a1 c5678') M=L.fromkeys(['a','b']) self.assertEqual(d2l(L),R1) self.assertEqual(d2l(M),s2l('a0b0'))
def test4(self): L = DictSet(s2d('a1 c5666788')) with self.assertRaises(TypeError) as cm: L.add('d',[]) self.assertEqual(str(cm.exception), "unhashable type: 'list'")
def test7(self): L = DictSet(s2d('a123 b456')) L.remove('a') with self.assertRaises(KeyError) as cm: L.remove('a') self.assertEqual(str(cm.exception),"'a'")
def test4(self): L = DictSet(s2d('a12 c568 d123 e78')) g=L.unique_combinations() self.assertEqual(''.join([''.join(v) for v in g]), '151715181527152815371538161716181627162816371638' '181718181827182818371838251725182527252825372538' '261726182627262826372638281728182827282828372838')
def test0(self): L = DictSet(s2d('a1 c5666788')) R = s2l('a1 c56 7') with self.assertRaises(TypeError) as cm: L.__setitem__([], '8') self.assertEqual(str(cm.exception), "unhashable type: 'list'")
def test1(self): L = DictSet(s2d('a1 c5666788')) R = s2l('a1 c56 7') with self.assertRaises(TypeError) as cm: L.__setitem__('a', 42) self.assertEqual(str(cm.exception), "'int' object is not iterable")
def test3(self): L = DictSet(s2d('a123 b324')) M = s2d('a1 c5666788') R = s2l('a123 b324 c56 78') self.assertTrue(isinstance(L.union(M), DictSet)) self.assertEqual(d2l(L.union(M)), R) self.assertEqual(d2l(L), s2l('a123 b234')) self.assertEqual(d2l(M), s2l('a1 c5666788'))
def test2(self): L = DictSet(s2d('a1 c567889')) M = s2d('a123 b324 c5 78') R = s2l('a1 c5 78 ') self.assertTrue(isinstance(L.intersection(M),DictSet)) self.assertEqual(d2l(L.intersection(M)),R) self.assertEqual(d2l(L),s2l('a1 c56789')) self.assertEqual(d2l(M),s2l('a123 b324 c5 78'))
def test0(self): L = DictSet(s2d('a1 c5666788')) R = s2l('a1 c56 7') with self.assertRaises(TypeError) as cm: L.__setitem__([],'8') self.assertEqual(str(cm.exception), "unhashable type: 'list'")
def test3(self): L = DictSet(s2d('a123 b324 c5 78 d0')) M = s2d('a1 c56788 e0') R = s2l('a 23 b324 c 6') self.assertTrue(isinstance(L.symmetric_difference(M),DictSet)) self.assertEqual(d2l(L.symmetric_difference(M)),R) self.assertEqual(d2l(L),s2l('a123 b234 c5 78 d0')) self.assertEqual(d2l(M),s2l('a1 c56788 e0'))
def test2(self): L = DictSet(s2d('a1 c5666788')) R = s2l('a1 c56 7') L.remove('c','8') with self.assertRaises(KeyError) as cm: L.remove('d','8') self.assertEqual(str(cm.exception),"'d'")
def test1(self): L = DictSet(s2d('')) M = s2d('a1 c5666788 e0') R = s2l('a1 c56 78') self.assertTrue(isinstance(L.symmetric_difference(M),DictSet)) self.assertEqual(d2l(L.symmetric_difference(M)),R) self.assertEqual(d2l(L),s2l('')) self.assertEqual(d2l(M),s2l('a1 c5666788 e0'))
def test1(self): L = DictSet(s2d('a1 c5666788')) R = s2l('a1 c56 7') with self.assertRaises(TypeError) as cm: L.__setitem__('a',42) self.assertEqual(str(cm.exception), "'int' object is not iterable")
def test0(self): L = DictSet(s2d('a1 c5666788 e0')) M = s2d('') R = s2l('a1 c56 78') self.assertTrue(isinstance(L.symmetric_difference(M), DictSet)) self.assertEqual(d2l(L.symmetric_difference(M)), R) self.assertEqual(d2l(L), s2l('a1 c5678 e0')) self.assertEqual(d2l(M), s2l(''))
def test2(self): L = DictSet(s2d('a1 c567889')) M = s2d('a123 b324 c5 78') R = s2l('a1 c5 78 ') self.assertTrue(isinstance(L.intersection(M), DictSet)) self.assertEqual(d2l(L.intersection(M)), R) self.assertEqual(d2l(L), s2l('a1 c56789')) self.assertEqual(d2l(M), s2l('a123 b324 c5 78'))
def test3(self): L = DictSet(s2d('a123 b324 c5 78 d0')) M = s2d('a1 c56788 e0') R = s2l('a 23 b324 c 6') self.assertTrue(isinstance(L.symmetric_difference(M), DictSet)) self.assertEqual(d2l(L.symmetric_difference(M)), R) self.assertEqual(d2l(L), s2l('a123 b234 c5 78 d0')) self.assertEqual(d2l(M), s2l('a1 c56788 e0'))
def test2(self): L = DictSet(s2d('a1 c56788')) M = s2d('a123 b324 c5 78') R = s2l(' c 6') self.assertTrue(isinstance(L.difference(M),DictSet)) self.assertEqual(d2l(L.difference(M)),R) self.assertEqual(d2l(L),s2l('a1 c5678')) self.assertEqual(d2l(M),s2l('a123 b324 c5 78'))
def test3(self): L = DictSet(s2d('a123 b324')) M = s2d('a1 c5666788') R = s2l('a123 b324 c56 78') self.assertTrue(isinstance(L.union(M),DictSet)) self.assertEqual(d2l(L.union(M)),R) self.assertEqual(d2l(L),s2l('a123 b234')) self.assertEqual(d2l(M),s2l('a1 c5666788'))
def test4(self): L = DictSet(s2d('a12 c568 d123 e78')) g = L.unique_combinations() self.assertEqual( ''.join([''.join(v) for v in g]), '151715181527152815371538161716181627162816371638' '181718181827182818371838251725182527252825372538' '261726182627262826372638281728182827282828372838')
def test1(self): L = DictSet(s2d('')) M = s2d('a1 c5666788') R = s2l('') self.assertTrue(isinstance(L.difference(M), DictSet)) self.assertEqual(d2l(L.difference(M)), R) self.assertEqual(d2l(L), s2l('')) self.assertEqual(d2l(M), s2l('a1 c5666788'))
def test0(self): L = DictSet(s2d('a1 c5666788')) if sys.version_info[0]==2: R="DictSet([('a', set(['1'])), ('c', set(['5', '7', '6', '8']))])" elif sys.version_info[0]==3: R="DictSet([('a', {'1'}), ('c', {'5', '7', '6', '8'})])" self.assertEqual(L.__repr__(),R) self.assertEqual(d2l(eval(R)),d2l(L))
def test1(self): L = DictSet() if sys.version_info[0]==2: R="DictSet()" elif sys.version_info[0]==3: R="DictSet()" self.assertEqual(L.__repr__(),R) self.assertEqual(d2l(eval(R)),d2l(L))
def test3(self): L = DictSet(s2d('a123 b324 c5 78')) M = s2d('a1 c567889') R = s2l('a1 c5 78 ') L.intersection_update(M) self.assertTrue(isinstance(L, DictSet)) self.assertTrue(isinstance(M, dict)) self.assertEqual(d2l(L), R) # L is updated self.assertEqual(d2l(M), s2l('a1 c567889'))
def test1(self): L = DictSet() if sys.version_info[0] == 2: R = "DictSet()" elif sys.version_info[0] == 3: R = "DictSet()" self.assertEqual(L.__repr__(), R) self.assertEqual(d2l(eval(R)), d2l(L))
def test0(self): L = DictSet(s2d('a1 c5666788')) if sys.version_info[0] == 2: R = "DictSet([('a', set(['1'])), ('c', set(['5', '7', '6', '8']))])" elif sys.version_info[0] == 3: R = "DictSet([('a', {'1'}), ('c', {'5', '7', '6', '8'})])" self.assertEqual(L.__repr__(), R) self.assertEqual(d2l(eval(R)), d2l(L))
def test2(self): L = DictSet(s2d('a1 c5666788')) M = s2d('a123 b324') R = s2l('a123 b324 c56 78') L.update(M) self.assertTrue(isinstance(L, DictSet)) self.assertTrue(isinstance(M, dict)) self.assertEqual(d2l(L), R) # L is updated self.assertEqual(d2l(M), s2l('a123 b324'))
def test3(self): L = DictSet(s2d('a123 b324 c5 78')) M = s2d('a1 c567889') R = s2l('a1 c5 78 ') L.intersection_update(M) self.assertTrue(isinstance(L,DictSet)) self.assertTrue(isinstance(M,dict)) self.assertEqual(d2l(L),R) # L is updated self.assertEqual(d2l(M),s2l('a1 c567889'))
def test3(self): L = DictSet(s2d('a123 b324 c5 78')) M = s2d('a1 c56788') R = s2l('a 23 b324 c 6') L.symmetric_difference_update(M) self.assertTrue(isinstance(L, DictSet)) self.assertTrue(isinstance(M, dict)) self.assertEqual(d2l(L), R) # L is updated self.assertEqual(d2l(M), s2l('a1 c56788'))
def test2(self): L = DictSet(s2d('a1 c5666788')) M = s2d('a123 b324') R = s2l('a123 b324 c56 78') L.update(M) self.assertTrue(isinstance(L,DictSet)) self.assertTrue(isinstance(M,dict)) self.assertEqual(d2l(L),R) # L is updated self.assertEqual(d2l(M),s2l('a123 b324'))
def test1(self): L = DictSet(s2d('')) M = s2d('a1 c5666788') R = s2l('') L.difference_update(M) self.assertTrue(isinstance(L, DictSet)) self.assertTrue(isinstance(M, dict)) self.assertEqual(d2l(L), R) # L is updated self.assertEqual(d2l(M), s2l('a1 c5666788'))
def test3(self): L = DictSet(s2d('a123 b324 c5 78')) M = s2d('a1 c56788') R = s2l('a 23 b324 c 6') L.symmetric_difference_update(M) self.assertTrue(isinstance(L,DictSet)) self.assertTrue(isinstance(M,dict)) self.assertEqual(d2l(L),R) # L is updated self.assertEqual(d2l(M),s2l('a1 c56788'))
def test2(self): L = DictSet(s2d('a1 c5678')) R1 = s2l('a1 c5678') with self.assertRaises(TypeError) as cm: M = L.fromkeys(['a', 'b'], 5) self.assertEqual(str(cm.exception), "'int' object is not iterable") self.assertEqual(d2l(L), R1)
def test1(self): L = DictSet(s2d('')) M = s2d('a1 c5666788') R = s2l('') L.difference_update(M) self.assertTrue(isinstance(L,DictSet)) self.assertTrue(isinstance(M,dict)) self.assertEqual(d2l(L),R) # L is updated self.assertEqual(d2l(M),s2l('a1 c5666788'))
def test2(self): L = DictSet(s2d('a1 c5678')) R1 = s2l('a1 c5678') with self.assertRaises(TypeError) as cm: M=L.fromkeys(['a','b'],5) self.assertEqual(str(cm.exception), "'int' object is not iterable") self.assertEqual(d2l(L),R1)
def test1(self): L = DictSet(s2d('a12 c5666788 d0')) g=L.unique_combinations() self.assertEqual([v for v in g],[['1','5'], ['1','6'], ['1','7'], ['1','8'], ['2','5'], ['2','6'], ['2','7'], ['2','8']])
def test2(self): L = DictSet(s2d('a12 c5666788 d12345')) g=L.unique_combinations(keys=['a','c']) self.assertEqual([v for v in g],[['1','5'], ['1','6'], ['1','7'], ['1','8'], ['2','5'], ['2','6'], ['2','7'], ['2','8']])
def test3(self): L = DictSet(s2d('a12 c5666788 d12345')) g=L.unique_combinations(keys=['c','a']) self.assertEqual([v for v in g],[['5','1'], ['5','2'], ['6','1'], ['6','2'], ['7','1'], ['7','2'], ['8','1'], ['8','2']])
def test0(self): df=DataFrame() conditionsDict=DictSet({'A':[10,20,40,80], 'B':[100,800], 'rep':list(range(10))}) for A,B,rep in conditionsDict.unique_combinations(): df.insert({'A':A, 'B':B,'rep':rep}) for d,r in zip(df['A'],_rep_generator([10,20,40,80],4,20)): self.assertAlmostEqual(d,r) for d,r in zip(df['B'],_rep_generator([100,800],8,10)): self.assertAlmostEqual(d,r) for d,r in zip(df['rep'],_rep_generator(list(range(10)),8,1)): self.assertAlmostEqual(d,r)
def test0(self): df=DataFrame() conditionsDict=DictSet({'A':[10,20,40,80], 'B':[100,800], 'rep':range(10)}) for A,B,rep in conditionsDict.unique_combinations(): df.insert({'A':A, 'B':B,'rep':rep}) for d,r in zip(df['A'],_rep_generator([10,20,40,80],4,20)): self.assertAlmostEqual(d,r) for d,r in zip(df['B'],_rep_generator([100,800],8,10)): self.assertAlmostEqual(d,r) for d,r in zip(df['rep'],_rep_generator(range(10),8,1)): self.assertAlmostEqual(d,r)
def test22(self): """DictSet(iterable)""" self.assertEqual( d2l(DictSet([ ('a', ''), ('b', '123'), ('c', '45556'), ])), s2l('a 0 b 123 c 45 6'))
def test1(self): L = DictSet(s2d('a123 b456')) del L['a'] with self.assertRaises(KeyError) as cm: del L['a'] self.assertEqual(str(cm.exception), "'a'")
def test0(self): L = DictSet(s2d('a1c5666788')) M = s2d('') R = s2l('a1c56 78') self.assertTrue(isinstance(L | M, DictSet)) self.assertEqual(d2l(L | M), R) self.assertEqual(d2l(L), s2l('a1c5678')) self.assertEqual(d2l(M), s2l(''))
def test2(self): L = DictSet(s2d('a1 c56788 e0')) M = s2d('a123 b324 c5 78 d0') R = s2l('a 23 b324 c 6') self.assertTrue(isinstance(L ^ M, DictSet)) self.assertEqual(d2l(L ^ M), R) self.assertEqual(d2l(L), s2l('a1 c5678 e0')) self.assertEqual(d2l(M), s2l('a123 b324 c5 78 d0'))
def test3(self): L = DictSet(s2d('a123 b324 c5 78 e0')) M = s2d('a1 c567889 d0') R = s2l('a1 c5 78 ') self.assertTrue(isinstance(L & M, DictSet)) self.assertEqual(d2l(L & M), R) self.assertEqual(d2l(L), s2l('a123 b234 c5 78 e0')) self.assertEqual(d2l(M), s2l('a1 c567889 d0'))
def test4(self): L = DictSet(s2d('a1 c5666788')) R = s2l('a1 c56 7') L.remove('c','8') if sys.version_info[0]==2: with self.assertRaises(KeyError) as cm: L.remove([],'8') self.assertEqual(str(cm.exception),'[]') elif sys.version_info[0]==3: with self.assertRaises(TypeError) as cm: L.remove([],'8') self.assertEqual(str(cm.exception),"unhashable type: 'list'")
def test(self): # build the test data V=[] for i in range(300): V.append(normalvariate(100.,10.)) # build some weight vectors to test W1=[.001 for i in range(300)] W2=[1. for i in range(300)] W2[0]=10000. W3=[-1. for i in range(300)] W=[W1, W2, W3, None] # factorially examine the conditions in this DictSet # see: http://code.google.com/p/dictset/ ds = DictSet({'bins':[1,2,10,171,500], 'range':[(0,100),None], 'density':[True, False], 'weights':[0, 1, 2, 3], 'cumulative':[True, False]}) for b,r,d,w,c in ds.unique_combinations( ['bins','range','density','weights','cumulative']): print(b,r,d,w,c) DN, DB = pystaggrelite3.hist(V, b, r, d, W[w], c) pylab.figure() RN, RB, patches = pylab.hist(V, b, r, d, W[w], c) pylab.close() for d,r in zip(DN, RN): self.assertAlmostEqual(d, r) for d,r in zip(DB, RB): self.assertAlmostEqual(d, r)
def test3(self): L = DictSet(s2d('a1 c5666788')) R= s2l('a1 c5678 d234') self.assertEqual(L.setdefault('d','234'),set('234')) self.assertEqual(d2l(L),R)