| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * Test.php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * The abstract class for Tests inside the TestSuite. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * PHP version 7.4 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * @category Core | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * @package  RedboxTestSuite | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @author   Johnny Mast <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * @license  https://opensource.org/licenses/MIT MIT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * @link     https://github.com/johnnymast/redbox-testsuite | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * @since    GIT:1.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | namespace Redbox\Testsuite; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * Class Test | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * @package Redbox\Testsuite | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 23 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  | abstract class Test | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |      | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 28 | 14 |  |      * Instance that keeps track of the score | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |      * for this test. | 
            
                                                                        
                            
            
                                    
            
            
                | 30 | 14 |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 31 | 14 |  |      * @var Score | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |     public ?Score $score = null; | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |      | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |      * The number of increments. | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |      * @var int | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |     private int $increments = 0; | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |      | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |      * Test constructor. | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |      * Please not tests cant overwrite the function. | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |     final function __construct() | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |         $this->score = new Score($this); | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |      | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |      * Increment the score by $score amount. | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |      * @param mixed $value The score to increment with, float/double or int. | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |      * @return void | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     public function increment($value) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         $this->score += $value; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 62 |  |  |         $this->increments++; | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |      | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |      * Return the percentage the score is | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |      * compared to the maximal score. | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |      * @return float|int | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |     public function percentage() | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |         return ($this->score / $this->maxScore()) * 100; | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |      | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  |      * Calculate the average for this | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |      * score. | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |      * @return float|int | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  |     public function average() | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  |         return round($this->score / $this->getIncrements()); | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 86 |  |  |      | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 88 |  |  |      * Return the number of increments the | 
            
                                                                        
                            
            
                                    
            
            
                | 89 |  |  |      * score went over. | 
            
                                                                        
                            
            
                                    
            
            
                | 90 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 91 |  |  |      * @return int | 
            
                                                                        
                            
            
                                    
            
            
                | 92 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |     public function getIncrements(): int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     { | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 95 |  |  |         return $this->increments; | 
            
                                                                        
                            
            
                                    
            
            
                | 96 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 97 |  |  |      | 
            
                                                                        
                            
            
                                    
            
            
                | 98 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 99 |  |  |      * Return the score for this test. | 
            
                                                                        
                            
            
                                    
            
            
                | 100 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 101 |  |  |      * @return Score | 
            
                                                                        
                            
            
                                    
            
            
                | 102 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |     public function score(): Score | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |     { | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 105 |  |  |         return $this->score; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                                                                
            
                                    
            
            
                | 106 |  |  |     } | 
            
                                                                        
                                                                
            
                                    
            
            
                | 107 |  |  |      | 
            
                                                                        
                                                                
            
                                    
            
            
                | 108 |  |  |     /** | 
            
                                                        
            
                                    
            
            
                | 109 |  |  |      * Tests must implement this method to indicate | 
            
                                                        
            
                                    
            
            
                | 110 |  |  |      * the minimum score this test can reach. | 
            
                                                        
            
                                    
            
            
                | 111 |  |  |      * | 
            
                                                        
            
                                    
            
            
                | 112 |  |  |      * @return mixed | 
            
                                                        
            
                                    
            
            
                | 113 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 114 |  |  |     abstract public function minScore(); | 
            
                                                        
            
                                    
            
            
                | 115 |  |  |      | 
            
                                                        
            
                                    
            
            
                | 116 |  |  |     /** | 
            
                                                        
            
                                    
            
            
                | 117 |  |  |      * Tests must implement this method to indicate | 
            
                                                        
            
                                    
            
            
                | 118 |  |  |      * the maximum score this test can reach. | 
            
                                                        
            
                                    
            
            
                | 119 |  |  |      * | 
            
                                                        
            
                                    
            
            
                | 120 |  |  |      * @return mixed | 
            
                                                        
            
                                    
            
            
                | 121 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 122 |  |  |     abstract public function maxScore(); | 
            
                                                        
            
                                    
            
            
                | 123 |  |  |      | 
            
                                                        
            
                                    
            
            
                | 124 |  |  |     /** | 
            
                                                        
            
                                    
            
            
                | 125 |  |  |      * Tests must implement this method to start | 
            
                                                        
            
                                    
            
            
                | 126 |  |  |      * running their tests. | 
            
                                                        
            
                                    
            
            
                | 127 |  |  |      * | 
            
                                                        
            
                                    
            
            
                | 128 |  |  |      * @return void | 
            
                                                        
            
                                    
            
            
                | 129 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 130 |  |  |     abstract public function run(); | 
            
                                                        
            
                                    
            
            
                | 131 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 132 |  |  |  |