. */ namespace Tests\Traits; use Carbon\Carbon; /** * Trait RandomValues */ trait RandomValues { /** * @param $k * @param $xs * * @return array|array[] */ protected function combinationsOf($k, $xs): array { if ($k === 0) { return [[]]; } if (count($xs) === 0) { return []; } $x = $xs[0]; $xs1 = array_slice($xs, 1, count($xs) - 1); $res1 = $this->combinationsOf($k - 1, $xs1); for ($i = 0; $i < count($res1); $i++) { array_splice($res1[$i], 0, 0, $x); } $res2 = $this->combinationsOf($k, $xs1); return array_merge($res1, $res2); } /** * @return string */ protected function getRandomAmount(): string { return number_format(rand(1000, 100000) / 100, '2', '.'); } /** * @return string */ protected function getRandomCurrencyCode(): string { return $this->randomFromArray(['EUR', 'USD', 'GBP']); } /** * @return string */ protected function getRandomDateString(): string { $date = Carbon::now(); $date->subDays(rand(10, 100)); return $date->format('Y-m-d'); } /** * @return string */ protected function getRandomInterestPeriod(): string { return $this->randomFromArray(['daily', 'monthly', 'yearly']); } /** * @return string */ protected function getRandomPercentage(): string { return rand(1, 10000) / 100; } /** * @return string */ protected function randomAccountRole(): string { return $this->randomFromArray(['defaultAsset', 'sharedAsset', 'savingAsset']); } /** * @param array $array * * @return mixed */ private function randomFromArray(array $array) { return $array[rand(0, count($array) - 1)]; } /** * @return string */ protected function randomLiabilityType(): string { return $this->randomFromArray(['loan', 'debt', 'mortgage']); } }