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

Conversation

peter279k
Copy link

@peter279k peter279k commented Nov 5, 2017

Thank you for providing this great math package.Here is the changed log is as follows:

Changed log

  • add more testing and improve code coverage.
  • fix some errors during the testing.
  • hook the coveralls and it's the code coverage service.
  • set the configuration for the .travis.yml.
    set the dist is precise because of this issue. And it can test well in PHP 5.3.

BTW, I think the coding style should be unified.
Perhaps we can use PHP-CS-Fixer or hook the StyleCI service and set the PSR-2 coding style.
What do you think?

Thanks.

@malenkiki
Copy link
Owner

Whooooaa ! Thank you very very very much for this great PR!

I will check it later this day or tomorrow when I have some time.

@@ -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.

{
$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"); :-)

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 testGetTheCorrectName()
{
$r = new RandomComplex();
$this->assertEquals('r', $r->__get('r'));
Copy link
Owner

Choose a reason for hiding this comment

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

No, sorry, but this breaks original behavior. Please see fa42d35#r150422922

public function testSetWithTheSampleOne()
{
$t = new Independant();
$t->__set('sample_1', array(1,2,3));
Copy link
Owner

Choose a reason for hiding this comment

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

It is a magic setter, so it is better to test it in one shot like this:

$t->sample_1 = array(1,2,3);

public function testSetWithTheSampleTwo()
{
$t = new Independant();
$this->assertNull($t->__set('sample_2', array(1,2,3)));
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 testSetWithArgumentIsNoStatsInstance()
{
$t = new Independant();
$t->__set('sample_1', 'no');
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 testGetWithNameIsMidRange()
{
$s = new Stats(array(1,2,3,4,5,6,7));
$this->assertEquals(4, $s->__get('midrange'));
Copy link
Owner

Choose a reason for hiding this comment

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

It is a magic getter, so to test it, the best way is to call it:

$this->assertEquals(4, $s->midrange);

public function testGetWithNameIsPlatykurtic()
{
$s = new Stats(array(1,2,3,4,5,6,7));
$this->assertEquals(4, $s->__get('is_platykurtic'));
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 testGetWithNameIsLeptokurtic()
{
$s = new Stats(array(1,2,3,4,5,6,7));
$this->assertFalse($s->__get('is_leptokurtic'));
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 testGetWithNameIsMesokurtic()
{
$s = new Stats(array(1,2,3,4,5,6,7));
$this->assertFalse($s->__get('is_mesokurtic'));
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 testGetWithNameIsIndexOfDispersion()
{
$s = new Stats(array(1,2,3,4,5,6,7));
$this->assertEquals(1, $s->__get('coefficient_of_dispersion'));
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 testGetWithNameIsPearsonsR()
{
$s = new Stats(array(1,2,3,4,5,6,7));
$this->assertEquals(1, $s->__get('pearsons_rho'));
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 testGetShouldBeType()
{
$a = new Angle(4 * pi(), Angle::TYPE_RAD);
$this->assertEquals('rad', $a->__get('type'));
Copy link
Owner

Choose a reason for hiding this comment

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

It is a magic getter, so it better to test it as it should be call:

$this->assertEquals('rad', $a->type);

@malenkiki
Copy link
Owner

Great PR, but I havesome comment like you have see ;-)

Many thanks!

@peter279k
Copy link
Author

Hi @malenkiki, thank you for your review.
I will modify them at my available time.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants