@@ -61,9 +61,52 @@ describe("Position", async () => {
6161 } )
6262
6363 describe ( "parent" , async ( ) => {
64- it ( "Returns the first bits" , async ( ) => {
65- const result = await positionInstance . parent ( fullPosition )
66- expect ( result ) . to . be . equal ( parentPosition )
64+ it ( "Returns the associated parent position for a child position" , async ( ) => {
65+ // Sample Cases
66+ //
67+ // The first 8 positions get the first parent, the next 8 positions get
68+ // the second parent, and so on. The formula to find a parent position
69+ // based on a child position is `position / 8`.
70+
71+ const testData = [
72+ {
73+ position : 196831 ,
74+ parent : 24603 ,
75+ } ,
76+ {
77+ position : 238968 ,
78+ parent : 29871 ,
79+ } ,
80+ {
81+ position : 31002 ,
82+ parent : 3875 ,
83+ } ,
84+ {
85+ position : 1617940 ,
86+ parent : 202242 ,
87+ } ,
88+ ]
89+ for ( let i = 0 ; i < testData . length ; i ++ ) {
90+ const test = testData [ i ]
91+ const parent = await positionInstance . parent ( test . position )
92+ expect ( parent ) . to . equal (
93+ test . parent ,
94+ `unexpected result for test index ${ i } ` ,
95+ )
96+ }
97+
98+ // Generative Testing
99+ const numSamples = 100
100+ for ( let i = 0 ; i < numSamples ; i ++ ) {
101+ // generate a random position in [0, maxPosition)
102+ const position = Math . floor ( Math . random ( ) * maxPosition )
103+ const parent = await positionInstance . parent ( position )
104+ const expectation = Math . floor ( position / 8 )
105+ expect ( parent ) . to . equal (
106+ expectation ,
107+ `unexpected result for position ${ position } ` ,
108+ )
109+ }
67110 } )
68111 } )
69112
0 commit comments