fix scope in [0,n-1]
add test
Merge branch 'feat-fix-tree' into develop