1+ const calc = require ( "../src/byte_flag_calculator" ) ;
2+
3+ describe ( `byte flag calculator` , ( ) => {
4+ describe ( `dataProvider with HEX values` , ( ) => {
5+ describe ( `::hasBytes` , ( ) => {
6+ [
7+ { flags : 0x01 , flag : 0x01 } ,
8+ { flags : 0x03 , flag : 0x01 } ,
9+ { flags : 0x05 , flag : 0x01 } ,
10+ { flags : 0x07 , flag : 0x02 } ,
11+ { flags : 0x05 , flag : 0x04 } ,
12+ ] . forEach ( el => {
13+ it ( ` - expected true as ${ el . flag } bytes are presented in ${ el . flags } ` , ( ) => {
14+ expect ( calc . hasBytes ( el . flags , el . flag ) ) . toBe ( true ) ;
15+ } )
16+ } ) ;
17+
18+ [
19+ { flags : 0x00 , flag : 0x01 } ,
20+ { flags : 0x00 , flag : 0x02 } ,
21+ { flags : 0x01 , flag : 0x02 } ,
22+ { flags : 0x03 , flag : 0x04 } ,
23+ { flags : 0x06 , flag : 0x01 } ,
24+ ] . forEach ( el => {
25+ it ( ` - expected false as ${ el . flag } bytes aren't presented in ${ el . flags } ` , ( ) => {
26+ expect ( calc . hasBytes ( el . flags , el . flag ) ) . toBe ( false ) ;
27+ } )
28+ } ) ;
29+ } ) ;
30+
31+ describe ( `::addBytes` , ( ) => {
32+ [
33+ { flags : 0x00 , flag : 0x01 , expected : 0x01 } ,
34+ { flags : 0x01 , flag : 0x01 , expected : 0x01 } ,
35+ { flags : 0x01 , flag : 0x02 , expected : 0x03 } ,
36+ { flags : 0x03 , flag : 0x04 , expected : 0x07 } ,
37+ { flags : 0x06 , flag : 0x01 , expected : 0x07 } ,
38+ ] . forEach ( el => {
39+ it ( ` - expected ${ el . expected } by adding bytes ${ el . flag } to ${ el . flags } ` , ( ) => {
40+ expect ( calc . addBytes ( el . flags , el . flag ) ) . toBe ( el . expected ) ;
41+ } )
42+ } ) ;
43+ } ) ;
44+
45+ describe ( `::removeBytes` , ( ) => {
46+ [
47+ { flags : 0x00 , flag : 0x01 , expected : 0x00 } ,
48+ { flags : 0x02 , flag : 0x01 , expected : 0x02 } ,
49+ { flags : 0x12 , flag : 0x02 , expected : 0x10 } ,
50+ { flags : 0x04 , flag : 0x04 , expected : 0x00 } ,
51+ { flags : 0x0F , flag : 0xFF , expected : 0x0F } ,
52+ ] . forEach ( el => {
53+ it ( ` - expected ${ el . expected } by removing bytes ${ el . flag } from ${ el . flags } ` , ( ) => {
54+ expect ( calc . removeBytes ( el . flags , el . flag ) ) . toBe ( el . expected ) ;
55+ } )
56+ } ) ;
57+ } ) ;
58+ } ) ;
59+ } ) ;
0 commit comments