Explorar el Código

added Polynomial test

smiley hace 10 años
padre
commit
9c66169b8b
Se han modificado 2 ficheros con 39 adiciones y 3 borrados
  1. 5 3
      src/Polynomial.php
  2. 34 0
      tests/PolynomialTest.php

+ 5 - 3
src/Polynomial.php

@@ -140,9 +140,11 @@ class Polynomial{
 	 */
 	public function gexp($n){
 
-		switch(true){
-			case $n < 0   : $n += 255; break;
-			case $n >= 256: $n -= 255; break;
+		if($n < 0){
+			$n += 255;
+		}
+		elseif($n >= 256){
+			$n -= 255;
 		}
 
 		return $this->EXP_TABLE[$n];

+ 34 - 0
tests/PolynomialTest.php

@@ -0,0 +1,34 @@
+<?php
+/**
+ *
+ * @filesource   PolynomialTest.php
+ * @created      09.02.2016
+ * @package      chillerlan\QRCodeTest
+ * @author       Smiley <smiley@chillerlan.net>
+ * @copyright    2015 Smiley
+ * @license      MIT
+ */
+
+namespace chillerlan\QRCodeTest;
+
+use chillerlan\QRCode\Polynomial;
+
+class PolynomialTest extends \PHPUnit_Framework_TestCase{
+
+	/**
+	 * @var \chillerlan\QRCode\Polynomial
+	 */
+	protected $polynomial;
+
+	protected function setUp(){
+		$this->polynomial = new Polynomial;
+	}
+
+	/**
+	 * @expectedException \chillerlan\QRCode\QRCodeException
+	 * @expectedExceptionMessage log(0)
+	 */
+	public function testGlogException(){
+		$this->polynomial->glog(0);
+	}
+}