def test_delay_split(self): delay = LightCommandDelay(arguments=Arguments([132000])) main = LightSequenceMain(objects=[delay]) main.resolve_unsupported() self.assertEqual( main.export(), "; DELAY RESOLVE: 132000\ndelay (65535)\ndelay (65535)\ndelay (930)\nend" )
def test_compress_ramp_1(self): m1 = LightSequenceMain(objects=[ LightCommandColor(arguments=Arguments([0, 0, 0])), LightCommandRamp(arguments=Arguments([85, 50, 20, 10])), LightCommandRamp(arguments=Arguments([170, 100, 40, 10])) ]) m2 = LightSequenceMain(objects=[ LightCommandColor(arguments=Arguments([0, 0, 0])), LightCommandRamp(arguments=Arguments([170, 100, 40, 20])) ]) m1.compress(options={'epsilon': 0}) self.assertEqual(m1, m2)
def test_compress_ramp_2(self): m1 = LightSequenceMain(objects=[ LightCommandRamp(arguments=Arguments([0, 0, 0, 5])), LightCommandRamp(arguments=Arguments([85, 0, 0, 10])), LightCommandRamp(arguments=Arguments([170, 0, 0, 10])), LightCommandRamp(arguments=Arguments([255, 0, 0, 10])), LightCommandRamp(arguments=Arguments([170, 0, 0, 20])), LightCommandRamp(arguments=Arguments([85, 0, 0, 20])), LightCommandRamp(arguments=Arguments([0, 0, 0, 20])) ]) m2 = LightSequenceMain(objects=[ LightCommandRamp(arguments=Arguments([0, 0, 0, 5])), LightCommandRamp(arguments=Arguments([255, 0, 0, 30])), LightCommandRamp(arguments=Arguments([0, 0, 0, 60])) ]) m1.compress(options={'epsilon': 0, 'root': None}) self.assertEqual(m1, m2)
def test_light_object_sub(self): d = LightCommandDelay(arguments=Arguments([1]), noop=" ; comment") ds = LightSequenceDefsub(arguments=Arguments(['sub_name']), objects=[d], noop=' ; defsub') s = LightCommandSub(arguments=Arguments(['sub_name']), noop=" ; comment") m = LightSequenceMain(objects=[s]) f = LightSequenceFile(objects=[m, ds]) lo = LightSequenceLoop(arguments=Arguments([5]), objects=[s]) self.assertEqual( ds.export(), "defsub (sub_name) ; defsub\ndelay (1) ; comment\nendsub") self.assertEqual(ds.get_duration(), 1) self.assertEqual(s.export(), "sub (sub_name) ; comment") self.assertEqual(s.get_duration(root=f), 1) self.assertEqual(m.export(), "sub (sub_name) ; comment\nend") self.assertEqual(m.get_duration(root=f), 1) self.assertEqual( f.export(), "sub (sub_name) ; comment\nend\ndefsub (sub_name) ; defsub\ndelay (1) ; comment\nendsub" ) self.assertEqual(f.get_duration(), 1) self.assertEqual(lo.export(), "loop (5)\nsub (sub_name) ; comment\nendloop") self.assertEqual(lo.get_duration(root=f), 5) m.append(lo) self.assertEqual(f.get_duration(), 6)
def test_loop_unfold(self): delay = LightCommandDelay(arguments=Arguments([10])) mains = [] for l in (0, 1, 255, 521): loop = LightSequenceLoop(objects=[delay], arguments=Arguments([l])) mains.append(LightSequenceMain(objects=[loop])) mains[-1].resolve_unsupported() self.assertEqual(mains[0].export(), "end") self.assertEqual(mains[1].export(), "delay (10)\nend") self.assertEqual(mains[2].export(), "loop (255)\ndelay (10)\nendloop\nend") self.assertEqual( mains[3].export(), "loop (2); LOOP UNFOLD: 2 * 255 + 11 = 521\nloop (255)\ndelay (10)\nendloop\nendloop\nloop (11)\ndelay (10)\nendloop\nend" )
def test_define(self): arguments = Arguments(name="DEF_NAME", objects=[1, 2, 3]) define = LightCommandDefine(arguments=arguments) color = LightCommandColor(arguments=arguments) main = LightSequenceMain(objects=[define, color]) self.assertEqual(define.export(), "#define DEF_NAME 1, 2, 3") self.assertEqual(color.export(), "color (DEF_NAME)") main.add_namespace("GLO1_") self.assertEqual(main[0].export(), "#define GLO1_DEF_NAME 1, 2, 3") self.assertEqual(main[1].export(), "color (GLO1_DEF_NAME)") main.resolve_constants() self.assertEqual(main[0].export(), ";#define GLO1_DEF_NAME 1, 2, 3") self.assertEqual(main[1].export(), "color (1, 2, 3)")
def test_delay_zero(self): delay = LightCommandDelay(arguments=Arguments([0]), noop=" ; comment") main = LightSequenceMain(objects=[delay]) main.resolve_unsupported() self.assertEqual(main.export(), "; DELAY RESOLVE: 0 ; comment\nend")