function _check_proper_nesting_strict($nodes, $level_limit=-1, $line='') { $l = complex_array :: get_min_column_value('l', $nodes, $index); $r = complex_array :: get_max_column_value('r', $nodes, $index); $node = current($nodes); $this->assertEqual($node['l'], $l, 'l is invalid: ' . $node['l'] . ' , expected : ' . $l . ' at line: ' . $line); $this->assertEqual($node['r'], $r, 'r is invalid: ' . $node['r'] . ' , expected : ' . $r . ' at line: ' . $line); $children = ($r - $l - 1)/2; if($children > 0) { $last_r = $this->_check_proper_nesting_recursive($nodes, $line, $l, $r, $children, $level_limit-1); if($last_r !== false && sizeof($nodes) > $level_limit) $this->assertEqual($node['r'] - $last_r, 1, 'there is a gap between r ' . $node['r'] . ' and r ' . $last_r . ' at line: ' . $line); } }
function _check_proper_nesting($nodes, $line='') { $paths[] = complex_array :: get_min_column_value('path', $nodes, $index); $counter = 0; foreach($nodes as $id => $node) { if($counter == 0) { $this->assertEqual($node['path'], $paths[0], 'first element path is invalid: ' . $node['path'] . ' , expected : ' . $paths[0] . ' at line: ' . $line); } elseif(preg_match('~^(.*/)[^/]+/$~', $node['path'], $matches)) { $prev_path = $matches[1]; $this->assertTrue(in_array($prev_path, $paths), 'path is improperly nested: ' . $node['path'] . ' , expected parent not found: ' . $prev_path . ' at line: ' . $line); } else { $this->assertFalse(true, 'path is invalid: ' . $node['path'] . ' at line: ' . $line); } $paths[] = $node['path']; $counter++; } }
function _check_proper_nesting($nodes, $line='') { $this->assertEqual(complex_array :: sort_array($nodes, array('path' => 'ASC')), $nodes); $path = complex_array :: get_min_column_value('path', $nodes, $index); $parent_paths[] = $this->_get_parent_path($path); $counter = 0; foreach($nodes as $id => $node) { $parent_path = $this->_get_parent_path($node['path']); $this->assertTrue(in_array($parent_path, $parent_paths), 'path is improperly nested: ' . $node['path'] . ' , expected parent not found: ' . $parent_path . ' at line: ' . $line); $parent_paths[] = $node['path']; } }