public static function main() { $arr = array(1, 2, 3, 4, 5); // $arr = array("orange","banana","apple"); self::$lenght = count($arr); self::perm($arr); }
public function testPermutationStatic() { // Size 0 permutations --------------------------------------------------------------------- $permutationList0 = Permutation::get($this->_sourceDataSetKey, 0); $expectedPermutationList0 = []; $this->_assertPermutation($permutationList0, $expectedPermutationList0, 0); // Size 1 permutations --------------------------------------------------------------------- $permutationList1 = Permutation::get($this->_sourceDataSetKey, 1); $expectedPermutationList1 = [['z' => 10], ['a' => 50], ['x' => 77]]; $this->_assertPermutation($permutationList1, $expectedPermutationList1, 3); // If this test pass, we don't need to check for other Index arrays as it proves that the // combination is still treated as a map and thus if the key arrays tests pass, so would the // indexed arrays $permutationIdxList1 = Permutation::get($this->_sourceDataSetIdx, 1); $expectedPermutationIdxList1 = [[0 => 10], [1 => 50], [2 => 77]]; $this->_assertPermutation($permutationIdxList1, $expectedPermutationIdxList1, 3); // Size 3 combinations --------------------------------------------------------------------- $permutationList3 = Permutation::get($this->_sourceDataSetKey, 3); $expectedPermutationList3 = [['z' => 10, 'a' => 50, 'x' => 77], ['z' => 10, 'x' => 77, 'a' => 50], ['a' => 50, 'x' => 77, 'z' => 10], ['a' => 50, 'z' => 10, 'x' => 77], ['x' => 77, 'z' => 10, 'a' => 50], ['x' => 77, 'a' => 50, 'z' => 10]]; $this->_assertPermutation($permutationList3, $expectedPermutationList3, 6); // All combinations ------------------------------------------------------------------------ $permutationList = Permutation::get($this->_sourceDataSetKey); $expectedPermutationList = [['z' => 10], ['a' => 50], ['x' => 77], ['z' => 10, 'a' => 50], ['a' => 50, 'z' => 10], ['z' => 10, 'x' => 77], ['x' => 77, 'z' => 10], ['a' => 50, 'x' => 77], ['x' => 77, 'a' => 50], ['z' => 10, 'a' => 50, 'x' => 77], ['z' => 10, 'x' => 77, 'a' => 50], ['a' => 50, 'x' => 77, 'z' => 10], ['a' => 50, 'z' => 10, 'x' => 77], ['x' => 77, 'z' => 10, 'a' => 50], ['x' => 77, 'a' => 50, 'z' => 10]]; $this->_assertPermutation($permutationList, $expectedPermutationList, 15); }
public function testAddService() { $permutation = new Permutation(); $permutation->setNamespace('privatetravis'); $permutation->setLanguage('php:5.4'); $permutation->setCommand('env before_script script'); $permutation->setPrivileged(true); // Single service. $permutation->addService('mysql'); $steps = $permutation->getSteps(); $require = array('MYSQL_ID=$(docker run -d --privileged privatetravis/mysql)', 'MYSQL=$(docker inspect --format "{{ .Name }}" $MYSQL_ID | cut -d "/" -f 2)'); $this->assertEquals($require, $steps); $steps = $permutation->build(); $require[] = 'docker run --rm --privileged -v `pwd`:/data --link $MYSQL:mysql privatetravis/php:5.4 env before_script script'; $this->assertEquals($require, $steps); // More than one service. $permutation->addServices(array('postgres')); $steps = $permutation->getSteps(); $require = array('MYSQL_ID=$(docker run -d --privileged privatetravis/mysql)', 'MYSQL=$(docker inspect --format "{{ .Name }}" $MYSQL_ID | cut -d "/" -f 2)', 'POSTGRES_ID=$(docker run -d --privileged privatetravis/postgres)', 'POSTGRES=$(docker inspect --format "{{ .Name }}" $POSTGRES_ID | cut -d "/" -f 2)'); $this->assertEquals($require, $steps); $steps = $permutation->build(); $require[] = 'docker run --rm --privileged -v `pwd`:/data --link $MYSQL:mysql --link $POSTGRES:postgres privatetravis/php:5.4 env before_script script'; $this->assertEquals($require, $steps); }