def test_createS3Key(self): my_dict = dict() my_dict['col_name1'] = 'col_value1' my_dict['col_name2'] = 'col_value2' createdKey = S3Processor.S3Processor('test_bucket').createS3Key(my_dict) print('createdKey' + createdKey) TestCase.assertEquals(self, createdKey, 'col_name1=col_value1/col_name2=col_value2')
def test_tmx_manageCollisionEvents(self): boundaries = self.game.tilemap.layers['boundaries'] walls = self.game.tilemap.layers['walls'] destination = walls.cells[walls.cells.keys()[0]] (dx, dy) = self.__calcule_delta(self.game.perso, destination) self.game.perso.move(dx, dy) TestCase.assertNotEquals(self, self.game.perso.collision_rect.y, self.game.perso.last_coll_y) self.game.tmx_stackCollisionEvents(self.game.perso, self.game.tmxEvents) self.game.tmx_manageCollisionEvents(self.game.perso, self.game.tmxEvents) TestCase.assertEquals(self, self.game.perso.collision_rect.y, self.game.perso.last_coll_y) destination = boundaries.find('destination')[0] dest_filename = destination.properties['destination'] (dx, dy) = self.__calcule_delta(self.game.perso, destination) self.game.perso.move(dx, dy) self.game.tmx_stackCollisionEvents(self.game.perso, self.game.tmxEvents) self.game.tmx_manageCollisionEvents(self.game.perso, self.game.tmxEvents) TestCase.assertEquals(self, self.game.tilemap.filename, dest_filename)
def test_effectuer_transition(self): dest = self.game.tilemap.layers['boundaries'].find('destination')[0] dest_filename = dest.properties['destination'] self.game.effectuer_transition(dest) TestCase.assertEquals(self, self.game.tilemap.filename, dest_filename)
def goto(level,button=None): if button is None or (level not in (0,1,2,3) : return 0 return int(button) - level from unittest import TestCase Test = TestCase() Test.ass Test.assertEquals(goto(0,'2'),2); Test.assertEquals(3+goto(3,'1'),1); Test.assertEquals(2+goto(2,'2'),2);
def recoverSecret(triplets): """ triplets is a list of triplets from the secrent string. Return the string. """ secret = "" attempt = 0 test = TestCase() while triplets: symbol = next_symbol(triplets) secret += symbol test.assertEquals(triplets, SOLUTION[attempt]) data_before = ("cleanup", deepcopy(triplets), symbol) triplets = cleanup(triplets, symbol) data_after = ("cleanup", deepcopy(triplets), symbol) attempt += 1 try: test.assertEquals(triplets, SOLUTION[attempt]) except AssertionError as err: debug(t=triplets) print(secret, attempt) print("data_before", data_before) print("data_after", data_after) raise err return secret
def assertEquals(self, *args, **kwargs): raise DeprecationWarning( 'The {0}() function is deprecated. Please start using {1}() ' 'instead.'.format('assertEquals', 'assertEqual')) return _TestCase.assertEquals(self, *args, **kwargs)
def assertEquals(self, *args, **kwargs): raise DeprecationWarning( 'The {0}() function is deprecated. Please start using {1}() ' 'instead.'.format('assertEquals', 'assertEqual') ) return _TestCase.assertEquals(self, *args, **kwargs)
(b_end >= a_start and b_end <= a_end) def union((a_start, a_end), (b_start, b_end)): return min(a_start, b_start), max(a_end, b_end) def interval_insert(myl, interval): myl = list(myl) target = None i = 0 while i < len(myl): if target is not None and overlaps(myl[i], myl[target]): myl[target] = union(myl[i], myl[target]) myl.pop(i) elif target is None and overlaps(myl[i], interval): target = i myl[i] = union(myl[i], interval) i += 1 else: i += 1 if target is None: myl.append(interval) return myl from unittest import TestCase test = TestCase() test.assertEquals(interval_insert([(1,2)], (3,4)), [(1, 2), (3, 4)]) test.assertEquals(interval_insert([(3,4)], (1,2)), [(1, 2), (3, 4)]) # test.assertEquals(interval_insert([(1,2), (3, 4)], (2,3)), [(1, 4)]) # test.assertEquals(interval_insert([(1,2), (3, 4), (5, 6)], (2,3)), [(1, 4), (5, 6)])
from unittest import TestCase value = "foo" def strchecker_(x1, x2): return x1 == x2 assert TestCase.assertEquals(strchecker_("foo", "Foo") == "Hello")
x = " and " else: x = ", " m = (x if (flag) else "") + str(m) + " minute" + ("s" if m > 1 else "") flag = 1 if s == 0: s = "" else: s = (" and " if (flag) else "") + str(s) + " second" + ("s" if s > 1 else "") return y + d + h + m + s from unittest import TestCase test = TestCase() try: test.assertEquals(format_duration(1), "1 second") test.assertEquals(format_duration(62), "1 minute and 2 seconds") test.assertEquals(format_duration(120), "2 minutes") test.assertEquals(format_duration(3600), "1 hour") test.assertEquals(format_duration(3662), "1 hour, 1 minute and 2 seconds") test.assertEquals(format_duration(15731080), "'182 days, 1 hour, 44 minutes and 40 seconds'") except Exception as e: print(e)
def group_check(s): pat = "(\(\)|\[\]|\{\})" while re.search(pat, s): s = re.sub(pat, "", s) return len(s) < 1 def group_check(s): stack = [] adict = {"(": ")", "[": "]", "{": "}"} for character in s: if stack == [] or character in adict: stack.append(character) top = stack[-1] if top in adict: if adict[top] == character: stack.pop() if stack == []: return True return False from unittest import TestCase Test = TestCase() Test.assertEquals(group_check("()"), True) Test.assertEquals(group_check("({"), False)
def test_addClockSec(self): self.game.addClockSec("playerHud", 1) TestCase.assertEquals(self, self.game.clocks["playerHud"], 1 * self.game.FPS)
reads_to_edges_map, overlap_length_dict, max_overlap_length = \ build_reads_to_overlap_edges_map(kmers_to_reads, uids_to_reads, num_read_uids, k) # TODO: implement iterative lowering of an overlap length lower bound (say 50, 40, 30) while max_overlap_length >= k: r_uid, s_uid = merge_most_overlapping_reads(overlap_length_dict, max_overlap_length, num_read_uids, uids_to_reads) num_read_uids += 1 remove_merged_reads(uids_to_reads, r_uid, s_uid) merged_read_uid = num_read_uids - 1 max_overlap_length = \ update_edge_maps_and_max_overlap(reads_to_edges_map, overlap_length_dict, max_overlap_length, r_uid, s_uid, merged_read_uid, k, uids_to_reads) reads, qualities = read_fastq('ads1_week4_reads.fq') reads = list(set(reads)) # remove duplicates - 14 duplicates test = TestCase() start = clock() test.assertEquals(greedy_scs(reads), 15894) elapsed = clock() - start print 'time: %f' % elapsed
# modify and return the original matrix rotated 90 degrees clockwise in place def rotate_in_place(matrix): return [[row[i] for row in reversed(matrix)] for i in range(len(matrix))] matrix2 = [[1, 2], [3, 4]] print(rotate_in_place(matrix2)) from unittest import TestCase Test = TestCase() # Test.describe("rotate_in_place") matrix2 = [[1, 2], [3, 4]] rmatrix2 = [[3, 1], [4, 2]] # Test.it("should return the rotated matrices") Test.assertEquals(rotate_in_place(matrix2), rmatrix2)