Comments (4)
You can't mock static functions in PHPUnit; only object methods.
If static method a uses static method b, you'd want to have unit tests on method b on its own. Then the tests on static method a are testing just a, since you know your tests on b test that that works properly.
Now, if method b is a random number generator, then it is going to be impossible to test specific output since the output will depend on the rng. The best you could do is test that it is a number, that it is within the range of possible values based on the range of the rng, etc.
This doesn't necessarily sound like an issue of not being able to mock static methods, but that a rng is being used. Even if there was just one static method and it used a PHP rand function, your output is dependent on that, and you can't know exactly what the output will be.
from math-php.
Thinking about this a little more, a possibly elegant solution is to make your static method a higher-order function that accepts as an additional parameter a function (PHP callable closure) that will act as the random number generator. Then for unit tests, you can pass in your testRNG function that returns non-random numbers so you can test the expected output of your method knowing what the inputs will be because you seeded the RNG with your own values.
Then, from a user interface perspective, you might want to wrap that higher-order function with a convenience wrapper method that will supply the standard RNG, but still give the user the option to directly call it with their own RNG if they want.
Just an idea.
from math-php.
I think I have a better solution. If I add the Dirac Delta as a distribution, I could add it's inverse function to the DiracDetla class, which would override the parent inverse function. The inverse of the Dirac Delta is Zero for all values of p.
from math-php.
This is in a pull request.
from math-php.
Related Issues (20)
- What is the point of the complex polar form? HOT 7
- Division by zero in Probability\Distribution\Continuous\Continuous HOT 21
- Dealing with NANs HOT 3
- Integer Modulo n HOT 3
- Add vector, matrix and quaternion operations for 3d geometry HOT 1
- Could math-php support KPHP? HOT 1
- Truncated Mean Percentage HOT 5
- Incompatibility with Iterator and ArrayAccess interfaces HOT 1
- Quartiles calculation in Stats Descriptive HOT 1
- MiddlePayment For Loan HOT 2
- `number` is not a valid PHP type HOT 5
- Kernel Density Estimation: Improved Sheather-Jones algorithm HOT 4
- Bug for the t-test? HOT 5
- Add row/column algebra methods to Matrix for Vector HOT 3
- Document additional Matrix Row Operations and add their Columnar counterparts HOT 5
- Implicit Behavior of ImmutableSet
- Add Moore-Penrose Inverse HOT 12
- Psalm does not understand `number` pseudo-type HOT 3
- Add a factor method for Polynomials HOT 4
- Repeated measures ANOVA HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from math-php.