@@ -436,7 +436,7 @@ public function cases_fromString()
436436 /**
437437 * Tests BitArray::fromString
438438 *
439- * @param array $string Initial values
439+ * @param string $string bits
440440 *
441441 * @return void
442442 *
@@ -479,6 +479,107 @@ public function test_fromJson()
479479 );
480480 }
481481
482+ /**
483+ * Data provider for test_fromSlice
484+ *
485+ * @return array
486+ *
487+ * @since 1.0.0
488+ */
489+ public function cases_fromSlice ()
490+ {
491+ return [
492+ ['' , 0 , null , '' ],
493+ ['11010110 ' , 0 , null , '11010110 ' ],
494+ ['11010110 ' , 1 , null , '1010110 ' ],
495+ ['11010110 ' , 8 , null , '' ],
496+ ['11010110 ' , 9 , null , '' ],
497+ ['11010110 ' , -7 , null , '1010110 ' ],
498+ ['11010110 ' , -8 , null , '11010110 ' ],
499+ ['11010110 ' , -9 , null , '11010110 ' ],
500+
501+ ['' , 0 , 4 , '' ],
502+ ['11010110 ' , 0 , 4 , '1101 ' ],
503+ ['11010110 ' , 1 , 4 , '1010 ' ],
504+ ['11010110 ' , 8 , 4 , '' ],
505+ ['11010110 ' , 9 , 4 , '' ],
506+ ['11010110 ' , -7 , 4 , '1010 ' ],
507+ ['11010110 ' , -8 , 4 , '1101 ' ],
508+ ['11010110 ' , -9 , 4 , '1101 ' ],
509+
510+ ['' , 0 , 8 , '' ],
511+ ['11010110 ' , 0 , 8 , '11010110 ' ],
512+ ['11010110 ' , 1 , 8 , '1010110 ' ],
513+ ['11010110 ' , 8 , 8 , '' ],
514+ ['11010110 ' , 9 , 8 , '' ],
515+ ['11010110 ' , -7 , 8 , '1010110 ' ],
516+ ['11010110 ' , -8 , 8 , '11010110 ' ],
517+ ['11010110 ' , -9 , 8 , '11010110 ' ],
518+
519+ ['' , 0 , 9 , '' ],
520+ ['11010110 ' , 0 , 9 , '11010110 ' ],
521+ ['11010110 ' , 1 , 9 , '1010110 ' ],
522+ ['11010110 ' , 8 , 9 , '' ],
523+ ['11010110 ' , 9 , 9 , '' ],
524+ ['11010110 ' , -7 , 9 , '1010110 ' ],
525+ ['11010110 ' , -8 , 9 , '11010110 ' ],
526+ ['11010110 ' , -9 , 9 , '11010110 ' ],
527+
528+ ['' , 0 , -4 , '' ],
529+ ['11010110 ' , 0 , -4 , '1101 ' ],
530+ ['11010110 ' , 1 , -4 , '101 ' ],
531+ ['11010110 ' , 8 , -4 , '' ],
532+ ['11010110 ' , 9 , -4 , '' ],
533+ ['11010110 ' , -7 , -4 , '101 ' ],
534+ ['11010110 ' , -8 , -4 , '1101 ' ],
535+ ['11010110 ' , -9 , -4 , '1101 ' ],
536+
537+ ['' , 0 , -8 , '' ],
538+ ['11010110 ' , 0 , -8 , '' ],
539+ ['11010110 ' , 1 , -8 , '' ],
540+ ['11010110 ' , 8 , -8 , '' ],
541+ ['11010110 ' , 9 , -8 , '' ],
542+ ['11010110 ' , -7 , -8 , '' ],
543+ ['11010110 ' , -8 , -8 , '' ],
544+ ['11010110 ' , -9 , -8 , '' ],
545+
546+ ['' , 0 , -9 , '' ],
547+ ['11010110 ' , 0 , -9 , '' ],
548+ ['11010110 ' , 1 , -9 , '' ],
549+ ['11010110 ' , 8 , -9 , '' ],
550+ ['11010110 ' , 9 , -9 , '' ],
551+ ['11010110 ' , -7 , -9 , '' ],
552+ ['11010110 ' , -8 , -9 , '' ],
553+ ['11010110 ' , -9 , -9 , '' ],
554+ ];
555+ }
556+
557+ /**
558+ * Tests BitArray::fromSlice
559+ *
560+ * @param string $string Initial values
561+ * @param integer $offset Slice offset
562+ * @param integer $size Slice size
563+ * @param string $result Expected result
564+ *
565+ * @return void
566+ *
567+ * @covers chdemko\BitArray\BitArray::fromSlice
568+ * @covers chdemko\BitArray\BitArray::__construct
569+ * @covers chdemko\BitArray\BitArray::__toString
570+ *
571+ * @dataProvider cases_fromSlice
572+ *
573+ * @since 1.0.0
574+ */
575+ public function test_fromSlice ($ string , $ offset , $ size , $ result )
576+ {
577+ $ this ->assertEquals (
578+ $ result ,
579+ (string ) BitArray::fromSlice (BitArray::fromString ($ string ), $ offset , $ size )
580+ );
581+ }
582+
482583 /**
483584 * Tests BitArray::applyComplement
484585 *
0 commit comments