Browse Source

K7 PHP: Bubblesort Once.

Frederic G. MARAND 4 years ago
parent
commit
489b0624ac

+ 0 - 6
php/.idea/runConfigurations/7_Count_the_divisors.xml

@@ -1,6 +0,0 @@
-<component name="ProjectRunConfigurationManager">
-  <configuration default="false" name="7 Count the divisors" type="PHPUnitRunConfigurationType" factoryName="PHPUnit">
-    <TestRunner class="TestDivisorsCase" directory="Test" file="$PROJECT_DIR$/counthedivisors/TestDivisorsCase.php" scope="Class" options="-v --debug " />
-    <method v="2" />
-  </configuration>
-</component>

+ 0 - 6
php/.idea/runConfigurations/8_Are_the_the_same.xml

@@ -1,6 +0,0 @@
-<component name="ProjectRunConfigurationManager">
-  <configuration default="false" name="8 Are the the same" type="PHPUnitRunConfigurationType" factoryName="PHPUnit" singleton="false">
-    <TestRunner class="TestCompCase" directory="$PROJECT_DIR$/aretheythesame" file="$PROJECT_DIR$/aretheythesame/Test.php" scope="Class" options="-v --debug " />
-    <method v="2" />
-  </configuration>
-</component>

+ 6 - 0
php/.idea/runConfigurations/k7_Bubblesort_once.xml

@@ -0,0 +1,6 @@
+<component name="ProjectRunConfigurationManager">
+  <configuration default="false" name="k7 Bubblesort once" type="PHPUnitRunConfigurationType" factoryName="PHPUnit">
+    <TestRunner class="BubblesortOnceTest" directory="Test" file="$PROJECT_DIR$/kyu7/bubblesort_once/k_test.php" scope="Class" options="-v --debug " />
+    <method v="2" />
+  </configuration>
+</component>

+ 6 - 0
php/.idea/runConfigurations/k7_Count_the_divisors.xml

@@ -0,0 +1,6 @@
+<component name="ProjectRunConfigurationManager">
+  <configuration default="false" name="k7 Count the divisors" type="PHPUnitRunConfigurationType" factoryName="PHPUnit">
+    <TestRunner class="TestDivisorsCase" directory="Test" file="$PROJECT_DIR$/kyu7/counthedivisors/TestDivisorsCase.php" scope="Class" options="-v --debug " />
+    <method v="2" />
+  </configuration>
+</component>

+ 6 - 0
php/.idea/runConfigurations/k8_Are_the_the_same.xml

@@ -0,0 +1,6 @@
+<component name="ProjectRunConfigurationManager">
+  <configuration default="false" name="k8 Are the the same" type="PHPUnitRunConfigurationType" factoryName="PHPUnit" singleton="false">
+    <TestRunner class="TestCompCase" directory="$PROJECT_DIR$/aretheythesame" file="$PROJECT_DIR$/kyu6/aretheythesame/Test.php" scope="Class" options="-v --debug " />
+    <method v="2" />
+  </configuration>
+</component>

+ 27 - 36
php/.idea/workspace.xml

@@ -2,25 +2,14 @@
 <project version="4">
   <component name="ChangeListManager">
     <list default="true" id="4dbf7897-7552-490b-b266-845b385e4550" name="Default Changelist" comment="">
-      <change afterPath="$PROJECT_DIR$/../go/.idea/codewars.iml" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/../go/.idea/go.iml" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/.idea/CodeWars PHP.iml" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/.idea/deployment.xml" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/.idea/php-test-framework.xml" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/.idea/php.xml" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/.idea/runConfigurations/7_Count_the_divisors.xml" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/.idea/runConfigurations/8_Are_the_the_same.xml" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/.idea/symfony2.xml" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/composer.json" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/composer.lock" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/kyu6/aretheythesame/Test.php" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/kyu6/aretheythesame/aretheythesame.php" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/kyu7/counthedivisors/TestDivisorsCase.php" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/kyu7/counthedivisors/countthedivisors.php" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/.idea/runConfigurations/k7_Bubblesort_once.xml" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/.idea/runConfigurations/k7_Count_the_divisors.xml" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/.idea/runConfigurations/k8_Are_the_the_same.xml" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/kyu7/bubblesort_once/k.php" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/kyu7/bubblesort_once/k_test.php" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/.idea/runConfigurations/7_Count_the_divisors.xml" beforeDir="false" />
+      <change beforePath="$PROJECT_DIR$/.idea/runConfigurations/8_Are_the_the_same.xml" beforeDir="false" />
+      <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
     </list>
     <option name="SHOW_DIALOG" value="false" />
     <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -107,14 +96,15 @@
       <recent name="$PROJECT_DIR$/kyu6" />
     </key>
   </component>
-  <component name="RunManager" selected="PHPUnit.7 Count the divisors">
+  <component name="RunManager" selected="PHPUnit.k7 Bubblesort once">
     <configuration name="countthedivisors.php" type="PhpLocalRunConfigurationType" factoryName="PHP Console" temporary="true" path="$PROJECT_DIR$/counthedivisors/countthedivisors.php">
       <method v="2" />
     </configuration>
     <list>
       <item itemvalue="PHP Script.countthedivisors.php" />
-      <item itemvalue="PHPUnit.7 Count the divisors" />
-      <item itemvalue="PHPUnit.8 Are the the same" />
+      <item itemvalue="PHPUnit.k7 Count the divisors" />
+      <item itemvalue="PHPUnit.k7 Bubblesort once" />
+      <item itemvalue="PHPUnit.k8 Are the the same" />
     </list>
     <recent_temporary>
       <list>
@@ -146,6 +136,7 @@
       <workItem from="1580305849240" duration="23000" />
       <workItem from="1580305880657" duration="28000" />
       <workItem from="1580305931255" duration="88000" />
+      <workItem from="1580991546300" duration="730000" />
     </task>
     <servers />
   </component>
@@ -169,34 +160,34 @@
       <screen x="0" y="23" width="1680" height="1027" />
     </state>
     <state x="428" y="200" key="#Test_Frameworks/0.23.1680.1027/-135.-1177.1920.1177@0.23.1680.1027" timestamp="1579703629704" />
-    <state x="304" y="200" width="1071" height="740" key="#com.intellij.execution.impl.EditConfigurationsDialog" timestamp="1579713560676">
+    <state x="369" y="240" width="1071" height="740" key="#com.intellij.execution.impl.EditConfigurationsDialog" timestamp="1580991689940">
       <screen x="0" y="23" width="1680" height="1027" />
     </state>
-    <state x="304" y="200" width="1071" height="740" key="#com.intellij.execution.impl.EditConfigurationsDialog/0.23.1680.1027/-135.-1177.1920.1177@0.23.1680.1027" timestamp="1579713560676" />
-    <state x="100" y="123" width="1480" height="827" key="#com.intellij.execution.junit2.states.ComparisonFailureState$DiffDialog" timestamp="1579703802073">
+    <state x="369" y="240" width="1071" height="740" key="#com.intellij.execution.impl.EditConfigurationsDialog/0.23.1680.1027/-135.-1177.1920.1177@0.23.1680.1027" timestamp="1580991689940" />
+    <state x="100" y="123" width="1480" height="827" key="#com.intellij.execution.junit2.states.ComparisonFailureState$DiffDialog" timestamp="1580992118445">
       <screen x="0" y="23" width="1680" height="1027" />
     </state>
-    <state x="100" y="123" width="1480" height="827" key="#com.intellij.execution.junit2.states.ComparisonFailureState$DiffDialog/0.23.1680.1027/-135.-1177.1920.1177@0.23.1680.1027" timestamp="1579703802073" />
+    <state x="100" y="123" width="1480" height="827" key="#com.intellij.execution.junit2.states.ComparisonFailureState$DiffDialog/0.23.1680.1027/-135.-1177.1920.1177@0.23.1680.1027" timestamp="1580992118445" />
     <state x="581" y="31" key="#com.intellij.refactoring.rename.AutomaticRenamingDialog" timestamp="1579713482085">
       <screen x="0" y="23" width="1680" height="1027" />
     </state>
     <state x="581" y="31" key="#com.intellij.refactoring.rename.AutomaticRenamingDialog/0.23.1680.1027/-135.-1177.1920.1177@0.23.1680.1027" timestamp="1579713482085" />
-    <state width="1638" height="345" key="GridCell.Tab.0.bottom" timestamp="1579715573122">
+    <state width="1638" height="280" key="GridCell.Tab.0.bottom" timestamp="1580992287378">
       <screen x="0" y="23" width="1680" height="1027" />
     </state>
-    <state width="1638" height="345" key="GridCell.Tab.0.bottom/0.23.1680.1027/-135.-1177.1920.1177@0.23.1680.1027" timestamp="1579715573122" />
-    <state width="1638" height="345" key="GridCell.Tab.0.center" timestamp="1579715573121">
+    <state width="1638" height="280" key="GridCell.Tab.0.bottom/0.23.1680.1027/-135.-1177.1920.1177@0.23.1680.1027" timestamp="1580992287378" />
+    <state width="1638" height="280" key="GridCell.Tab.0.center" timestamp="1580992287377">
       <screen x="0" y="23" width="1680" height="1027" />
     </state>
-    <state width="1638" height="345" key="GridCell.Tab.0.center/0.23.1680.1027/-135.-1177.1920.1177@0.23.1680.1027" timestamp="1579715573121" />
-    <state width="1638" height="345" key="GridCell.Tab.0.left" timestamp="1579715573120">
+    <state width="1638" height="280" key="GridCell.Tab.0.center/0.23.1680.1027/-135.-1177.1920.1177@0.23.1680.1027" timestamp="1580992287377" />
+    <state width="1638" height="280" key="GridCell.Tab.0.left" timestamp="1580992287377">
       <screen x="0" y="23" width="1680" height="1027" />
     </state>
-    <state width="1638" height="345" key="GridCell.Tab.0.left/0.23.1680.1027/-135.-1177.1920.1177@0.23.1680.1027" timestamp="1579715573120" />
-    <state width="1638" height="345" key="GridCell.Tab.0.right" timestamp="1579715573122">
+    <state width="1638" height="280" key="GridCell.Tab.0.left/0.23.1680.1027/-135.-1177.1920.1177@0.23.1680.1027" timestamp="1580992287377" />
+    <state width="1638" height="280" key="GridCell.Tab.0.right" timestamp="1580992287377">
       <screen x="0" y="23" width="1680" height="1027" />
     </state>
-    <state width="1638" height="345" key="GridCell.Tab.0.right/0.23.1680.1027/-135.-1177.1920.1177@0.23.1680.1027" timestamp="1579715573122" />
+    <state width="1638" height="280" key="GridCell.Tab.0.right/0.23.1680.1027/-135.-1177.1920.1177@0.23.1680.1027" timestamp="1580992287377" />
     <state width="1638" height="345" key="GridCell.Tab.1.bottom" timestamp="1579715573123">
       <screen x="0" y="23" width="1680" height="1027" />
     </state>
@@ -213,10 +204,10 @@
       <screen x="0" y="23" width="1680" height="1027" />
     </state>
     <state width="1638" height="345" key="GridCell.Tab.1.right/0.23.1680.1027/-135.-1177.1920.1177@0.23.1680.1027" timestamp="1579715573123" />
-    <state x="661" y="470" key="NewPhpFileDialog" timestamp="1579712472765">
+    <state x="661" y="470" key="NewPhpFileDialog" timestamp="1580991621622">
       <screen x="0" y="23" width="1680" height="1027" />
     </state>
-    <state x="661" y="470" key="NewPhpFileDialog/0.23.1680.1027/-135.-1177.1920.1177@0.23.1680.1027" timestamp="1579712472765" />
+    <state x="661" y="470" key="NewPhpFileDialog/0.23.1680.1027/-135.-1177.1920.1177@0.23.1680.1027" timestamp="1580991621622" />
     <state x="349" y="175" key="SettingsEditor" timestamp="1579713540401">
       <screen x="0" y="23" width="1680" height="1027" />
     </state>

+ 17 - 0
php/kyu7/bubblesort_once/k.php

@@ -0,0 +1,17 @@
+<?php
+
+function bubblesort_once($a) {
+  $clone = array_replace([], $a);
+  if (count($clone) < 2) {
+    return $clone;
+  }
+
+  for ($i = 0; $i < count($clone) - 1; $i++) {
+    if ($clone[$i] > $clone[$i + 1]) {
+      $tmp = $clone[$i+1];
+      $clone[$i+1] = $clone[$i];
+      $clone[$i] = $tmp;
+    }
+  }
+  return $clone;
+}

+ 11 - 0
php/kyu7/bubblesort_once/k_test.php

@@ -0,0 +1,11 @@
+<?php
+
+use PHPUnit\Framework\TestCase;
+
+require_once __DIR__ . "/k.php";
+
+class BubblesortOnceTest extends TestCase {
+  public function testExample() {
+    $this->assertEquals(array(7, 5, 3, 1, 2, 4, 6, 8, 9), bubblesort_once(array(9, 7, 5, 3, 1, 2, 4, 6, 8)));
+  }
+}