import { Bool } from "../Bool" ; describe ( "Bool" , ( ) => { it ( "should encode bool with true" , ( ) => { let v = new Bool ( true ) ; expect < u8 [ ] > ( v . toU8a ( ) ) . toStrictEqual ( [ 0x01 ] ) ; } ) ; it ( "should encode bool with false" , ( ) => { let v = new Bool ( false ) ; expect < u8 [ ] > ( v . toU8a ( ) ) . toStrictEqual ( [ 0x00 ] ) ; } ) ; it ( "should instantiate true Bool from U8Array" , ( ) => { expect < Bool > ( Bool . fromU8a ( [ 0x01 ] ) ) . toStrictEqual ( new Bool ( true ) ) ; } ) ; it ( "should instantiate false Bool from U8Array" , ( ) => { expect < Bool > ( Bool . fromU8a ( [ 0x00 ] ) ) . toStrictEqual ( new Bool ( false ) ) ; } ) ; it ( "should read only first byte at current position" , ( ) => { expect < Bool > ( Bool . fromU8a ( [ 0x00 , 0x01 , 0xff ] , 1 ) ) . toStrictEqual ( new Bool ( true ) ) ; expect < Bool > ( Bool . fromU8a ( [ 0x00 , 0x0f , 0xff , 0x00 ] , 3 ) ) . toStrictEqual ( new Bool ( false ) ) ; } ) ; it ( "should decode using populate from bytes" , ( ) => { const instance = new Bool ( ) ; instance . populateFromBytes ( [ 0 ] ) ; expect < Bool > ( instance ) . toStrictEqual ( new Bool ( false ) ) ; instance . populateFromBytes ( [ 1 ] ) ; expect < Bool > ( instance ) . toStrictEqual ( new Bool ( true ) ) ; } ) ; itThrows ( "when provided invalid bool value" , ( ) => { Bool . fromU8a ( [ 0x05 ] ) ; } ) ; itThrows ( "should throw when index is out of range" , ( ) => { Bool . fromU8a ( [ 0 , 1 , 0 , 1 , 0 ] , 5 ) ; } ) ; } ) ;