Example #1
0
 def test_commit_once(self):
     Command.cmd_commit('first ci')
     commit = Commit(sha1=Branch().head_commit)
     self.assertIsNone(commit.parent_sha1)
     tree = Tree(sha1=commit.tree)
     objects = tree.parse_objects()
     self.assertEqual(objects[self.path]['sha1'], Blob(self.content).sha1)
Example #2
0
 def test_commit_once(self):
     Command.cmd_commit('first ci')
     commit = Commit(sha1=Branch().head_commit)
     self.assertIsNone(commit.parent_sha1)
     tree = Tree(sha1=commit.tree)
     objects = tree.parse_objects()
     self.assertEqual(objects[self.path]['sha1'], Blob(self.content).sha1)
Example #3
0
 def build_tree(path):
     tree = Tree()
     for basename, entry in trees[path].iteritems():
         if type(entry) == dict:
             mode = stat.S_IFDIR
             sha = build_tree(os.path.join(path, basename))
         else:
             (mode, sha) = entry
         tree.add(mode, basename, sha)
     object_store.add_object(tree)
     return tree.id
Example #4
0
 def add_barrier(self, gradient):
     '''Add barrier on the road, the number and speed will
     increase according to difficulty gradient'''
     # use last_add to limit minimum spacing
     self.last_add += 1
     if self.last_add > 80 - gradient * 3 and \
             random.randint(0, int(100 - gradient * 2)) == 0:
         fence = Fence(self.cv, self.cv_w, self.cv_h)
         fence.x_speed += gradient
         self.objects.append(fence)
         self.last_add = 0
     elif self.last_add > 80 - gradient * 3 and \
             random.randint(0, int(120 - gradient * 2)) == 0:
         tree = Tree(self.cv, self.cv_w, self.cv_h)
         tree.x_speed += gradient
         self.objects.append(tree)
         self.last_add = 0
     elif gradient >= 0.5 and self.last_add > 80 - gradient * 3 and \
             random.randint(0, int(200 - gradient * 2)) == 0:
         # pinball will not occur during first 50 m
         pinball = Pinball(self.cv, self.cv_w, self.cv_h)
         pinball.x_speed += gradient
         pinball.gravity += gradient * 0.06
         self.objects.append(pinball)
         self.last_add = 0
Example #5
0
    def test_commit_twice(self):
        Command.cmd_commit('first ci')
        parent_sha1 = Branch().head_commit

        second_content = '11\n'
        write_to_file(self.path, second_content)

        new_path = '2.txt'
        new_content = '2\n'
        write_to_file(new_path, new_content)

        Command.cmd_add('.')
        Command.cmd_commit('second ci')

        commit = Commit(sha1=Branch().head_commit)
        self.assertEqual(parent_sha1, commit.parent_sha1)
        tree = Tree(sha1=commit.tree)
        objects = tree.parse_objects()
        self.assertEqual(objects[self.path]['sha1'], Blob(second_content).sha1)
        self.assertEqual(objects[new_path]['sha1'], Blob(new_content).sha1)
Example #6
0
 def test_commit_twice(self):
     Command.cmd_commit('first ci')
     parent_sha1 = Branch().head_commit
     
     second_content = '11\n'
     write_to_file(self.path, second_content)
     
     new_path = '2.txt'
     new_content = '2\n'
     write_to_file(new_path, new_content)
     
     Command.cmd_add('.')
     Command.cmd_commit('second ci')
     
     commit = Commit(sha1=Branch().head_commit)
     self.assertEqual(parent_sha1, commit.parent_sha1)
     tree = Tree(sha1=commit.tree)
     objects = tree.parse_objects()
     self.assertEqual(objects[self.path]['sha1'], Blob(second_content).sha1)
     self.assertEqual(objects[new_path]['sha1'], Blob(new_content).sha1)
Example #7
0
 def _build_tree(path):
     dir_arr = []
     file_arr = []
     for name, entry in path.iteritems():
         if isinstance(entry, dict):
             mode = stat.S_IFDIR
             sha1 = _build_tree(entry).sha1
             dir_arr.append({'name': name, 'mode': mode, 'sha1': sha1})
         else:
             (mode, sha1) = entry
             file_arr.append({'name': name, 'mode': mode, 'sha1': sha1})
     newtree = Tree(
         sorted(dir_arr, key=lambda x: x['name']) +
         sorted(file_arr, key=lambda x: x['name']))
     write_to_file(newtree.path, newtree.content)
     return newtree
Example #8
0
# 5
# 38
# 1469
print('breadth first traversal of a binary tree')
bft_exec(node5)

# dft() should return:
# 5
# 38
# 1469
# print('\n\ndepth first traversal of a binary tree')
# dft(node5)
# print('\n\nsearching binary tree')
# for i in range(10):
#     print(i, search(node5, i))

num_values = 100_000

tree = Tree(num_values, False)
tree = Tree(num_values, True)

bft_exec(tree.root)
dft_exec(tree.root)
for i in range(10):
    if not search_exec(tree.root, i):
        print(f'{i} not found')
    else:
        print(f'{i} found')

gc.collect()
Example #9
0
def create_map(map_width: int, map_height: int):
    num_trees = randint(20, 40)
    for _ in range(num_trees):
        x = randint(20, map_width - 20)
        y = randint(20, map_height - 20)
        trees[(x, y)] = Tree(x, y, 0, randint(30, 50))