Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more testing and fix some errors #25

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
language: php
dist: precise
php:
- "7.1"
- "7.0"
- "5.6"
- "5.5"
- "5.4"
- "5.3"
before_script:
- composer self-update
- composer install --prefer-source --no-interaction --dev
- 7.1
- 7.0
- 5.6
- 5.5
- 5.4
- 5.3
install:
- composer install
script:
- phpunit --coverage-clover build/logs/clover.xml
after_success:
- travis_retry vendor/bin/coveralls -v
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
}
},
"require-dev": {
"phpunit/phpunit": "^4.8"
"phpunit/phpunit": "^4.8",
"php-coveralls/php-coveralls": "^1.0"
}
}
2 changes: 1 addition & 1 deletion src/Malenki/Math/RandomComplex.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ protected static function checkOrder($float_min, $float_max)
public function __get($name)
{
if (in_array($name, array('rho', 'theta', 'r', 'i'))) {
return $this->$name;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?

This break the possibility to have $object->rho, or $object->theta or $object->r or $object->i direct read access.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think directly return $name is appropriate.
If set the original code $this->$name, the variable will return null.
Because this variable is not defined in this class.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about declare a private $name and change $this->$name to $this->name?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what you mean, but it is confusing, really.

But this class should be change in futur I think.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want keep magic getter to get this values, less confusing I think.

return $name;
}
}

Expand Down
18 changes: 17 additions & 1 deletion src/Malenki/Math/Stats/NonParametricTest/WilcoxonMannWhitney.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,23 @@ public function set($sampleOne, $sampleTwo)

public function clear()
{
//TODO
$this->int_count = null;
$this->arr_ranks = array();
$this->arr_rank_values = array();
$this->arr_rank_sums = array();
$this->arr_rank_means = array();
$this->arr_rank_sigmas = array();
$this->u1 = null;
$this->u2 = null;
$this->u = null;
$this->sigma = null;
$this->sigma_corrected = null;
$this->sigma2 = null;
$this->sigma2_corrected = null;
$this->mean = null;
$this->z = null;
$this->z_corrected = null;

}


Expand Down
6 changes: 3 additions & 3 deletions src/Malenki/Math/Stats/Stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public function __get($name)
)
)
{
return $this->pearsonsR();
return $this->pearsonsR($this->arr);
}

}
Expand Down Expand Up @@ -401,7 +401,7 @@ public function range()
/**
* @todo Implement mode for continuous distribution, see http://en.wikipedia.org/wiki/Mode_(statistics)#Mode_of_a_sample
*/
public function mode($inteval = null)
public function mode($interval = null)
{
if (is_null($this->arr_mode)) {
if ($this->allInteger()) {
Expand Down Expand Up @@ -587,7 +587,7 @@ public function lehmerMean($p)

public function lehmer($p)
{
return $this->lehmerMean();
return $this->lehmerMean($p);
}

public function contraharmonicMean()
Expand Down
13 changes: 13 additions & 0 deletions tests/FactorialTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,17 @@ public function testFactorialVariousValidFactorials()
$f = new Factorial(5);
$this->assertEquals(120, $f->result);
}

public function testGetShouldBeNull()
{
$f = new Factorial(2);
$this->assertNull($f->__get(null));
}

public function testToString()
{
$f = new Factorial(2);
$this->assertInternalType('string', $f->__toString());
$this->assertSame('2', $f->__toString());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... or just $this->assertSame('2', "$f"); :-)

}
}
137 changes: 136 additions & 1 deletion tests/MatrixTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,14 @@ public function testComputeDeterminantOfSquareMatrix()
$this->assertEquals(621, $m->det);
}

public function testComputeDetOfSquareMatrix()
{
$m = new Matrix(2, 2);
$m->populate(array(1, 2, 3, 4));

$this->assertEquals(-2, $m->determinant());
}

/**
* @expectedException RuntimeException
*/
Expand Down Expand Up @@ -374,9 +382,136 @@ public function testGettingTraceFromNonSquareMatrixShouldFail()
$m->trace();
}


public function testGettigExponentialMatrixShouldSuccess()
{
$this->markTestIncomplete();
}

public function testGetShouldBeNull()
{
$m = new Matrix(2, 3);
$this->assertNull($m->__get(null));
}

/**
* @expectedException \InvalidArgumentException
*/
public function testMatrixIsNotIntegers()
{
$m = new Matrix(true, false);
}

/**
* @expectedException \InvalidArgumentException
*/
public function testMatrixIsNegativeIntegers()
{
$m = new Matrix(-2, -3);
}

/**
* @expectedException \InvalidArgumentException
*/
public function testGetIsNotIntegers()
{
$m = new Matrix(2, 3);
$m->get(0.1, 0.01);
}

/**
* @expectedException \InvalidArgumentException
*/
public function testGetMatrixRowColumnIsNegativeIntegers()
{
$m = new Matrix(2, 3);
$m->get(-1, -2);
}

/**
* @expectedException \OutOfRangeException
*/
public function testAddRowShouldBeOutOfRange()
{
$m = new Matrix(2, 3);
$m->addRow(array(2, 3, 4));
$m->addRow(array(2, 3, 4));
$m->addRow(array(2, 3, 4));
}

/**
* @expectedException \InvalidArgumentException
*/
public function testAddRowShouldBeTheSameAmountColumn()
{
$m = new Matrix(2, 3);
$m->addRow(array(2, 3));
}

/**
* @expectedException \OutOfRangeException
*/
public function testAddColShouldBeOutOfRange()
{
$m = new Matrix(2, 2);
$m->addCol(array(2, 3));
$m->addCol(array(2, 3));
$m->addCol(array(2, 3));
}

/**
* @expectedException \InvalidArgumentException
*/
public function testAddColShouldBeTheSameAmountColumn()
{
$m = new Matrix(2, 3);
$m->addCol(array(2, 3, 4));
}

/**
* @expectedException \OutOfRangeException
*/
public function testGetRowShouldBeOutOfRange()
{
$m = new Matrix(2, 3);
$m->getRow(0);
}

/**
* @expectedException \OutOfRangeException
*/
public function testGetColShouldBeOutOfRange()
{
$m = new Matrix(2, 3);
$m->getCol(4);
}

public function testMultiplyAllowShouldBeFalse()
{
$m = new Matrix(2, 3);
$this->assertFalse($m->multiplyAllow(false));
}

public function testMultiplyAllowShouldBeInstanceOfComplex()
{
$m = new Matrix(2, 3);
$this->assertTrue($m->multiplyAllow(new Complex(1, 2)));
}

/**
* @expectedException \RuntimeException
*/
public function testMultiplyShouldBeTheWrongNumberOfRows()
{
$m = new Matrix(2, 3);
$m->multiply(false);
}

/**
* @expectedException \InvalidArgumentException
*/
public function testAddShouldNotBeInstanceOfMatrix()
{
$m = new Matrix(2, 3);
$m->add(false);
}
}
46 changes: 46 additions & 0 deletions tests/Number/ComplexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,52 @@ public function testDivideComplexNumberByRealShouldSuccess()
$this->assertEquals($must, $real->divide($z));
}

public function testGetShouldBeNull()
{
$z = new Complex(1, 2);
$this->assertNull($z->__get('no'));
}

public function testNegative()
{
$neg = new Complex(1, 2);
$this->assertInternalType('object', $neg->negative());
}

public function testSubstractShouldReturnAddMethodResult()
{
$subs = new Complex(1, 2);
$this->assertInternalType('object', $subs->substract(2));
}

public function testEqualArgumentZIsNumberic()
{
$equal = new Complex(2, 2);
$this->assertFalse($equal->equal(2));
}

public function testToStringShouldBeZero()
{
$z = new Complex(0, 0, Complex::TRIGONOMETRIC);
$this->assertSame(0, $z->__toString());
}

/**
* @expectedException \InvalidArgumentException
*/
public function testComplexInstanceFloatAShouldBeInvalidNumber()
{
$z = new Complex(false, 2, null);
}

/**
* @expectedException \InvalidArgumentException
*/
public function testComplexInstanceMixBShouldBeInvalid()
{
$z = new Complex(2, false, null);
}

/**
* @expectedException \InvalidArgumentException
*/
Expand Down
22 changes: 22 additions & 0 deletions tests/Number/RationalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,26 @@ public function testStringContextShouldSuccess()
$r = new Rational(2, 3);
$this->assertEquals('2/3', "$r");
}

public function testGetShouldBeNull()
{
$r = new Rational(2, 3);
$this->assertNull($r->__get('no'));
}

/**
* @expectedException \InvalidArgumentException
*/
public function testRationalInstanceIsInvalidIntegers()
{
$r = new Rational(0.1, 0.01);
}

/**
* @expectedException \InvalidArgumentException
*/
public function testRationalInstanceArgumentDenominatorIsZero()
{
$r = new Rational(1, 0);
}
}
25 changes: 24 additions & 1 deletion tests/Number/RealTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,35 @@ public function testIfRealIsIntegerOrNotShouldSuccess()
$this->assertTrue($i->isInteger());
}


public function testStringContextShouldSuccess()
{
$i = new Real(2.56);
$d = new Real(0.56);
$this->assertEquals('2.56', "$i");
$this->assertEquals('0.56', "$d");
}

public function testGetShouldBePI()
{
$real = new Real(2.56);
$this->assertEquals(M_PI, $real->__get('pi')->__toString());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum… I dont know, this is strange to get pi, e, and so on from an instance. Confusing.

But, we can do that:

$real = new Real(Real::PI);
$this->assertEquals(M_PI, "$real");

}

public function testGetShouldBeE()
{
$real = new Real(2.56);
$this->assertEquals(M_E, $real->__get('e')->__toString());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same idea as in fa42d35#r150423847

}

public function testGetShouldBeEuler()
{
$real = new Real(2.56);
$this->assertEquals(M_EULER, $real->__get('euler')->__toString());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

public function testGetShouldBeNull()
{
$real = new Real(2.56);
$this->assertNull($real->__get('no'));
}
}
Loading