Comments (12)
And let's have tests for them. Even just sanity-check, do-they-run-without-crashing tests. iterutils exists, but it has no tests.
from more-itertools.
Started hacking on this. Progress is here: https://github.com/Lonnen/more-itertools/compare/add-itertools-recipes
As functions get tests I add them to __all__
. Not sure what I'm going to do when I get down to the random functions. Advice is appreciated, for that and on any of the work in progress. May not get back to finish this until next weekend.
from more-itertools.
For the random functions, you can just call random.seed(...)
first. Then they'll give known results.
from more-itertools.
Or you could mock things into random
.
from more-itertools.
Looks great so far! I'm so glad you dove into this. A couple thoughts:
- Let's stick the recipes in a
recipes.py
module next to__init__
and import the routines into__init__
. This should make the lib a bit easier to explore for anybody poking at the code. - Let's pep-257-ify the docstrings while we're in there.
Tests look great—even more comprehensive than I envisioned.
from more-itertools.
What about mocking random? I've tried using seed, but the same seed produces different results in py2* and py3*
from more-itertools.
Sure. Mock away.
from more-itertools.
After a little investigation, random.seed()
is not a problem and setting the same seed will return the same values in python 2.* and python 3.*. The real issue was that random.choice()
will not choose the same elements between different versions.
Thought about this for a while, and decided against mocking. Instead I avoid trying to test whether the results are truly random (and the associated philosophical rabbit hole), and instead wrote some tests to check that the results exhibit some expected properties. Some of these tests involve setting up and testing for highly likely events; the odds of which I've calculated and left in comments for now. I also tend to set the random seed in those examples, just to make sure things are not going to heisenfail.
from more-itertools.
Sorry for the accidental close. Errant mouse click.
The branch is updated, please take a look and let me know if you'd like more / less coverage somewhere, or if I went straight off the rails. I haven't addressed pep-257 and there are a few lines that aren't quite pep-8 compliant. I'll fix those next.
from more-itertools.
Tests look great at first glance. I'd like to keep the recipes in a recipes.py, so I'd also like to do the tests in parallel, in a test_recipes.py. (We can make a tests folder.) And I'll want to rename Random_productTests to be CamelCasier. RandomProductTests is fine; people are smart enough to figure out what that means.
Really looking forward to merging this in. :-)
from more-itertools.
Ok. Check it out now. For the random docstring examples I use doctest:+SKIP
, because of the problems getting random.choice to work across python versions.
from more-itertools.
from more-itertools.
Related Issues (20)
- All possible combinations from a sequence of a specified length HOT 6
- Documentation build error: `ModuleNotFoundError: No module named 'sphinx_rtd_theme'`
- Optimization: combination_with_replacement_index
- Use math.comb and math.perm instead of math.factorial? HOT 6
- Adding `min_size` and `max_size` parameters to `powerset`. HOT 4
- Proposal for new itertool `postpend` HOT 1
- strictly_n only raises an exception when the iterator progresses past "n"
- `make_size` - A tools that will make an iterable exactly size n HOT 6
- Speed up `ichunked` HOT 1
- Minor improvement for `padded`
- Remove recursion from `collapse` HOT 1
- add `bucket.as_dict` HOT 3
- Add `prepend_if` / `append_if` recipies HOT 3
- Padded Improvement HOT 1
- Optimize windowed HOT 3
- Optimize adjacent itertool HOT 7
- Optimize replace itertool HOT 8
- Optimize chunked_even itertool HOT 1
- Optimize unique_in_window itertool HOT 1
- apt reports syntax error in recipes.py:853 HOT 2
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 more-itertools.