@@ -279,3 +279,135 @@ def test_write_csv_read_csv_encoded_command(self):
279279 print ("csv-encoded: " , csv_pattern .stitches )
280280 self .assertEqual (encoded_command , csv_pattern .stitches [- 1 ][2 ])
281281 self .addCleanup (os .remove , file1 )
282+
283+ def test_issue_87 (self ):
284+ """
285+ Initial test raised by issue 87.
286+ """
287+ pattern = EmbPattern ()
288+ stitches_1 = [[0 , 1 ], [2 , 3 ]]
289+ stitches_2 = [[4 , 5 ], [6 , 7 ]]
290+ pattern .add_block (stitches_1 , 0xFF0000 )
291+ pattern .add_block (stitches_2 , 0x0000FF )
292+ self .assertEqual (len (list (pattern .get_as_colorblocks ())), 2 )
293+
294+ def test_issue_87_2 (self ):
295+ """
296+ Tests a pattern arbitrarily starting with a color change.
297+ With two predefined blocks. The blocks should maintain their blockness.
298+ The color change should isolate 0 stitches, of an unknown color.
299+ :return:
300+ """
301+ pattern = EmbPattern ()
302+ stitches_1 = [[0 , 1 ], [2 , 3 ]]
303+ stitches_2 = [[4 , 5 ], [6 , 7 ]]
304+
305+ pattern .color_change ()
306+ pattern .add_thread ('random' )
307+ pattern .add_block (stitches_1 , 0xFF0000 )
308+ pattern .add_block (stitches_2 , 0x0000FF )
309+ blocks = list (pattern .get_as_colorblocks ())
310+ # for q in blocks:
311+ # print(q)
312+ self .assertEqual (blocks [1 ][1 ].color , 0xFF0000 )
313+ self .assertEqual (blocks [2 ][1 ].color , 0x0000FF )
314+ self .assertEqual (len (blocks ), 3 )
315+
316+ for block in blocks :
317+ stitch_block = block [0 ]
318+ for stitch in stitch_block :
319+ self .assertNotEqual (stitch [2 ], COLOR_BREAK )
320+
321+ pattern = EmbPattern ()
322+ pattern .add_thread ('random' )
323+ pattern .color_change () # end block 1, empty
324+ pattern .add_thread (0xFF0000 )
325+ pattern += stitches_1
326+ pattern .color_change () # end block 2
327+ pattern .add_thread (0x0000FF )
328+ pattern += stitches_2
329+ blocks = list (pattern .get_as_colorblocks ())
330+ # end block 3, no explicit end.
331+ # for q in blocks:
332+ # print(q)
333+ self .assertEqual (blocks [0 ][0 ][- 1 ][2 ], COLOR_CHANGE ) # Color change ends the block.
334+ self .assertEqual (blocks [1 ][0 ][- 1 ][2 ], COLOR_CHANGE ) # Color change ends the block.
335+ self .assertEqual (blocks [1 ][1 ].color , 0xFF0000 )
336+ self .assertEqual (blocks [2 ][1 ].color , 0x0000FF )
337+ self .assertEqual (len (blocks ), 3 )
338+
339+ def test_issue_87_3 (self ):
340+ """
341+ Tests a pattern arbitrarily starting with a needle_set.
342+ With two predefined blocks. The blocks should maintain their blockness.
343+ The needle set should not contribute a block. Initial needle_set, only
344+ define a starting needle.
345+ :return:
346+ """
347+ pattern = EmbPattern ()
348+ pattern .needle_change ()
349+ stitches_1 = [[0 , 1 ], [2 , 3 ]]
350+ stitches_2 = [[4 , 5 ], [6 , 7 ]]
351+ pattern .add_block (stitches_1 , 0xFF0000 )
352+ pattern .add_block (stitches_2 , 0x0000FF )
353+ blocks = list (pattern .get_as_colorblocks ())
354+ # for q in blocks:
355+ # print(q)
356+ self .assertEqual (blocks [0 ][1 ], 0xFF0000 )
357+ self .assertEqual (blocks [1 ][1 ], 0x0000FF )
358+ self .assertEqual (len (blocks ), 2 )
359+ for block in blocks :
360+ stitch_block = block [0 ]
361+ for stitch in stitch_block :
362+ self .assertNotEqual (stitch [2 ], COLOR_BREAK )
363+
364+ pattern = EmbPattern ()
365+
366+ pattern .needle_change () # start block 0
367+ pattern += stitches_1
368+ pattern += EmbThread (0xFF0000 )
369+
370+ pattern .needle_change () # start block 1
371+ pattern += stitches_1
372+ pattern += EmbThread (0x0000FF )
373+
374+ pattern .needle_change () # start block 2
375+ pattern += EmbThread ('random' )
376+
377+ blocks = list (pattern .get_as_colorblocks ())
378+ # for q in blocks:
379+ # print(q)
380+ # Mask is required here since needle_set automatically appends extended data.
381+ self .assertEqual (blocks [0 ][0 ][0 ][2 ] & COMMAND_MASK , NEEDLE_SET ) # Needle_set starts the block.
382+ self .assertEqual (blocks [1 ][0 ][0 ][2 ] & COMMAND_MASK , NEEDLE_SET ) # Needle_set starts the block.
383+ self .assertEqual (blocks [0 ][1 ], 0xFF0000 )
384+ self .assertEqual (blocks [1 ][1 ], 0x0000FF )
385+ self .assertEqual (len (blocks ), 3 )
386+
387+ def test_issue_87_4 (self ):
388+ """
389+ Tests a pattern arbitrarily starting with a color break.
390+ With two predefined blocks. The blocks should maintain their blockness.
391+ And ending with another arbitrary color break. This should give exactly
392+ 2 blocks which were defined as prepended colorbreaks postpended color breaks
393+ are not to have an impact.
394+ :return:
395+ """
396+ pattern = EmbPattern ()
397+ pattern += COLOR_BREAK
398+ stitches_1 = [[0 , 1 ], [2 , 3 ]]
399+ stitches_2 = [[4 , 5 ], [6 , 7 ]]
400+ pattern .add_block (stitches_1 , 0xFF0000 )
401+ pattern .add_block (stitches_2 , 0x0000FF )
402+ pattern += COLOR_BREAK
403+ blocks = list (pattern .get_as_colorblocks ())
404+ # for q in blocks:
405+ # print(q)
406+
407+ for block in blocks :
408+ stitch_block = block [0 ]
409+ for stitch in stitch_block :
410+ self .assertNotEqual (stitch [2 ], COLOR_BREAK )
411+ self .assertEqual (blocks [0 ][1 ], 0xFF0000 )
412+ self .assertEqual (blocks [1 ][1 ], 0x0000FF )
413+ self .assertEqual (len (list (pattern .get_as_colorblocks ())), 2 )
0 commit comments