#!/usr/bin/env python # -*- coding: utf-8 -*- # import test test.start('Add animations to container') import easyvideo.animation animations = easyvideo.animation.Animations() frames = easyvideo.animation.FrameSet('data/frame01.png', 'data/frame02.png', 'data/frame03.png', 'data/frame04.png', 'data/frame05.png', 'data/frame06.png', 'data/frame07.png', 'data/frame08.png') try: animations.add('animation1', frames.animation) except Exception, e: test.failed('Cannot add animation (%s)' % e) test.ok()
#!/usr/bin/env python # -*- coding: utf-8 -*- # import test test.start('Layer drawing') import easyvideo.screen scr = easyvideo.screen.Screen() import random import pygame def _randint(max_val): return random.randint(0, max_val) for circle in range(100): try: pygame.draw.circle(scr.background.layer, (_randint(255), _randint(255), _randint(255), 255), (_randint(1024), _randint(768)), _randint(10)) except Exception, e: test.failed('Cannot draw into layer (%s)' % e) scr.update() test.ok()
#!/usr/bin/env python # -*- coding: utf-8 -*- # import test test.start('Layer property access') import easyvideo.screen scr = easyvideo.screen.Screen() try: test.ok('Background layer size: %s' % scr.background.area) except Exception, e: test.failed('Cannot get layer size (%s)' % e)
#!/usr/bin/env python # -*- coding: utf-8 -*- # import test test.start('Screen layers access') import easyvideo.screen scr = easyvideo.screen.Screen() try: test.ok('Background layer: %s' % type(scr.background.layer)) except Exception, e: test.failed('Cannot access to background layer (%s)' % e)
#!/usr/bin/env python # -*- coding: utf-8 -*- # import test test.start('Get screen properties') import easyvideo.screen scr = easyvideo.screen.Screen() try: test.ok('Screen resolution: %sx%s' % scr.size) except Exception, e: test.failed('Cannot get screen size (%s)' % e)
for pair in self.table[self.hashf(key)]: if pair[0] == key: pair[1] = value return self.table[self.hashf(key)].append([key, value]) def __getitem__(self, item): for pair in self.table[self.hashf(item)]: if pair[0] == item: return pair[1] raise KeyError("No such key {}".format(item)) if __name__ == "__main__": import test dic = Hash() dic[1] = 2 test.ok(dic[1] == 2) dic[1] = 5 dic[11] = 3 test.ok(dic[1] == 5) test.ok(dic[11] == 3) try: dic[12] except KeyError as e: test.ok(e.args[0] == "No such key 12")
import test def is_unique(s): charset = set() for i in s: if i in charset: return False charset.add(i) return True def is_unique_no_new_ds(s): return not any((i[1] in s[i[0] + 1:] for i in enumerate(s))) if __name__ == "__main__": test.ok(is_unique("abc")) test.ok(is_unique("")) test.ok(not is_unique("aa")) test.ok(is_unique_no_new_ds("abc")) test.ok(is_unique_no_new_ds("")) test.ok(not is_unique_no_new_ds("aa")) test.ok(not is_unique_no_new_ds("asffff"))